#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ itoa(int, char *);
int /*<<< orphan*/ perror(char *);
int main(int argc, char *argv[]) {
  FILE *in, *out;
  in = fopen("input.dat", "r");
  if (in == NULL) {
    perror("input.dat");
    return 1;
  }
  out = fopen("output.dat", "w");
  if (out == NULL) {
    perror("output.dat");
    return 1;
  }
  int n;
  char s[128];
  while (fscanf(in, "%d", &n) != EOF) {
    itoa(n, s);
    fprintf(out, "%d, is '%s'\n", n, s);
  }
  fclose(in);
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe80(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b3 <main+0x53>
lea    0xe5e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    125d <main+0xfd>
lea    0xe52(%rip),%rdi
lea    0xe56(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ed <main+0x8d>
lea    0xe30(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    125d <main+0xfd>
jmp    11f2 <main+0x92>
mov    -0x18(%rbp),%rdi
lea    0xe1c(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1040 <fscanf@plt>
mov    0x2ddb(%rip),%rcx
cmp    (%rcx),%rax
je     1244 <main+0xe4>
mov    -0x24(%rbp),%edi
lea    -0xb0(%rbp),%rsi
call   1080 <itoa@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    -0xb0(%rbp),%rcx
lea    0xde2(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11f2 <main+0x92>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
lea    0xe88(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     124a <main+0xea>
mov    %rax,%r14
lea    0xe75(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1253 <main+0xf3>
mov    %rax,%r15
lea    0xe63(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
call   1040 <fscanf@plt>
mov    0x2e1e(%rip),%r12
cmp    (%r12),%rax
je     1226 <main+0xc6>
lea    0x10(%rsp),%rbx
lea    0xe3d(%rip),%r13
lea    0xc(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
call   1080 <itoa@plt>
mov    0xc(%rsp),%edx
mov    %r15,%rdi
lea    0xe12(%rip),%rsi
mov    %rbx,%rcx
call   1050 <fprintf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1040 <fscanf@plt>
cmp    (%r12),%rax
jne    11f0 <main+0x90>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdaf(%rip),%rdi
jmp    125a <main+0xfa>
lea    0xdb2(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
jmp    1238 <main+0xd8>

LLVM IR (-O0):
@.str = [10 x i8] c"input.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.dat\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.5 = [13 x i8] c"%d, is '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %40
15: ; preds = %2
%16 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %40
21: ; preds = %15
br label %22
22: ; preds = %27, %21
%23 = load i32*, i32** %6
%24 = call i64 @fscanf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %8)
%25 = load i64, i64* @EOF
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %35
27: ; preds = %22
%28 = load i32, i32* %8
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%30 = call i32 @itoa(i32 %28, i8* %29)
%31 = load i32*, i32** %7
%32 = load i32, i32* %8
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%34 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %32, i8* %33)
br label %22
35: ; preds = %22
%36 = load i32*, i32** %6
%37 = call i32 @fclose(i32* %36)
%38 = load i32*, i32** %7
%39 = call i32 @fclose(i32* %38)
store i32 0, i32* %3
br label %40
40: ; preds = %35, %19, %13
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [10 x i8] c"input.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.dat\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.5 = [13 x i8] c"%d, is '%s'\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [128 x i8]
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %31
9: ; preds = %2
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %31
14: ; preds = %9
%15 = bitcast i32* %3 to i8*
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%17 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%18 = load i64, i64* @EOF
%19 = icmp eq i64 %17, %18
br i1 %19, label %28, label %20
20: ; preds = %14, %20
%21 = load i32, i32* %3
%22 = call i32 @itoa(i32 %21, i8* %16)
%23 = load i32, i32* %3
%24 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %23, i8* %16)
%25 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%26 = load i64, i64* @EOF
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %20
28: ; preds = %20, %14
%29 = call i32 @fclose(i32* %5)
%30 = call i32 @fclose(i32* %10)
br label %31
31: ; preds = %28, %12, %7
%32 = phi i32 [ 1, %7 ], [ 1, %12 ], [ 0, %28 ]
ret i32 %32
}