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

/* Variables and functions */
int atoi(char *);
int *calloc(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pupple(int *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int main(void) {
  int index = 0;
  char buf[100];
  FILE *p = fopen("D:\\temp\\a.txt", "r");
  while (!feof(p)) {
    memset(buf, 0, sizeof(buf));
    fgets(buf, sizeof(buf), p);
    index++;
  }
  fclose(p);
  int *array = calloc(sizeof(int), index);
  p = fopen("D:\\temp\\a.txt", "r");
  index = 0;
  while (!feof(p)) {
    memset(buf, 0, sizeof(buf));
    fgets(buf, sizeof(buf), p);
    array[index] = atoi(buf);
    index++;
  }
  fclose(p);
  pupple(array, index);
  p = fopen("D:\\temp\\b.txt", "w");
  int i;
  for (i = 0; i < index; i++) {
    memset(buf, 0, sizeof(buf));
    sprintf(buf, "%d\n", array[i]);
    fputs(buf, p);
  }
  fclose(p);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xe40(%rip),%rdi
lea    0xe47(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ee <main+0x4e>
jmp    121e <main+0x7e>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11d0 <main+0x30>
mov    -0x78(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%esi
mov    $0x4,%edi
call   1070 <calloc@plt>
mov    %rax,-0x80(%rbp)
lea    0xdc1(%rip),%rdi
lea    0xdc8(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x78(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x78(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1274 <main+0xd4>
jmp    12ba <main+0x11a>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
lea    -0x70(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,%edx
mov    -0x80(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1256 <main+0xb6>
mov    -0x78(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   10c0 <pupple@plt>
lea    0xd3a(%rip),%rdi
lea    0xd41(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x78(%rbp)
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    134e <main+0x1ae>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
lea    -0x70(%rbp),%rdi
mov    -0x80(%rbp),%rax
movslq -0x84(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xcf8(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%rsi
call   1040 <fputs@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    12f0 <main+0x150>
mov    -0x78(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xe4b(%rip),%rdi
lea    0xe52(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1080 <feof@plt>
xor    %ebx,%ebx
mov    $0x0,%ebp
test   %eax,%eax
jne    120e <main+0x6e>
xor    %ebp,%ebp
mov    %rsp,%r15
nopl   0x0(%rax)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
mov    %r15,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
add    $0x1,%ebp
mov    %r14,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     11e0 <main+0x40>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0x4,%edi
mov    %ebp,%esi
call   1070 <calloc@plt>
mov    %rax,%r14
lea    0xdd4(%rip),%rdi
lea    0xddb(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    128b <main+0xeb>
xor    %ebx,%ebx
mov    %rsp,%rbp
nopl   0x0(%rax)
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
mov    %rbp,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
mov    %rbp,%rdi
call   10a0 <atoi@plt>
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
mov    %r15,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     1250 <main+0xb0>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   10c0 <pupple@plt>
lea    0xd6c(%rip),%rdi
lea    0xd73(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
test   %ebx,%ebx
je     1302 <main+0x162>
mov    %ebx,%r13d
xor    %ebp,%ebp
mov    %rsp,%rbx
lea    0xd5a(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
mov    (%r14,%rbp,4),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <fputs@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    12d0 <main+0x130>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"D:\\temp\\a.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"D:\\temp\\b.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%7 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %4
br label %8
8: ; preds = %13, %0
%9 = load i32*, i32** %4
%10 = call i32 @feof(i32* %9)
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %21
13: ; preds = %8
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 100)
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%17 = load i32*, i32** %4
%18 = call i32 @fgets(i8* %16, i32 100, i32* %17)
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %8
21: ; preds = %8
%22 = load i32*, i32** %4
%23 = call i32 @fclose(i32* %22)
%24 = load i32, i32* %2
%25 = call i32* @calloc(i32 4, i32 %24)
store i32* %25, i32** %5
%26 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %4
store i32 0, i32* %2
br label %27
27: ; preds = %32, %21
%28 = load i32*, i32** %4
%29 = call i32 @feof(i32* %28)
%30 = icmp ne i32 %29, 0
%31 = xor i1 %30, true
br i1 %31, label %32, label %46
32: ; preds = %27
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%34 = call i32 @memset(i8* %33, i32 0, i32 100)
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%36 = load i32*, i32** %4
%37 = call i32 @fgets(i8* %35, i32 100, i32* %36)
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%39 = call i32 @atoi(i8* %38)
%40 = load i32*, i32** %5
%41 = load i32, i32* %2
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
store i32 %39, i32* %43
%44 = load i32, i32* %2
%45 = add nsw i32 %44, 1
store i32 %45, i32* %2
br label %27
46: ; preds = %27
%47 = load i32*, i32** %4
%48 = call i32 @fclose(i32* %47)
%49 = load i32*, i32** %5
%50 = load i32, i32* %2
%51 = call i32 @pupple(i32* %49, i32 %50)
%52 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 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* %52, i32** %4
store i32 0, i32* %6
br label %53
53: ; preds = %70, %46
%54 = load i32, i32* %6
%55 = load i32, i32* %2
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %73
57: ; preds = %53
%58 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%59 = call i32 @memset(i8* %58, i32 0, i32 100)
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%61 = load i32*, i32** %5
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %61, i64 %63
%65 = load i32, i32* %64
%66 = call i32 @sprintf(i8* %60, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %65)
%67 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%68 = load i32*, i32** %4
%69 = call i32 @fputs(i8* %67, i32* %68)
br label %70
70: ; preds = %57
%71 = load i32, i32* %6
%72 = add nsw i32 %71, 1
store i32 %72, i32* %6
br label %53
73: ; preds = %53
%74 = load i32*, i32** %4
%75 = call i32 @fclose(i32* %74)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"D:\\temp\\a.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"D:\\temp\\b.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @feof(i32* %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %0, %6
%7 = phi i32 [ %10, %6 ], [ 0, %0 ]
%8 = call i32 @memset(i8* %2, i32 0, i32 100)
%9 = call i32 @fgets(i8* %2, i32 100, i32* %3)
%10 = add nuw nsw i32 %7, 1
%11 = call i32 @feof(i32* %3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %6, label %13
13: ; preds = %6, %0
%14 = phi i32 [ 0, %0 ], [ %10, %6 ]
%15 = call i32 @fclose(i32* %3)
%16 = call i32* @calloc(i32 4, i32 %14)
%17 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @feof(i32* %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %31
20: ; preds = %13, %20
%21 = phi i64 [ %26, %20 ], [ 0, %13 ]
%22 = call i32 @memset(i8* %2, i32 0, i32 100)
%23 = call i32 @fgets(i8* %2, i32 100, i32* %17)
%24 = call i32 @atoi(i8* %2)
%25 = getelementptr inbounds i32, i32* %16, i64 %21
store i32 %24, i32* %25
%26 = add nuw i64 %21, 1
%27 = call i32 @feof(i32* %17)
%28 = icmp eq i32 %27, 0
br i1 %28, label %20, label %29
29: ; preds = %20
%30 = trunc i64 %26 to i32
br label %31
31: ; preds = %29, %13
%32 = phi i32 [ 0, %13 ], [ %30, %29 ]
%33 = call i32 @fclose(i32* %17)
%34 = call i32 @pupple(i32* %16, i32 %32)
%35 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp eq i32 %32, 0
br i1 %36, label %48, label %37
37: ; preds = %31
%38 = zext i32 %32 to i64
br label %39
39: ; preds = %37, %39
%40 = phi i64 [ 0, %37 ], [ %46, %39 ]
%41 = call i32 @memset(i8* %2, i32 0, i32 100)
%42 = getelementptr inbounds i32, i32* %16, i64 %40
%43 = load i32, i32* %42
%44 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %43)
%45 = call i32 @fputs(i8* %2, i32* %35)
%46 = add nuw nsw i64 %40, 1
%47 = icmp eq i64 %46, %38
br i1 %47, label %48, label %39
48: ; preds = %39, %31
%49 = call i32 @fclose(i32* %35)
ret i32 0
}