#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 atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  FILE *fb_out;
  int i, n, x;
  if (argc != 3) {
    fprintf(stderr, "Wrong number of arguments. Syntax: %s n fileOutput\n",
            argv[0]);
    return -1;
  }
  n = atoi(argv[1]);
  if ((fb_out = fopen(argv[2], "wb")) == NULL) {
    fprintf(stderr, "Error opening the output file.\n");
    return -1;
  }
  srand(time(NULL));
  for (i = 0; i < n; i++) {
    x = rand();
    fwrite(&x, sizeof(int), 1, fb_out);
    fprintf(stdout, "%d ", x);
  }
  fprintf(stdout, "\n");
  fclose(fb_out);
  return 0;
}


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)
cmpl   $0x3,-0x8(%rbp)
je     11ca <main+0x4a>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b2 <main+0x132>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe4b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    121f <main+0x9f>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b2 <main+0x132>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    128b <main+0x10b>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1236 <main+0xb6>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1248 <main+0xc8>
mov    0x8(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
lea    0xe87(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1264 <main+0xe4>
mov    %rax,%rbx
xor    %r14d,%r14d
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
test   %ebp,%ebp
jle    1227 <main+0xa7>
lea    0x4(%rsp),%r15
mov    0x2df9(%rip),%r13
lea    0xe71(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %eax,0x4(%rsp)
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    0x0(%r13),%edi
mov    0x4(%rsp),%edx
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0xffffffff,%ebp
jne    11f0 <main+0x70>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1281 <main+0x101>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xda5(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    127b <main+0xfb>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0xdc3(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [52 x i8] c"Wrong number of arguments. Syntax: %s n fileOutput\0A\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [32 x i8] c"Error opening the output file.\0A\00"
@stdout = global i32 0
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [2 x i8] c"\0A\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 ne i32 %10, 3
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 -1, i32* %3
br label %53
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %8
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %6
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %18
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %53
31: ; preds = %18
%32 = call i32 @time(i32* null)
%33 = call i32 @srand(i32 %32)
store i32 0, i32* %7
br label %34
34: ; preds = %45, %31
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %48
38: ; preds = %34
%39 = call i32 (...) @rand()
store i32 %39, i32* %9
%40 = load i32*, i32** %6
%41 = call i32 @fwrite(i32* %9, i32 4, i32 1, i32* %40)
%42 = load i32, i32* @stdout
%43 = load i32, i32* %9
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %38
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %34
48: ; preds = %34
%49 = load i32, i32* @stdout
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%51 = load i32*, i32** %6
%52 = call i32 @fclose(i32* %51)
store i32 0, i32* %3
br label %53
53: ; preds = %48, %28, %12
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [52 x i8] c"Wrong number of arguments. Syntax: %s n fileOutput\0A\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [32 x i8] c"Error opening the output file.\0A\00"
@stdout = global i32 0
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %38
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %38
21: ; preds = %10
%22 = tail call i32 @time(i32* null)
%23 = tail call i32 @srand(i32 %22)
%24 = icmp sgt i32 %13, 0
br i1 %24, label %25, label %34
25: ; preds = %21, %25
%26 = phi i32 [ %32, %25 ], [ 0, %21 ]
%27 = tail call i32 (...) @rand()
store i32 %27, i32* %3
%28 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32* %16)
%29 = load i32, i32* @stdout
%30 = load i32, i32* %3
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = add nuw nsw i32 %26, 1
%33 = icmp eq i32 %32, %13
br i1 %33, label %34, label %25
34: ; preds = %25, %21
%35 = load i32, i32* @stdout
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%37 = tail call i32 @fclose(i32* %16)
br label %38
38: ; preds = %34, %18, %6
%39 = phi i32 [ -1, %6 ], [ -1, %18 ], [ 0, %34 ]
ret i32 %39
}