#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 */

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *);
int rand();
int /*<<< orphan*/ sprintf(char *, char *, float);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char buff[100];
  float num;
  int i = 0;
  if (argc < 3) {
    printf("Usage:  ./Program out.txt 1000\n");
    return -1;
  }
  int fout = open(argv[1], O_CREAT | O_RDWR, 0640);
  if (fout < 0)
    return -1;
  int n = 0;
  sscanf(argv[2], "%d", &n);
  while (i < n) {
    num = rand() % 1000 / 1000.0;
    sprintf(buff, "%f ", num);
    write(fout, buff, strlen(buff));
    i++;
  }
  close(fout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x88(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11c5 <main+0x45>
lea    0xe54(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12dc <main+0x15c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
mov    0x2e03(%rip),%rax
or     (%rax),%esi
mov    $0x1a0,%edx
call   1080 <open@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
jge    1208 <main+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    12dc <main+0x15c>
movl   $0x0,-0x90(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe07(%rip),%rsi
lea    -0x90(%rbp),%rdx
call   1070 <sscanf@plt>
mov    -0x88(%rbp),%eax
cmp    -0x90(%rbp),%eax
jge    12ca <main+0x14a>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cvtsi2sd %edx,%xmm0
movsd  0xda6(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x84(%rbp)
ff
lea    -0x80(%rbp),%rdi
movss  -0x84(%rbp),%xmm0
ff
lea    0xdae(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x8c(%rbp),%eax
mov    %eax,-0x9c(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    122d <main+0xad>
mov    -0x8c(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
cmp    $0x2,%edi
jg     11a0 <main+0x20>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
jmp    126d <main+0xed>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e4a(%rip),%rax
mov    0x2e2b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1a0,%edx
call   1080 <open@plt>
test   %eax,%eax
js     126d <main+0xed>
mov    %eax,%r15d
movl   $0x0,0xc(%rsp)
mov    0x10(%rbx),%rdi
lea    0xe27(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1070 <sscanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1261 <main+0xe1>
lea    0xe12(%rip),%r14
lea    0x10(%rsp),%rbx
xor    %ebp,%ebp
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
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xdcc(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
add    $0x1,%ebp
cmp    0xc(%rsp),%ebp
jl     1200 <main+0x80>
mov    %r15d,%edi
call   1060 <close@plt>
xor    %eax,%eax
jmp    1272 <main+0xf2>
mov    $0xffffffff,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Usage: ./Program out.txt 1000\0A\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%f \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca float
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %54
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_CREAT
%20 = load i32, i32* @O_RDWR
%21 = or i32 %19, %20
%22 = call i32 @open(i8* %18, i32 %21, i32 416)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %15
store i32 -1, i32* %3
br label %54
26: ; preds = %15
store i32 0, i32* %10
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @sscanf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %10)
br label %31
31: ; preds = %35, %26
%32 = load i32, i32* %8
%33 = load i32, i32* %10
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %51
35: ; preds = %31
%36 = call i32 (...) @rand()
%37 = srem i32 %36, 1000
%38 = sitofp i32 %37 to double
%39 = fdiv double %38, 1.000000e+03
%40 = fptrunc double %39 to float
store float %40, float* %7
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%42 = load float, float* %7
%43 = call i32 @sprintf(i8* %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), float %42)
%44 = load i32, i32* %9
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
%48 = call i32 @write(i32 %44, i8* %45, i32 %47)
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %31
51: ; preds = %31
%52 = load i32, i32* %9
%53 = call i32 @close(i32 %52)
store i32 0, i32* %3
br label %54
54: ; preds = %51, %25, %13
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%f \00"
@str = [31 x i8] c"Usage: ./Program out.txt 1000\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = icmp slt i32 %0, 3
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %39
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_CREAT
%13 = load i32, i32* @O_RDWR
%14 = or i32 %13, %12
%15 = tail call i32 @open(i8* %11, i32 %14, i32 416)
%16 = icmp slt i32 %15, 0
br i1 %16, label %39, label %17
17: ; preds = %9
%18 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%22 = load i32, i32* %4
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %37
24: ; preds = %17, %24
%25 = phi i32 [ %34, %24 ], [ 0, %17 ]
%26 = call i32 (...) @rand()
%27 = srem i32 %26, 1000
%28 = sitofp i32 %27 to double
%29 = fdiv double %28, 1.000000e+03
%30 = fptrunc double %29 to float
%31 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), float %30)
%32 = call i32 @strlen(i8* %5)
%33 = call i32 @write(i32 %15, i8* %5, i32 %32)
%34 = add nuw nsw i32 %25, 1
%35 = load i32, i32* %4
%36 = icmp slt i32 %34, %35
br i1 %36, label %24, label %37
37: ; preds = %24, %17
%38 = call i32 @close(i32 %15)
br label %39
39: ; preds = %37, %9, %7
%40 = phi i32 [ -1, %7 ], [ 0, %37 ], [ -1, %9 ]
ret i32 %40
}