#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
float myran2(long *);
int /*<<< orphan*/ *open_writefile(char *);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  int i;
  int no_error = 1;
  int nrand = 0;
  long randseed;
  float tmprand;
  char outfile[1000];
  FILE *ofp = NULL;
  if (argc < 3) {
    fprintf(stderr, "\nUsage: randgen [outfile] [n]\n\n");
    fprintf(stderr, "  outfile is the requested output file name.\n");
    fprintf(stderr, "  n is the number of random numbers to be generated\n\n");
    return 1;
  }
  printf("\n");
  strcpy(outfile, argv[1]);
  if (sscanf(argv[2], "%d", &nrand) != 1 || nrand < 1) {
    fprintf(stderr, "ERROR: n must be a positive integer.\n\n");
    return 1;
  }
  printf("\nWill generate %d random numbers.\n", nrand);
  randseed = -97867564;
  if (!(ofp = open_writefile(outfile))) {
    fprintf(stderr, "ERROR: Cannot open output file.\n\n");
    return 1;
  }
  for (i = 0; i < nrand; i++) {
    tmprand = myran2(&randseed);
    fprintf(ofp, "%f\n", tmprand);
  }
  if (ofp)
    fclose(ofp);
  if (no_error) {
    printf("\nProgram randgen finished.\n\n");
    return 0;
  } else {
    fprintf(stderr, "\nERROR.  Exiting randgen.\n\n");
    return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x428(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11fd <main+0x8d>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1371 <main+0x201>
lea    0xf0e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe56(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    124a <main+0xda>
cmpl   $0x1,-0x1c(%rbp)
jge    126d <main+0xfd>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1371 <main+0x201>
mov    -0x1c(%rbp),%esi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0xfffffffffa2aa8d4,-0x28(%rbp)
fa
lea    -0x420(%rbp),%rdi
call   1060 <open_writefile@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
jne    12c6 <main+0x156>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1371 <main+0x201>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1315 <main+0x1a5>
lea    -0x28(%rbp),%rdi
call   1090 <myran2@plt>
movss  %xmm0,-0x2c(%rbp)
mov    -0x428(%rbp),%rax
mov    %eax,%edi
movss  -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdf3(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12cd <main+0x15d>
cmpq   $0x0,-0x428(%rbp)
je     132f <main+0x1bf>
mov    -0x428(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,-0x18(%rbp)
je     1353 <main+0x1e3>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1371 <main+0x201>
mov    0x2c86(%rip),%rax
mov    (%rax),%edi
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3f8,%rsp
movl   $0x0,0x4(%rsp)
cmp    $0x2,%edi
jg     11df <main+0x4f>
mov    0x2e2f(%rip),%rbx
mov    (%rbx),%edi
lea    0xe46(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe56(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe74(%rip),%rsi
jmp    12cb <main+0x13b>
mov    %rsi,%rbx
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rbx),%rsi
lea    0x10(%rsp),%rdi
call   1040 <strcpy@plt>
mov    0x10(%rbx),%rdi
lea    0xe7f(%rip),%rsi
lea    0x4(%rsp),%rdx
call   10a0 <sscanf@plt>
cmp    $0x1,%eax
jne    12a9 <main+0x119>
mov    0x4(%rsp),%esi
test   %esi,%esi
jle    12a9 <main+0x119>
lea    0xe83(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movq   $0xfffffffffa2aa8d4,0x8(%rsp)
2a fa
lea    0x10(%rsp),%rdi
call   1080 <open_writefile@plt>
test   %rax,%rax
je     12bb <main+0x12b>
mov    %rax,%rbx
cmpl   $0x0,0x4(%rsp)
jle    1291 <main+0x101>
xor    %ebp,%ebp
lea    0x8(%rsp),%r14
lea    0xe91(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   10b0 <myran2@plt>
cvtss2sd %xmm0,%xmm0
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1,%al
call   1090 <fprintf@plt>
add    $0x1,%ebp
cmp    0x4(%rsp),%ebp
jl     1270 <main+0xe0>
mov    %rbx,%rdi
call   1060 <fclose@plt>
lea    0xe57(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
jmp    12d7 <main+0x147>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
lea    0xdce(%rip),%rsi
jmp    12cb <main+0x13b>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"\0AUsage: randgen [outfile] [n]\0A\0A\00"
@.str.1 = [46 x i8] c" outfile is the requested output file name.\0A\00"
@.str.2 = [54 x i8] c" n is the number of random numbers to be generated\0A\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [39 x i8] c"ERROR: n must be a positive integer.\0A\0A\00"
@.str.6 = [35 x i8] c"\0AWill generate %d random numbers.\0A\00"
@.str.7 = [34 x i8] c"ERROR: Cannot open output file.\0A\0A\00"
@.str.8 = [4 x i8] c"%f\0A\00"
@.str.9 = [29 x i8] c"\0AProgram randgen finished.\0A\0A\00"
@.str.10 = [28 x i8] c"\0AERROR. Exiting randgen.\0A\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 i64
%10 = alloca float
%11 = alloca [1000 x i8]
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
store i32 0, i32* %8
store i32* null, i32** %12
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %78
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%24 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @strcpy(i8* %24, i8* %27)
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @sscanf(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %8)
%33 = icmp ne i32 %32, 1
br i1 %33, label %37, label %34
34: ; preds = %22
%35 = load i32, i32* %8
%36 = icmp slt i32 %35, 1
br i1 %36, label %37, label %40
37: ; preds = %34, %22
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %78
40: ; preds = %34
%41 = load i32, i32* %8
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i32 %41)
store i64 -97867564, i64* %9
%43 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%44 = call i32* @open_writefile(i8* %43)
store i32* %44, i32** %12
%45 = icmp ne i32* %44, null
br i1 %45, label %49, label %46
46: ; preds = %40
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %78
49: ; preds = %40
store i32 0, i32* %6
br label %50
50: ; preds = %61, %49
%51 = load i32, i32* %6
%52 = load i32, i32* %8
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %64
54: ; preds = %50
%55 = call float @myran2(i64* %9)
store float %55, float* %10
%56 = load i32*, i32** %12
%57 = ptrtoint i32* %56 to i32
%58 = load float, float* %10
%59 = fpext float %58 to double
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), double %59)
br label %61
61: ; preds = %54
%62 = load i32, i32* %6
%63 = add nsw i32 %62, 1
store i32 %63, i32* %6
br label %50
64: ; preds = %50
%65 = load i32*, i32** %12
%66 = icmp ne i32* %65, null
br i1 %66, label %67, label %70
67: ; preds = %64
%68 = load i32*, i32** %12
%69 = call i32 @fclose(i32* %68)
br label %70
70: ; preds = %67, %64
%71 = load i32, i32* %7
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %70
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %3
br label %78
75: ; preds = %70
%76 = load i32, i32* @stderr
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %3
br label %78
78: ; preds = %75, %73, %46, %37, %15
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"\0AUsage: randgen [outfile] [n]\0A\0A\00"
@.str.1 = [46 x i8] c" outfile is the requested output file name.\0A\00"
@.str.2 = [54 x i8] c" n is the number of random numbers to be generated\0A\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [39 x i8] c"ERROR: n must be a positive integer.\0A\0A\00"
@.str.6 = [35 x i8] c"\0AWill generate %d random numbers.\0A\00"
@.str.7 = [34 x i8] c"ERROR: Cannot open output file.\0A\0A\00"
@.str.8 = [4 x i8] c"%f\0A\00"
@str = [28 x i8] c"\0AProgram randgen finished.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca [1000 x i8]
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = bitcast i64* %4 to i8*
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%9 = icmp slt i32 %0, 3
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
br label %56
17: ; preds = %2
%18 = tail call i32 @putchar(i32 10)
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strcpy(i8* %8, i8* %20)
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%25 = icmp ne i32 %24, 1
%26 = load i32, i32* %3
%27 = icmp slt i32 %26, 1
%28 = select i1 %25, i1 true, i1 %27
br i1 %28, label %29, label %32
29: ; preds = %17
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
br label %56
32: ; preds = %17
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i32 %26)
store i64 -97867564, i64* %4
%34 = call i32* @open_writefile(i8* %8)
%35 = icmp eq i32* %34, null
br i1 %35, label %42, label %36
36: ; preds = %32
%37 = load i32, i32* %3
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %53
39: ; preds = %36
%40 = ptrtoint i32* %34 to i64
%41 = trunc i64 %40 to i32
br label %45
42: ; preds = %32
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
br label %56
45: ; preds = %39, %45
%46 = phi i32 [ 0, %39 ], [ %50, %45 ]
%47 = call float @myran2(i64* %4)
%48 = fpext float %47 to double
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), double %48)
%50 = add nuw nsw i32 %46, 1
%51 = load i32, i32* %3
%52 = icmp slt i32 %50, %51
br i1 %52, label %45, label %53
53: ; preds = %45, %36
%54 = call i32 @fclose(i32* %34)
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %56
56: ; preds = %53, %42, %29, %10
%57 = phi i32 [ 1, %10 ], [ 1, %29 ], [ 0, %53 ], [ 1, %42 ]
ret i32 %57
}