#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;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int atoi(char *);
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int rand();
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
scalar_t__ strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int write(int, char *, scalar_t__);
int main(int argc, char **argv) {
  int i, out_fd, ec = 0;
  if (argc < 3) {
    return -1;
  }
  srand(time(NULL));
  out_fd = open(argv[2], O_CREAT | O_TRUNC | O_RDWR, 0644);
  if (out_fd < 0) {
    return -2;
  }
  for (i = 0; i < atoi(argv[1]); i++) {
    char buf[16];
    snprintf(buf, sizeof(buf) - 1, "%d", rand());
    if (write(out_fd, buf, strlen(buf)) != (int)strlen(buf)) {
      ec = -3;
      break;
    }
  }
  close(out_fd);
  return ec;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11c3 <main+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d3 <main+0x143>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
mov    0x2e05(%rip),%rax
or     (%rax),%esi
mov    0x2de4(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1219 <main+0x89>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12d3 <main+0x143>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    12c5 <main+0x135>
lea    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   10b0 <rand@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%ecx
mov    $0xf,%esi
lea    0xd9f(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x44(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %eax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
je     12b2 <main+0x122>
movl   $0xfffffffd,-0x1c(%rbp)
jmp    12c5 <main+0x135>
jmp    12b7 <main+0x127>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1220 <main+0x90>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0xffffffff,%r14d
cmp    $0x3,%edi
jl     1278 <main+0xe8>
mov    %rsi,%r15
xor    %r14d,%r14d
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    0x2e30(%rip),%rax
mov    0x2e21(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x10(%r15),%rdi
mov    0x2dfa(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1090 <open@plt>
test   %eax,%eax
js     1262 <main+0xd2>
mov    %eax,%r12d
mov    0x8(%r15),%rdi
call   10a0 <atoi@plt>
test   %eax,%eax
jle    1270 <main+0xe0>
lea    0xdfb(%rip),%r14
mov    %rsp,%r13
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10b0 <rand@plt>
mov    %r13,%rdi
mov    $0xf,%esi
mov    %r14,%rdx
mov    %eax,%ecx
call   1050 <snprintf@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %r12d,%edi
mov    %r13,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebp
jne    126a <main+0xda>
add    $0x1,%ebx
mov    0x8(%r15),%rdi
call   10a0 <atoi@plt>
cmp    %eax,%ebx
jl     1210 <main+0x80>
xor    %r14d,%r14d
jmp    1270 <main+0xe0>
mov    $0xfffffffe,%r14d
jmp    1278 <main+0xe8>
mov    $0xfffffffd,%r14d
mov    %r12d,%edi
call   1060 <close@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@.str = [3 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 [16 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %58
13: ; preds = %2
%14 = call i32 @time(i32* null)
%15 = call i32 @srand(i32 %14)
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_CREAT
%20 = load i32, i32* @O_TRUNC
%21 = or i32 %19, %20
%22 = load i32, i32* @O_RDWR
%23 = or i32 %21, %22
%24 = call i32 @open(i8* %18, i32 %23, i32 420)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %13
store i32 -2, i32* %3
br label %58
28: ; preds = %13
store i32 0, i32* %6
br label %29
29: ; preds = %51, %28
%30 = load i32, i32* %6
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
%35 = icmp slt i32 %30, %34
br i1 %35, label %36, label %54
36: ; preds = %29
%37 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%38 = call i32 (...) @rand()
%39 = call i32 @snprintf(i8* %37, i32 15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %7
%41 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%42 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%43 = call i64 @strlen(i8* %42)
%44 = call i32 @write(i32 %40, i8* %41, i64 %43)
%45 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%46 = call i64 @strlen(i8* %45)
%47 = trunc i64 %46 to i32
%48 = icmp ne i32 %44, %47
br i1 %48, label %49, label %50
49: ; preds = %36
store i32 -3, i32* %8
br label %54
50: ; preds = %36
br label %51
51: ; preds = %50
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1
store i32 %53, i32* %6
br label %29
54: ; preds = %49, %29
%55 = load i32, i32* %7
%56 = call i32 @close(i32 %55)
%57 = load i32, i32* %8
store i32 %57, i32* %3
br label %58
58: ; preds = %54, %27, %12
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@.str = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [16 x i8]
%4 = icmp slt i32 %0, 3
br i1 %4, label %40, label %5
5: ; preds = %2
%6 = tail call i32 @time(i32* null)
%7 = tail call i32 @srand(i32 %6)
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_CREAT
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %11, %10
%13 = load i32, i32* @O_RDWR
%14 = or i32 %12, %13
%15 = tail call i32 @open(i8* %9, i32 %14, i32 420)
%16 = icmp slt i32 %15, 0
br i1 %16, label %40, label %17
17: ; preds = %5
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
%22 = icmp sgt i32 %21, 0
br i1 %22, label %27, label %37
23: ; preds = %27
%24 = load i8*, i8** %19
%25 = call i32 @atoi(i8* %24)
%26 = icmp slt i32 %36, %25
br i1 %26, label %27, label %37
27: ; preds = %17, %23
%28 = phi i32 [ %36, %23 ], [ 0, %17 ]
%29 = call i32 (...) @rand()
%30 = call i32 @snprintf(i8* %18, i32 15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = call i64 @strlen(i8* %18)
%32 = call i32 @write(i32 %15, i8* %18, i64 %31)
%33 = call i64 @strlen(i8* %18)
%34 = trunc i64 %33 to i32
%35 = icmp eq i32 %32, %34
%36 = add nuw nsw i32 %28, 1
br i1 %35, label %23, label %37
37: ; preds = %23, %27, %17
%38 = phi i32 [ 0, %17 ], [ -3, %27 ], [ 0, %23 ]
%39 = call i32 @close(i32 %15)
br label %40
40: ; preds = %5, %2, %37
%41 = phi i32 [ %38, %37 ], [ -1, %2 ], [ -2, %5 ]
ret i32 %41
}