#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ stderr;
int main() {
  FILE *in, *out;
  int num, count = 0;
  if ((in = fopen("d.txt", "r")) == NULL) {
    fprintf(stderr, "Cannot open input file - exiting!\n");
    exit(1);
  }
  if ((out = fopen("d2.txt", "w")) == NULL) {
    fprintf(stderr, "Cannot open output file - exiting!\n");
    exit(1);
  }
  fscanf(in, "%d", &num);
  while (!feof(in)) {
    fprintf(out, "Num %d = %d\n", ++count, num);
    fscanf(in, "%d", &num);
  }
  fclose(in);
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xe83(%rip),%rdi
lea    0xe82(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11b9 <main+0x59>
mov    0x2e42(%rip),%rax
movslq (%rax),%rdi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe6b(%rip),%rdi
lea    0xe6b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11fc <main+0x9c>
mov    0x2dff(%rip),%rax
movslq (%rax),%rdi
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xe51(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    122e <main+0xce>
jmp    1265 <main+0x105>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
mov    -0x1c(%rbp),%ecx
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe01(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <fscanf@plt>
jmp    1210 <main+0xb0>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe7e(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1251 <main+0xe1>
mov    %rax,%rbx
lea    0xe8a(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1269 <main+0xf9>
mov    %rax,%r14
lea    0xe98(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1230 <main+0xc0>
mov    $0x1,%ebp
lea    0xe76(%rip),%r15
lea    0xe6c(%rip),%r12
lea    0x4(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x4(%rsp),%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
add    $0x1,%ebp
test   %eax,%eax
je     1200 <main+0x90>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d88(%rip),%rax
movslq (%rax),%rcx
lea    0xda6(%rip),%rdi
mov    $0x22,%esi
jmp    127f <main+0x10f>
mov    0x2d70(%rip),%rax
movslq (%rax),%rcx
lea    0xdba(%rip),%rdi
mov    $0x23,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"d.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [35 x i8] c"Cannot open input file - exiting!\0A\00"
@.str.3 = [7 x i8] c"d2.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [36 x i8] c"Cannot open output file - exiting!\0A\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [13 x i8] c"Num %d = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
%6 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %14
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i32*
%12 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %15, i32** %3
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i32*
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = load i32*, i32** %2
%25 = call i32 @fscanf(i32* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %4)
br label %26
26: ; preds = %31, %23
%27 = load i32*, i32** %2
%28 = call i32 @feof(i32* %27)
%29 = icmp ne i32 %28, 0
%30 = xor i1 %29, true
br i1 %30, label %31, label %39
31: ; preds = %26
%32 = load i32*, i32** %3
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
%35 = load i32, i32* %4
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %34, i32 %35)
%37 = load i32*, i32** %2
%38 = call i32 @fscanf(i32* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %4)
br label %26
39: ; preds = %26
%40 = load i32*, i32** %2
%41 = call i32 @fclose(i32* %40)
%42 = load i32*, i32** %3
%43 = call i32 @fclose(i32* %42)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"d.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [35 x i8] c"Cannot open input file - exiting!\0A\00"
@.str.3 = [7 x i8] c"d2.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [36 x i8] c"Cannot open output file - exiting!\0A\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [13 x i8] c"Num %d = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %11
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = sext i32 %6 to i64
%8 = inttoptr i64 %7 to i32*
%9 = tail call i64 @fwrite(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i64 34, i64 1, i32* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i32*
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i64 35, i64 1, i32* %17)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %11
%21 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %1)
%22 = call i32 @feof(i32* %3)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %20, %24
%25 = phi i32 [ %26, %24 ], [ 0, %20 ]
%26 = add nuw nsw i32 %25, 1
%27 = load i32, i32* %1
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %26, i32 %27)
%29 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %1)
%30 = call i32 @feof(i32* %3)
%31 = icmp eq i32 %30, 0
br i1 %31, label %24, label %32
32: ; preds = %24, %20
%33 = call i32 @fclose(i32* %3)
%34 = call i32 @fclose(i32* %12)
ret i32 0
}