#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef unsigned long uint8_t;
typedef int uint;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int baseconvert(unsigned long, char *, char *, int, unsigned long, char *,
                char *, int);
int /*<<< orphan*/ baseconvert_is_valid_in_base(unsigned long, char *, char *,
                                                int);
int baseconvert_targetlen(unsigned long, unsigned long, int);
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, unsigned long, int, int /*<<< orphan*/ *);
int freadall(char **, int /*<<< orphan*/);
int /*<<< orphan*/ freopen(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
unsigned long ftell(int /*<<< orphan*/ *);
int fwrite(char *, int, int, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  unsigned long in_radix = 0, out_radix = 0;
  char *in_digits = NULL, *out_digits = NULL;
  int i;
  for (i = 1; i < argc; i++) {
    if (in_digits == NULL) {
      in_digits = argv[i];
    } else if (out_digits == NULL) {
      out_digits = argv[i];
    } else
      die("Usage: baseconvert IN_DIGITS_FILE OUT_DIGITS_FILE\nDigits files: "
          "ith character represents i in that base.\nData to be converted is "
          "read from stdin and results are written to stdout.\nExample: echo "
          "-n 15 | ./baseconvert decimal.txt base2.txt # gives 1111");
  }
  if (in_digits == NULL || out_digits == NULL)
    die("Usage: baseconvert IN_DIGITS_FILE OUT_DIGITS_FILE\nDigits files: ith "
        "character represents i in that base.\nData to be converted is read "
        "from stdin and results are written to stdout.\nExample: echo -n 15 | "
        "./baseconvert decimal.txt base2.txt # gives 1111");
  FILE *fh = fopen(in_digits, "rb");
  in_digits = NULL;
  if (fh != NULL) {
    fseek(fh, 0L, SEEK_END);
    in_radix = ftell(fh);
    rewind(fh);
    in_digits = malloc(in_radix);
    if (in_digits != NULL)
      fread(in_digits, in_radix, 1, fh);
    fclose(fh);
  }
  if (in_digits == NULL)
    die("In digits file bad.");
  fh = fopen(out_digits, "rb");
  out_digits = NULL;
  if (fh != NULL) {
    fseek(fh, 0L, SEEK_END);
    out_radix = ftell(fh);
    rewind(fh);
    out_digits = malloc(out_radix);
    if (out_digits != NULL)
      fread(out_digits, out_radix, 1, fh);
    fclose(fh);
  }
  if (out_digits == NULL)
    die("Out digits file bad.");
  uint8_t in_max_digit = in_radix - 1, out_max_digit = out_radix - 1;
  char *stdinbytes;
  freopen(NULL, "rb", stdin);
  uint in_len = freadall(&stdinbytes, stdin);
  if (!baseconvert_is_valid_in_base(in_max_digit, in_digits, stdinbytes,
                                    in_len)) {
    if (stdinbytes[in_len - 1] == '\n')
      die("Bad input. Maybe because of a newline at the end?");
    else
      die("Bad input.");
  }
  uint out_len = baseconvert_targetlen(in_max_digit, out_max_digit, in_len);
  char *converted = malloc(out_len);
  if (converted == NULL)
    die("Failed to allocate memory.");
  out_len = baseconvert(in_max_digit, in_digits, stdinbytes, in_len,
                        out_max_digit, out_digits, converted, out_len);
  if (fwrite(converted, out_len, 1, stdout) != 1)
    perror("Writing final output");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12a0 <main+0xb0>
cmpq   $0x0,-0x28(%rbp)
jne    125c <main+0x6c>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
jmp    128d <main+0x9d>
cmpq   $0x0,-0x30(%rbp)
jne    127c <main+0x8c>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
jmp    1288 <main+0x98>
lea    0xd7d(%rip),%rdi
call   10f0 <die@plt>
jmp    128d <main+0x9d>
jmp    1292 <main+0xa2>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1230 <main+0x40>
cmpq   $0x0,-0x28(%rbp)
je     12b6 <main+0xc6>
cmpq   $0x0,-0x30(%rbp)
jne    12c2 <main+0xd2>
lea    0xd43(%rip),%rdi
call   10f0 <die@plt>
mov    -0x28(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     134e <main+0x15e>
mov    -0x40(%rbp),%rdi
mov    0x2cf4(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10b0 <fseek@plt>
mov    -0x40(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x40(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x18(%rbp),%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1345 <main+0x155>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x40(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x28(%rbp)
jne    1365 <main+0x175>
lea    0xd9e(%rip),%rdi
call   10f0 <die@plt>
mov    -0x30(%rbp),%rdi
lea    0xd8b(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     13f1 <main+0x201>
mov    -0x40(%rbp),%rdi
mov    0x2c51(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10b0 <fseek@plt>
mov    -0x40(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x40(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     13e8 <main+0x1f8>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x40(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x30(%rbp)
jne    1408 <main+0x218>
lea    0xd0f(%rip),%rdi
call   10f0 <die@plt>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    0x2bb9(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%edi
lea    0xcc7(%rip),%rsi
call   1070 <freopen@plt>
mov    0x2ba0(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdi
call   1080 <freadall@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x58(%rbp),%rdx
mov    -0x5c(%rbp),%ecx
call   10d0 <baseconvert_is_valid_in_base@plt>
cmp    $0x0,%eax
jne    14a7 <main+0x2b7>
mov    -0x58(%rbp),%rax
mov    -0x5c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1496 <main+0x2a6>
lea    0xc9b(%rip),%rdi
call   10f0 <die@plt>
jmp    14a2 <main+0x2b2>
lea    0xcbc(%rip),%rdi
call   10f0 <die@plt>
jmp    14a7 <main+0x2b7>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x5c(%rbp),%edx
call   1040 <baseconvert_targetlen@plt>
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    14dd <main+0x2ed>
lea    0xc8c(%rip),%rdi
call   10f0 <die@plt>
mov    -0x48(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x58(%rbp),%rdx
mov    -0x5c(%rbp),%ecx
mov    -0x50(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    -0x68(%rbp),%r10
mov    -0x60(%rbp),%eax
mov    %r10,(%rsp)
mov    %eax,0x8(%rsp)
call   10c0 <baseconvert@plt>
mov    %eax,-0x60(%rbp)
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%esi
mov    0x2ab7(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1110 <fwrite@plt>
cmp    $0x1,%eax
je     153a <main+0x34a>
lea    0xc4a(%rip),%rdi
call   1100 <perror@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     1256 <main+0x66>
mov    %rsi,%r15
mov    %edi,%r13d
mov    $0x1,%ebp
xor    %ebx,%ebx
lea    0xde9(%rip),%r14
xor    %r12d,%r12d
jmp    122d <main+0x3d>
nopl   0x0(%rax)
mov    (%r15,%rbp,8),%rbx
add    $0x1,%rbp
cmp    %rbp,%r13
je     125d <main+0x6d>
test   %rbx,%rbx
je     1220 <main+0x30>
test   %r12,%r12
je     1250 <main+0x60>
mov    %r14,%rdi
call   10f0 <die@plt>
jmp    1224 <main+0x34>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbp,8),%r12
jmp    1224 <main+0x34>
xor    %ebx,%ebx
xor    %r12d,%r12d
jmp    1267 <main+0x77>
test   %rbx,%rbx
je     1267 <main+0x77>
test   %r12,%r12
jne    1273 <main+0x83>
lea    0xd92(%rip),%rdi
call   10f0 <die@plt>
lea    0xe81(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     12e1 <main+0xf1>
mov    %rax,%rbx
mov    0x2d57(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %rbx,%rdi
call   1090 <ftell@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1060 <rewind@plt>
mov    %r15d,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     12ea <main+0xfa>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
add    $0xffffffffffffffff,%r15
jmp    1305 <main+0x115>
mov    $0xffffffffffffffff,%r15
jmp    12f6 <main+0x106>
mov    %rbx,%rdi
call   1050 <fclose@plt>
add    $0xffffffffffffffff,%r15
lea    0xe01(%rip),%rdi
call   10f0 <die@plt>
xor    %r14d,%r14d
lea    0xdef(%rip),%rsi
mov    %r12,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1375 <main+0x185>
mov    %rax,%rbp
mov    0x2cc5(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %rbp,%rdi
call   1090 <ftell@plt>
mov    %rax,%r13
mov    %rbp,%rdi
call   1060 <rewind@plt>
mov    %r13d,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     137e <main+0x18e>
mov    %rax,0x10(%rsp)
mov    %rax,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
add    $0xffffffffffffffff,%r13
jmp    139d <main+0x1ad>
mov    $0xffffffffffffffff,%r13
jmp    138a <main+0x19a>
mov    %rbp,%rdi
call   1050 <fclose@plt>
add    $0xffffffffffffffff,%r13
lea    0xd81(%rip),%rdi
call   10f0 <die@plt>
xor    %eax,%eax
mov    %rax,0x10(%rsp)
mov    0x2c3c(%rip),%rbx
mov    (%rbx),%edx
lea    0xd4e(%rip),%rsi
xor    %edi,%edi
call   1070 <freopen@plt>
mov    (%rbx),%esi
lea    0x8(%rsp),%rdi
call   1080 <freadall@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rdx
mov    %r15,%rdi
mov    %r14,%r12
mov    %r14,%rsi
mov    %eax,%ecx
call   10d0 <baseconvert_is_valid_in_base@plt>
test   %eax,%eax
jne    13ff <main+0x20f>
mov    0x8(%rsp),%rax
movslq %ebp,%rcx
cmpb   $0xa,-0x1(%rcx,%rax,1)
lea    0xd38(%rip),%rax
lea    0xd63(%rip),%rdi
cmove  %rax,%rdi
call   10f0 <die@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1040 <baseconvert_targetlen@plt>
mov    %eax,%r14d
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    142a <main+0x23a>
lea    0xd3f(%rip),%rdi
call   10f0 <die@plt>
mov    0x8(%rsp),%rdx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebp,%ecx
mov    %r13,%r8
mov    0x10(%rsp),%r9
push   %r14
push   %rbx
call   10c0 <baseconvert@plt>
add    $0x10,%rsp
mov    0x2b7e(%rip),%rcx
mov    (%rcx),%ecx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   1110 <fwrite@plt>
cmp    $0x1,%eax
jne    1479 <main+0x289>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcff(%rip),%rdi
call   1100 <perror@plt>
jmp    1468 <main+0x278>

LLVM IR (-O0):
@.str = [251 x i8] c"Usage: baseconvert IN_DIGITS_FILE OUT_DIGITS_FILE\0ADigits files: ith character represents i in that base.\0AData to be converted is read from stdin and results are written to stdout.\0AExample: echo -n 15 | ./baseconvert decimal.txt base2.txt # gives 1111\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.2 = [20 x i8] c"In digits file bad.\00"
@.str.3 = [21 x i8] c"Out digits file bad.\00"
@stdin = global i32 0
@.str.4 = [50 x i8] c"Bad input. Maybe because of a newline at the end?\00"
@.str.5 = [11 x i8] c"Bad input.\00"
@.str.6 = [27 x i8] c"Failed to allocate memory.\00"
@stdout = global i32 0
@.str.7 = [21 x i8] c"Writing final output\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i64
%13 = alloca i64
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
store i64 0, i64* %7
store i8* null, i8** %8
store i8* null, i8** %9
store i32 1, i32* %10
br label %18
18: ; preds = %44, %2
%19 = load i32, i32* %10
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %47
22: ; preds = %18
%23 = load i8*, i8** %8
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i8**, i8*** %5
%27 = load i32, i32* %10
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
store i8* %30, i8** %8
br label %43
31: ; preds = %22
%32 = load i8*, i8** %9
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = load i8**, i8*** %5
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
%39 = load i8*, i8** %38
store i8* %39, i8** %9
br label %42
40: ; preds = %31
%41 = call i32 @die(i8* getelementptr inbounds ([251 x i8], [251 x i8]* @.str, i64 0, i64 0))
br label %42
42: ; preds = %40, %34
br label %43
43: ; preds = %42, %25
br label %44
44: ; preds = %43
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
store i32 %46, i32* %10
br label %18
47: ; preds = %18
%48 = load i8*, i8** %8
%49 = icmp eq i8* %48, null
br i1 %49, label %53, label %50
50: ; preds = %47
%51 = load i8*, i8** %9
%52 = icmp eq i8* %51, null
br i1 %52, label %53, label %55
53: ; preds = %50, %47
%54 = call i32 @die(i8* getelementptr inbounds ([251 x i8], [251 x i8]* @.str, i64 0, i64 0))
br label %55
55: ; preds = %53, %50
%56 = load i8*, i8** %8
%57 = call i32* @fopen(i8* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %57, i32** %11
store i8* null, i8** %8
%58 = load i32*, i32** %11
%59 = icmp ne i32* %58, null
br i1 %59, label %60, label %81
60: ; preds = %55
%61 = load i32*, i32** %11
%62 = load i32, i32* @SEEK_END
%63 = call i32 @fseek(i32* %61, i64 0, i32 %62)
%64 = load i32*, i32** %11
%65 = call i64 @ftell(i32* %64)
store i64 %65, i64* %6
%66 = load i32*, i32** %11
%67 = call i32 @rewind(i32* %66)
%68 = load i64, i64* %6
%69 = trunc i64 %68 to i32
%70 = call i8* @malloc(i32 %69)
store i8* %70, i8** %8
%71 = load i8*, i8** %8
%72 = icmp ne i8* %71, null
br i1 %72, label %73, label %78
73: ; preds = %60
%74 = load i8*, i8** %8
%75 = load i64, i64* %6
%76 = load i32*, i32** %11
%77 = call i32 @fread(i8* %74, i64 %75, i32 1, i32* %76)
br label %78
78: ; preds = %73, %60
%79 = load i32*, i32** %11
%80 = call i32 @fclose(i32* %79)
br label %81
81: ; preds = %78, %55
%82 = load i8*, i8** %8
%83 = icmp eq i8* %82, null
br i1 %83, label %84, label %86
84: ; preds = %81
%85 = call i32 @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %86
86: ; preds = %84, %81
%87 = load i8*, i8** %9
%88 = call i32* @fopen(i8* %87, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %88, i32** %11
store i8* null, i8** %9
%89 = load i32*, i32** %11
%90 = icmp ne i32* %89, null
br i1 %90, label %91, label %112
91: ; preds = %86
%92 = load i32*, i32** %11
%93 = load i32, i32* @SEEK_END
%94 = call i32 @fseek(i32* %92, i64 0, i32 %93)
%95 = load i32*, i32** %11
%96 = call i64 @ftell(i32* %95)
store i64 %96, i64* %7
%97 = load i32*, i32** %11
%98 = call i32 @rewind(i32* %97)
%99 = load i64, i64* %7
%100 = trunc i64 %99 to i32
%101 = call i8* @malloc(i32 %100)
store i8* %101, i8** %9
%102 = load i8*, i8** %9
%103 = icmp ne i8* %102, null
br i1 %103, label %104, label %109
104: ; preds = %91
%105 = load i8*, i8** %9
%106 = load i64, i64* %7
%107 = load i32*, i32** %11
%108 = call i32 @fread(i8* %105, i64 %106, i32 1, i32* %107)
br label %109
109: ; preds = %104, %91
%110 = load i32*, i32** %11
%111 = call i32 @fclose(i32* %110)
br label %112
112: ; preds = %109, %86
%113 = load i8*, i8** %9
%114 = icmp eq i8* %113, null
br i1 %114, label %115, label %117
115: ; preds = %112
%116 = call i32 @die(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %117
117: ; preds = %115, %112
%118 = load i64, i64* %6
%119 = sub i64 %118, 1
store i64 %119, i64* %12
%120 = load i64, i64* %7
%121 = sub i64 %120, 1
store i64 %121, i64* %13
%122 = load i32, i32* @stdin
%123 = call i32 @freopen(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %122)
%124 = load i32, i32* @stdin
%125 = call i32 @freadall(i8** %14, i32 %124)
store i32 %125, i32* %15
%126 = load i64, i64* %12
%127 = load i8*, i8** %8
%128 = load i8*, i8** %14
%129 = load i32, i32* %15
%130 = call i32 @baseconvert_is_valid_in_base(i64 %126, i8* %127, i8* %128, i32 %129)
%131 = icmp ne i32 %130, 0
br i1 %131, label %146, label %132
132: ; preds = %117
%133 = load i8*, i8** %14
%134 = load i32, i32* %15
%135 = sub nsw i32 %134, 1
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds i8, i8* %133, i64 %136
%138 = load i8, i8* %137
%139 = sext i8 %138 to i32
%140 = icmp eq i32 %139, 10
br i1 %140, label %141, label %143
141: ; preds = %132
%142 = call i32 @die(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0))
br label %145
143: ; preds = %132
%144 = call i32 @die(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %145
145: ; preds = %143, %141
br label %146
146: ; preds = %145, %117
%147 = load i64, i64* %12
%148 = load i64, i64* %13
%149 = load i32, i32* %15
%150 = call i32 @baseconvert_targetlen(i64 %147, i64 %148, i32 %149)
store i32 %150, i32* %16
%151 = load i32, i32* %16
%152 = call i8* @malloc(i32 %151)
store i8* %152, i8** %17
%153 = load i8*, i8** %17
%154 = icmp eq i8* %153, null
br i1 %154, label %155, label %157
155: ; preds = %146
%156 = call i32 @die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
br label %157
157: ; preds = %155, %146
%158 = load i64, i64* %12
%159 = load i8*, i8** %8
%160 = load i8*, i8** %14
%161 = load i32, i32* %15
%162 = load i64, i64* %13
%163 = load i8*, i8** %9
%164 = load i8*, i8** %17
%165 = load i32, i32* %16
%166 = call i32 @baseconvert(i64 %158, i8* %159, i8* %160, i32 %161, i64 %162, i8* %163, i8* %164, i32 %165)
store i32 %166, i32* %16
%167 = load i8*, i8** %17
%168 = load i32, i32* %16
%169 = load i32, i32* @stdout
%170 = call i32 @fwrite(i8* %167, i32 %168, i32 1, i32 %169)
%171 = icmp ne i32 %170, 1
br i1 %171, label %172, label %174
172: ; preds = %157
%173 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
br label %174
174: ; preds = %172, %157
ret i32 0
}

LLVM IR (-O2):
@.str = [251 x i8] c"Usage: baseconvert IN_DIGITS_FILE OUT_DIGITS_FILE\0ADigits files: ith character represents i in that base.\0AData to be converted is read from stdin and results are written to stdout.\0AExample: echo -n 15 | ./baseconvert decimal.txt base2.txt # gives 1111\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.2 = [20 x i8] c"In digits file bad.\00"
@.str.3 = [21 x i8] c"Out digits file bad.\00"
@stdin = global i32 0
@.str.4 = [50 x i8] c"Bad input. Maybe because of a newline at the end?\00"
@.str.5 = [11 x i8] c"Bad input.\00"
@.str.6 = [27 x i8] c"Failed to allocate memory.\00"
@stdout = global i32 0
@.str.7 = [21 x i8] c"Writing final output\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %31
5: ; preds = %2
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %22
%8 = phi i64 [ 1, %5 ], [ %25, %22 ]
%9 = phi i8* [ null, %5 ], [ %24, %22 ]
%10 = phi i8* [ null, %5 ], [ %23, %22 ]
%11 = icmp eq i8* %9, null
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = getelementptr inbounds i8*, i8** %1, i64 %8
%14 = load i8*, i8** %13
br label %22
15: ; preds = %7
%16 = icmp eq i8* %10, null
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = getelementptr inbounds i8*, i8** %1, i64 %8
%19 = load i8*, i8** %18
br label %22
20: ; preds = %15
%21 = tail call i32 @die(i8* getelementptr inbounds ([251 x i8], [251 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %12, %20, %17
%23 = phi i8* [ %10, %12 ], [ %19, %17 ], [ %10, %20 ]
%24 = phi i8* [ %14, %12 ], [ %9, %17 ], [ %9, %20 ]
%25 = add nuw nsw i64 %8, 1
%26 = icmp eq i64 %25, %6
br i1 %26, label %27, label %7
27: ; preds = %22
%28 = icmp eq i8* %24, null
%29 = icmp eq i8* %23, null
%30 = select i1 %28, i1 true, i1 %29
br i1 %30, label %31, label %35
31: ; preds = %2, %27
%32 = phi i8* [ %24, %27 ], [ null, %2 ]
%33 = phi i8* [ %23, %27 ], [ null, %2 ]
%34 = tail call i32 @die(i8* getelementptr inbounds ([251 x i8], [251 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %27, %31
%36 = phi i8* [ %24, %27 ], [ %32, %31 ]
%37 = phi i8* [ %23, %27 ], [ %33, %31 ]
%38 = tail call i32* @fopen(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%39 = icmp eq i32* %38, null
br i1 %39, label %55, label %40
40: ; preds = %35
%41 = load i32, i32* @SEEK_END
%42 = tail call i32 @fseek(i32* %38, i64 0, i32 %41)
%43 = tail call i64 @ftell(i32* %38)
%44 = tail call i32 @rewind(i32* %38)
%45 = trunc i64 %43 to i32
%46 = tail call i8* @malloc(i32 %45)
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %51
48: ; preds = %40
%49 = tail call i32 @fclose(i32* %38)
%50 = add i64 %43, -1
br label %55
51: ; preds = %40
%52 = tail call i32 @fread(i8* %46, i64 %43, i32 1, i32* %38)
%53 = tail call i32 @fclose(i32* %38)
%54 = add i64 %43, -1
br label %58
55: ; preds = %35, %48
%56 = phi i64 [ %50, %48 ], [ -1, %35 ]
%57 = tail call i32 @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %58
58: ; preds = %51, %55
%59 = phi i64 [ %56, %55 ], [ %54, %51 ]
%60 = phi i8* [ null, %55 ], [ %46, %51 ]
%61 = tail call i32* @fopen(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%62 = icmp eq i32* %61, null
br i1 %62, label %78, label %63
63: ; preds = %58
%64 = load i32, i32* @SEEK_END
%65 = tail call i32 @fseek(i32* %61, i64 0, i32 %64)
%66 = tail call i64 @ftell(i32* %61)
%67 = tail call i32 @rewind(i32* %61)
%68 = trunc i64 %66 to i32
%69 = tail call i8* @malloc(i32 %68)
%70 = icmp eq i8* %69, null
br i1 %70, label %71, label %74
71: ; preds = %63
%72 = tail call i32 @fclose(i32* %61)
%73 = add i64 %66, -1
br label %78
74: ; preds = %63
%75 = tail call i32 @fread(i8* %69, i64 %66, i32 1, i32* %61)
%76 = tail call i32 @fclose(i32* %61)
%77 = add i64 %66, -1
br label %81
78: ; preds = %58, %71
%79 = phi i64 [ %73, %71 ], [ -1, %58 ]
%80 = tail call i32 @die(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %81
81: ; preds = %74, %78
%82 = phi i64 [ %79, %78 ], [ %77, %74 ]
%83 = phi i8* [ null, %78 ], [ %69, %74 ]
%84 = bitcast i8** %3 to i8*
%85 = load i32, i32* @stdin
%86 = tail call i32 @freopen(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %85)
%87 = load i32, i32* @stdin
%88 = call i32 @freadall(i8** %3, i32 %87)
%89 = load i8*, i8** %3
%90 = call i32 @baseconvert_is_valid_in_base(i64 %59, i8* %60, i8* %89, i32 %88)
%91 = icmp eq i32 %90, 0
br i1 %91, label %92, label %101
92: ; preds = %81
%93 = load i8*, i8** %3
%94 = add nsw i32 %88, -1
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8, i8* %93, i64 %95
%97 = load i8, i8* %96
%98 = icmp eq i8 %97, 10
%99 = select i1 %98, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0)
%100 = call i32 @die(i8* %99)
br label %101
101: ; preds = %92, %81
%102 = call i32 @baseconvert_targetlen(i64 %59, i64 %82, i32 %88)
%103 = call i8* @malloc(i32 %102)
%104 = icmp eq i8* %103, null
br i1 %104, label %105, label %107
105: ; preds = %101
%106 = call i32 @die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
br label %107
107: ; preds = %105, %101
%108 = load i8*, i8** %3
%109 = call i32 @baseconvert(i64 %59, i8* %60, i8* %108, i32 %88, i64 %82, i8* %83, i8* %103, i32 %102)
%110 = load i32, i32* @stdout
%111 = call i32 @fwrite(i8* %103, i32 %109, i32 1, i32 %110)
%112 = icmp eq i32 %111, 1
br i1 %112, label %115, label %113
113: ; preds = %107
%114 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
br label %115
115: ; preds = %113, %107
ret i32 0
}