#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_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
size_t atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc < 3) {
    fprintf(stderr, "usage: fread_fwrite <repeats>\n");
    exit(EXIT_FAILURE);
  }
  size_t repeats = atoi(argv[1]);
  size_t chunk_size = atoi(argv[2]);
  for (int i = 0; i < repeats; ++i) {
    FILE *src = fopen("test.dat", "r");
    if (src == NULL) {
      fprintf(stderr, "error opening test.dat");
      exit(EXIT_FAILURE);
    }
    FILE *dst = fopen("output.dat", "w");
    if (dst == NULL) {
      fprintf(stderr, "error opening output.dat");
      exit(EXIT_FAILURE);
    }
    char *buffer = malloc(chunk_size);
    fclose(src);
    fclose(dst);
    free(buffer);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11b3 <main+0x43>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    12aa <main+0x13a>
lea    0xe3e(%rip),%rdi
lea    0xe27(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    122f <main+0xbf>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe12(%rip),%rdi
lea    0xdfb(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1274 <main+0x104>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11dc <main+0x6c>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     11a3 <main+0x33>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
call   1080 <atoi@plt>
test   %rbx,%rbx
je     122b <main+0xbb>
mov    %rax,%r14
lea    0xe6e(%rip),%rbp
nopw   0x0(%rax,%rax,1)
lea    0xe58(%rip),%rdi
lea    0xe41(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1239 <main+0xc9>
mov    %rax,%r15
lea    0xe56(%rip),%rdi
mov    %rbp,%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     124e <main+0xde>
mov    %rax,%r12
mov    %r14,%rdi
call   1060 <malloc@plt>
mov    %rax,%r13
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r13,%rdi
call   1030 <free@plt>
add    $0xffffffffffffffff,%rbx
jne    11d0 <main+0x60>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
lea    0xdd8(%rip),%rsi
jmp    1190 <main+0x20>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
jmp    1190 <main+0x20>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"usage: fread_fwrite <repeats>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"test.dat\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [23 x i8] c"error opening test.dat\00"
@.str.4 = [11 x i8] c"output.dat\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [25 x i8] c"error opening output.dat\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @atoi(i8* %22)
store i64 %23, i64* %6
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i64 @atoi(i8* %26)
store i64 %27, i64* %7
store i32 0, i32* %8
br label %28
28: ; preds = %60, %19
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = load i64, i64* %6
%32 = icmp ult i64 %30, %31
br i1 %32, label %33, label %63
33: ; preds = %28
%34 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %34, i32** %9
%35 = load i32*, i32** %9
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %33
%43 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %43, i32** %10
%44 = load i32*, i32** %10
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %51
46: ; preds = %42
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %42
%52 = load i64, i64* %7
%53 = call i8* @malloc(i64 %52)
store i8* %53, i8** %11
%54 = load i32*, i32** %9
%55 = call i32 @fclose(i32* %54)
%56 = load i32*, i32** %10
%57 = call i32 @fclose(i32* %56)
%58 = load i8*, i8** %11
%59 = call i32 @free(i8* %58)
br label %60
60: ; preds = %51
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
br label %28
63: ; preds = %28
%64 = load i32, i32* @EXIT_SUCCESS
%65 = call i32 @exit(i32 %64)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"usage: fread_fwrite <repeats>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"test.dat\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [23 x i8] c"error opening test.dat\00"
@.str.4 = [11 x i8] c"output.dat\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [25 x i8] c"error opening output.dat\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @atoi(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i64 @atoi(i8* %14)
%16 = icmp eq i64 %12, 0
br i1 %16, label %17, label %20
17: ; preds = %37, %9
%18 = load i32, i32* @EXIT_SUCCESS
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %9, %37
%21 = phi i64 [ %42, %37 ], [ 0, %9 ]
%22 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %20
%30 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = tail call i32 @exit(i32 %35)
unreachable
37: ; preds = %29
%38 = tail call i8* @malloc(i64 %15)
%39 = tail call i32 @fclose(i32* %22)
%40 = tail call i32 @fclose(i32* %30)
%41 = tail call i32 @free(i8* %38)
%42 = add nuw i64 %21, 1
%43 = icmp eq i64 %42, %12
br i1 %43, label %17, label %20
}