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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(int *, int, int, int /*<<< orphan*/ *);
int fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int, ...);
int rand();
int main(void) {
  FILE *fout, *fin;
  char *binfile = "data.bin";
  int data[25], datacopy[25], n;
  fout = fopen(binfile, "wb");
  if (fout == NULL) {
    perror("fopen()");
    exit(EXIT_FAILURE);
  }
  for (int i = 0; i < 25; i++)
    *(data + i) = rand() % 1000;
  n = fwrite(data, sizeof(data[0]), sizeof(data) / sizeof(data[0]), fout);
  fclose(fout);
  printf("Written \'%d\' elements and \'%d\' byte to file: \'%s\'\n", n,
         n * sizeof(int), binfile);
  fin = fopen(binfile, "rb");
  if (fout == NULL) {
    perror("fopen()");
    exit(EXIT_FAILURE);
  }
  n = fread(datacopy, sizeof(int), 25, fin);
  for (int i = 0; i < n; i++)
    printf("data[%d] = %d\n", i, datacopy[i]);
  fclose(fin);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d6 <main+0x56>
lea    0xe49(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movl   $0x0,-0x108(%rbp)
cmpl   $0x19,-0x108(%rbp)
jge    121e <main+0x9e>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
movslq -0x108(%rbp),%rax
mov    %edx,-0x90(%rbp,%rax,4)
mov    -0x108(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x108(%rbp)
jmp    11e0 <main+0x60>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x19,%edx
call   1090 <fwrite@plt>
mov    %eax,-0x104(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x104(%rbp),%esi
movslq -0x104(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
mov    -0x20(%rbp),%rcx
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    0xdd0(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    12a5 <main+0x125>
lea    0xd7a(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    -0x100(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
mov    $0x19,%edx
call   1030 <fread@plt>
mov    %eax,-0x104(%rbp)
movl   $0x0,-0x10c(%rbp)
mov    -0x10c(%rbp),%eax
cmp    -0x104(%rbp),%eax
jge    1317 <main+0x197>
mov    -0x10c(%rbp),%esi
movslq -0x10c(%rbp),%rax
mov    -0x100(%rbp,%rax,4),%edx
lea    0xd4e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10c(%rbp)
jmp    12cf <main+0x14f>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2cb1(%rip),%rax
mov    (%rax),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xd8,%rsp
lea    0xe6b(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1298 <main+0x118>
mov    %rax,%r14
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   10a0 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x70(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x19,%rbx
jne    11b0 <main+0x30>
lea    0x70(%rsp),%rdi
mov    $0x4,%esi
mov    $0x19,%edx
mov    %r14,%rcx
call   1090 <fwrite@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0x0(,%rbx,4),%edx
lea    0xe02(%rip),%rdi
lea    0xde7(%rip),%r14
mov    %ebx,%esi
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe1b(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x4,%esi
mov    $0x19,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    1278 <main+0xf8>
mov    %eax,%r12d
lea    0xdf0(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%rsp,%rbx,4),%edx
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1260 <main+0xe0>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x2d51(%rip),%rax
mov    (%rax),%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd6d(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"data.bin\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [8 x i8] c"fopen()\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [51 x i8] c"Written '%d' elements and '%d' byte to file: '%s'\0A\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [15 x i8] c"data[%d] = %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca [25 x i32]
%6 = alloca [25 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %4
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %2
%12 = load i32*, i32** %2
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %0
store i32 0, i32* %8
br label %19
19: ; preds = %29, %18
%20 = load i32, i32* %8
%21 = icmp slt i32 %20, 25
br i1 %21, label %22, label %32
22: ; preds = %19
%23 = call i32 (...) @rand()
%24 = srem i32 %23, 1000
%25 = getelementptr inbounds [25 x i32], [25 x i32]* %5, i64 0, i64 0
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
store i32 %24, i32* %28
br label %29
29: ; preds = %22
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
br label %19
32: ; preds = %19
%33 = getelementptr inbounds [25 x i32], [25 x i32]* %5, i64 0, i64 0
%34 = load i32*, i32** %2
%35 = call i32 @fwrite(i32* %33, i32 4, i32 25, i32* %34)
store i32 %35, i32* %7
%36 = load i32*, i32** %2
%37 = call i32 @fclose(i32* %36)
%38 = load i32, i32* %7
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = mul i64 %40, 4
%42 = trunc i64 %41 to i32
%43 = load i8*, i8** %4
%44 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %38, i32 %42, i8* %43)
%45 = load i8*, i8** %4
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %46, i32** %3
%47 = load i32*, i32** %2
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %53
49: ; preds = %32
%50 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %32
%54 = getelementptr inbounds [25 x i32], [25 x i32]* %6, i64 0, i64 0
%55 = load i32*, i32** %3
%56 = call i32 @fread(i32* %54, i32 4, i32 25, i32* %55)
store i32 %56, i32* %7
store i32 0, i32* %9
br label %57
57: ; preds = %68, %53
%58 = load i32, i32* %9
%59 = load i32, i32* %7
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %71
61: ; preds = %57
%62 = load i32, i32* %9
%63 = load i32, i32* %9
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [25 x i32], [25 x i32]* %6, i64 0, i64 %64
%66 = load i32, i32* %65
%67 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %62, i32 %66)
br label %68
68: ; preds = %61
%69 = load i32, i32* %9
%70 = add nsw i32 %69, 1
store i32 %70, i32* %9
br label %57
71: ; preds = %57
%72 = load i32*, i32** %3
%73 = call i32 @fclose(i32* %72)
%74 = load i32, i32* @EXIT_SUCCESS
ret i32 %74
}

LLVM IR (-O2):
@.str = [9 x i8] c"data.bin\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [8 x i8] c"fopen()\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [51 x i8] c"Written '%d' elements and '%d' byte to file: '%s'\0A\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [15 x i8] c"data[%d] = %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [25 x i32]
%2 = alloca [25 x i32]
%3 = bitcast [25 x i32]* %1 to i8*
%4 = bitcast [25 x i32]* %2 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %23
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %23
%12 = getelementptr inbounds [25 x i32], [25 x i32]* %1, i64 0, i64 0
%13 = call i32 @fwrite(i32* %12, i32 4, i32 25, i32* %5)
%14 = tail call i32 @fclose(i32* %5)
%15 = shl i32 %13, 2
%16 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%18 = getelementptr inbounds [25 x i32], [25 x i32]* %2, i64 0, i64 0
%19 = call i32 @fread(i32* %18, i32 4, i32 25, i32* %17)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %11
%22 = zext i32 %19 to i64
br label %33
23: ; preds = %0, %23
%24 = phi i64 [ %28, %23 ], [ 0, %0 ]
%25 = tail call i32 (...) @rand()
%26 = srem i32 %25, 1000
%27 = getelementptr inbounds [25 x i32], [25 x i32]* %1, i64 0, i64 %24
store i32 %26, i32* %27
%28 = add nuw nsw i64 %24, 1
%29 = icmp eq i64 %28, 25
br i1 %29, label %11, label %23
30: ; preds = %33, %11
%31 = tail call i32 @fclose(i32* %17)
%32 = load i32, i32* @EXIT_SUCCESS
ret i32 %32
33: ; preds = %21, %33
%34 = phi i64 [ 0, %21 ], [ %39, %33 ]
%35 = getelementptr inbounds [25 x i32], [25 x i32]* %2, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = trunc i64 %34 to i32
%38 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %37, i32 %36)
%39 = add nuw nsw i64 %34, 1
%40 = icmp eq i64 %39, %22
br i1 %40, label %30, label %33
}