#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 EXIT_SUCCESS;
int /*<<< orphan*/ assert(int);
int atoi(char *);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int rand();
int main(int argc, char *argv[1]) {
  int test_size = 1000, i, key;
  FILE *fout = NULL;
  if (argc == 2) {
    test_size = atoi(argv[1]);
    fout = fopen("input.dat", "wb");
  } else if (argc == 3) {
    test_size = atoi(argv[1]);
    fout = fopen(argv[2], "wb");
  }
  assert(fout != NULL);
  for (i = 0; i < test_size; i++) {
    key = rand() % 10000;
    fwrite(&key, sizeof(int), 1, fout);
  }
  assert(fclose(fout) == 0);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x3e8,-0x14(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11bb <main+0x5b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
lea    0xe5a(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
jmp    11f2 <main+0x92>
cmpl   $0x3,-0x8(%rbp)
jne    11ed <main+0x8d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe26(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
jmp    11f2 <main+0x92>
cmpq   $0x0,-0x28(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    124e <main+0xee>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x28(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    120b <main+0xab>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
je     118a <main+0x2a>
cmp    $0x2,%edi
jne    11aa <main+0x4a>
mov    0x8(%r14),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
lea    0xe78(%rip),%rdi
jmp    1199 <main+0x39>
mov    0x8(%r14),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
mov    0x10(%r14),%rdi
lea    0xe6a(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
jmp    11b2 <main+0x52>
mov    $0x3e8,%ebx
xor    %r14d,%r14d
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1040 <assert@plt>
test   %ebx,%ebx
jle    1213 <main+0xb3>
lea    0xc(%rsp),%r15
nopl   0x0(%rax)
xor    %eax,%eax
call   1080 <rand@plt>
cltq
imul   $0x68db8bad,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rcx
add    %edx,%ecx
imul   $0x2710,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0xc(%rsp)
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
add    $0xffffffff,%ebx
jne    11d0 <main+0x70>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"input.dat\00"
@.str.1 = [3 x i8] c"wb\00"
@EXIT_SUCCESS = global i32 0
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 i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1000, i32* %6
store i32* null, i32** %9
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %6
%17 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %9
br label %31
18: ; preds = %2
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 3
br i1 %20, label %21, label %30
21: ; preds = %18
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %6
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %9
br label %30
30: ; preds = %21, %18
br label %31
31: ; preds = %30, %12
%32 = load i32*, i32** %9
%33 = icmp ne i32* %32, null
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
store i32 0, i32* %7
br label %36
36: ; preds = %45, %31
%37 = load i32, i32* %7
%38 = load i32, i32* %6
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %48
40: ; preds = %36
%41 = call i32 (...) @rand()
%42 = srem i32 %41, 10000
store i32 %42, i32* %8
%43 = load i32*, i32** %9
%44 = call i32 @fwrite(i32* %8, i32 4, i32 1, i32* %43)
br label %45
45: ; preds = %40
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %36
48: ; preds = %36
%49 = load i32*, i32** %9
%50 = call i64 @fclose(i32* %49)
%51 = icmp eq i64 %50, 0
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = load i32, i32* @EXIT_SUCCESS
ret i32 %54
}

LLVM IR (-O2):
@.str = [10 x i8] c"input.dat\00"
@.str.1 = [3 x i8] c"wb\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
switch i32 %0, label %19 [
i32 2, label %5
i32 3, label %9
]
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
br label %15
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
br label %15
15: ; preds = %5, %9
%16 = phi i8* [ %14, %9 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %5 ]
%17 = phi i32 [ %12, %9 ], [ %8, %5 ]
%18 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %15, %2
%20 = phi i32 [ 1000, %2 ], [ %17, %15 ]
%21 = phi i32* [ null, %2 ], [ %18, %15 ]
%22 = icmp ne i32* %21, null
%23 = zext i1 %22 to i32
%24 = tail call i32 @assert(i32 %23)
%25 = icmp sgt i32 %20, 0
br i1 %25, label %26, label %33
26: ; preds = %19, %26
%27 = phi i32 [ %31, %26 ], [ 0, %19 ]
%28 = tail call i32 (...) @rand()
%29 = srem i32 %28, 10000
store i32 %29, i32* %3
%30 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32* %21)
%31 = add nuw nsw i32 %27, 1
%32 = icmp eq i32 %31, %20
br i1 %32, label %33, label %26
33: ; preds = %26, %19
%34 = tail call i64 @fclose(i32* %21)
%35 = icmp eq i64 %34, 0
%36 = zext i1 %35 to i32
%37 = tail call i32 @assert(i32 %36)
%38 = load i32, i32* @EXIT_SUCCESS
ret i32 %38
}