#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 errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ printf(char *, char *, ...);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
char *strerror(int);
int strtoul(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int num, i;
  FILE *f;
  if (argc < 3) {
    printf("Usage: %s <filename> <number>\n", argv[0]);
    return 1;
  }
  srand(time(NULL));
  f = fopen(argv[1], "a");
  if (!f) {
    do {
      int errsv = errno;
      printf("Unable to open file %s for writing"
             ": %s\n",
             argv[1], strerror(errsv));
      return errsv;
    } while (0);
    ;
  }
  num = strtoul(argv[2], NULL, 10);
  for (i = 0; i < num; i++) {
    fprintf(f, "%d ", rand() % 1000);
  }
  fclose(f);
  return 0;
}


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    11d1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ba <main+0x12a>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1249 <main+0xb9>
jmp    1209 <main+0x79>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
call   10a0 <strerror@plt>
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12ba <main+0x12a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1090 <strtoul@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12aa <main+0x11a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   10b0 <rand@plt>
mov    -0x38(%rbp),%rdi
mov    $0x3e8,%ecx
cltd
idiv   %ecx
lea    0xdb2(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1269 <main+0xd9>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
cmp    $0x2,%edi
jg     11bc <main+0x2c>
mov    0x0(%rbp),%rsi
lea    0xe56(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r14d
jmp    127a <main+0xea>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    0x8(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1250 <main+0xc0>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
xor    %r14d,%r14d
xor    %esi,%esi
mov    $0xa,%edx
call   1090 <strtoul@plt>
test   %eax,%eax
jle    1246 <main+0xb6>
mov    %eax,%ebp
lea    0xe47(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   10b0 <rand@plt>
movslq %eax,%rdx
imul   $0x10624dd3,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
imul   $0x3e8,%eax,%eax
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <fprintf@plt>
add    $0xffffffff,%ebp
jne    1210 <main+0x80>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    127a <main+0xea>
mov    0x2d89(%rip),%rax
mov    (%rax),%r14d
mov    0x8(%rbp),%rbx
mov    %r14d,%edi
call   10a0 <strerror@plt>
lea    0xdb4(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Usage: %s <filename> <number>\0A\00"
@.str.1 = [2 x i8] c"a\00"
@errno = global i32 0
@.str.2 = [40 x i8] c"Unable to open file %s for writing: %s\0A\00"
@.str.3 = [4 x i8] c"%d \00"
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
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %57
17: ; preds = %2
%18 = call i32 @time(i32* null)
%19 = call i32 @srand(i32 %18)
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %8
%24 = load i32*, i32** %8
%25 = icmp ne i32* %24, null
br i1 %25, label %37, label %26
26: ; preds = %17
br label %27
27: ; preds = %26
%28 = load i32, i32* @errno
store i32 %28, i32* %9
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = load i32, i32* %9
%33 = call i8* @strerror(i32 %32)
%34 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %31, i8* %33)
%35 = load i32, i32* %9
store i32 %35, i32* %3
br label %57
36: ; No predecessors!
br label %37
37: ; preds = %36, %17
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 @strtoul(i8* %40, i32* null, i32 10)
store i32 %41, i32* %6
store i32 0, i32* %7
br label %42
42: ; preds = %51, %37
%43 = load i32, i32* %7
%44 = load i32, i32* %6
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %54
46: ; preds = %42
%47 = load i32*, i32** %8
%48 = call i32 (...) @rand()
%49 = srem i32 %48, 1000
%50 = call i32 @fprintf(i32* %47, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %46
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %42
54: ; preds = %42
%55 = load i32*, i32** %8
%56 = call i32 @fclose(i32* %55)
store i32 0, i32* %3
br label %57
57: ; preds = %54, %27, %12
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str = [31 x i8] c"Usage: %s <filename> <number>\0A\00"
@.str.1 = [2 x i8] c"a\00"
@errno = global i32 0
@.str.2 = [40 x i8] c"Unable to open file %s for writing: %s\0A\00"
@.str.3 = [4 x i8] c"%d \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %33
7: ; preds = %2
%8 = tail call i32 @time(i32* null)
%9 = tail call i32 @srand(i32 %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %19
14: ; preds = %7
%15 = load i32, i32* @errno
%16 = load i8*, i8** %10
%17 = tail call i8* @strerror(i32 %15)
%18 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %16, i8* %17)
br label %33
19: ; preds = %7
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32 @strtoul(i8* nocapture %21, i32* null, i32 10)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %19, %24
%25 = phi i32 [ %29, %24 ], [ 0, %19 ]
%26 = tail call i32 (...) @rand()
%27 = srem i32 %26, 1000
%28 = tail call i32 @fprintf(i32* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = add nuw nsw i32 %25, 1
%30 = icmp eq i32 %29, %22
br i1 %30, label %31, label %24
31: ; preds = %24, %19
%32 = tail call i32 @fclose(i32* %12)
br label %33
33: ; preds = %31, %14, %4
%34 = phi i32 [ 1, %4 ], [ 0, %31 ], [ %15, %14 ]
ret i32 %34
}