#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 RAND_MAX;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ shuffle(int *, int);
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int i;
  int num = 0;
  char filename[] = "./numbers.txt";
  int *numbers = NULL;
  FILE *fp = NULL;
  srand((unsigned)time(NULL));
  printf("RAND_MAX:%d\n", RAND_MAX);
  printf("How many random numbers you want in '%s': ", filename);
  scanf("%d", &num);
  fp = fopen(filename, "w");
  if (!fp) {
    printf("create file '%s' failed!", filename);
    return 0;
  }
  fprintf(fp, "%d\n", num);
  numbers = malloc(num * sizeof(int));
  for (i = 0; i < num; ++i) {
    numbers[i] = i;
  }
  shuffle(numbers, num);
  for (i = 0; i < num; ++i) {
    fprintf(fp, "%d\n", numbers[i]);
  }
  fflush(fp);
  fclose(fp);
  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)
movl   $0x0,-0x18(%rbp)
mov    0xe3c(%rip),%rax
mov    %rax,-0x26(%rbp)
mov    0xe3a(%rip),%eax
mov    %eax,-0x1e(%rbp)
mov    0xe34(%rip),%ax
mov    %ax,-0x1a(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x26(%rbp),%rsi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe1a(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   10b0 <scanf@plt>
lea    -0x26(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1272 <main+0xd2>
lea    -0x26(%rbp),%rsi
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1328 <main+0x188>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xd97(%rip),%rsi
call   1070 <fprintf@plt>
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12c7 <main+0x127>
mov    -0x14(%rbp),%edx
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    129f <main+0xff>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <shuffle@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    130f <main+0x16f>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd1b(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12da <main+0x13a>
mov    -0x38(%rbp),%rdi
call   10a0 <fflush@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x4(%rsp)
movabs $0x7478742e737265,%rax
mov    %rax,0xe(%rsp)
movabs $0x7265626d756e2f2e,%rax
62 65 72
mov    %rax,0x8(%rsp)
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
lea    0xeaf(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeae(%rip),%rdi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec3(%rip),%rdi
lea    0x4(%rsp),%rsi
call   10b0 <scanf@plt>
lea    0xeb5(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1272 <main+0xd2>
mov    %rax,%r14
mov    0x4(%rsp),%edx
lea    0xe68(%rip),%rsi
mov    %rax,%rdi
call   1070 <fprintf@plt>
mov    0x4(%rsp),%r15d
lea    0x0(,%r15,4),%edi
call   1090 <malloc@plt>
mov    %rax,%r12
test   %r15d,%r15d
jle    13fd <main+0x25d>
cmp    $0x8,%r15d
jae    128a <main+0xea>
xor    %eax,%eax
jmp    13f0 <main+0x250>
lea    0xe62(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    144d <main+0x2ad>
mov    %r15d,%eax
and    $0xfffffff8,%eax
lea    -0x8(%rax),%rsi
mov    %rsi,%rdx
shr    $0x3,%rdx
add    $0x1,%rdx
mov    %edx,%ecx
and    $0x3,%ecx
cmp    $0x18,%rsi
jae    12b9 <main+0x119>
movdqa 0xd4e(%rip),%xmm0
xor    %esi,%esi
jmp    1390 <main+0x1f0>
and    $0xfffffffffffffffc,%rdx
movdqa 0xd3b(%rip),%xmm0
xor    %esi,%esi
movdqa 0xd40(%rip),%xmm8
movdqa 0xd47(%rip),%xmm9
movdqa 0xd4e(%rip),%xmm10
movdqa 0xd56(%rip),%xmm4
movdqa 0xd5e(%rip),%xmm5
movdqa 0xd66(%rip),%xmm6
movdqa 0xd6e(%rip),%xmm7
movdqa 0xd76(%rip),%xmm1
nopw   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm2
paddd  %xmm8,%xmm2
movdqu %xmm0,(%r12,%rsi,4)
movdqu %xmm2,0x10(%r12,%rsi,4)
movdqa %xmm0,%xmm2
paddd  %xmm9,%xmm2
movdqa %xmm0,%xmm3
paddd  %xmm10,%xmm3
movdqu %xmm2,0x20(%r12,%rsi,4)
movdqu %xmm3,0x30(%r12,%rsi,4)
movdqa %xmm0,%xmm2
paddd  %xmm4,%xmm2
movdqa %xmm0,%xmm3
paddd  %xmm5,%xmm3
movdqu %xmm2,0x40(%r12,%rsi,4)
movdqu %xmm3,0x50(%r12,%rsi,4)
movdqa %xmm0,%xmm2
paddd  %xmm6,%xmm2
movdqa %xmm0,%xmm3
paddd  %xmm7,%xmm3
movdqu %xmm2,0x60(%r12,%rsi,4)
movdqu %xmm3,0x70(%r12,%rsi,4)
add    $0x20,%rsi
paddd  %xmm1,%xmm0
add    $0xfffffffffffffffc,%rdx
jne    1310 <main+0x170>
test   %rcx,%rcx
je     13e0 <main+0x240>
lea    (%r12,%rsi,4),%rdx
add    $0x10,%rdx
shl    $0x5,%rcx
xor    %esi,%esi
movdqa 0xc65(%rip),%xmm1
movdqa 0xc6d(%rip),%xmm2
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movdqa %xmm0,%xmm3
paddd  %xmm1,%xmm3
movdqu %xmm0,-0x10(%rdx,%rsi,1)
movdqu %xmm3,(%rdx,%rsi,1)
paddd  %xmm2,%xmm0
add    $0x20,%rsi
cmp    %rsi,%rcx
jne    13c0 <main+0x220>
cmp    %r15,%rax
je     13fd <main+0x25d>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,(%r12,%rax,4)
add    $0x1,%rax
cmp    %rax,%r15
jne    13f0 <main+0x250>
mov    %r12,%rdi
mov    %r15d,%esi
call   1030 <shuffle@plt>
cmpl   $0x0,0x4(%rsp)
jle    143d <main+0x29d>
xor    %ebx,%ebx
lea    0xc8f(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    (%r12,%rbx,4),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <fprintf@plt>
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jl     1420 <main+0x280>
mov    %r14,%rdi
call   10a0 <fflush@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.filename = [14 x i8] c"./numbers.txt\00"
@.str = [13 x i8] c"RAND_MAX:%d\0A\00"
@RAND_MAX = global i32 0
@.str.1 = [43 x i8] c"How many random numbers you want in '%s': \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [25 x i8] c"create file '%s' failed!\00"
@.str.5 = [4 x i8] c"%d\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 [14 x i8]
%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* %7
%11 = bitcast [14 x i8]* %8 to i8*
store i32* null, i32** %9
store i32* null, i32** %10
%12 = call i64 @time(i32* null)
%13 = trunc i64 %12 to i32
%14 = call i32 @srand(i32 %13)
%15 = load i32, i32* @RAND_MAX
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [14 x i8], [14 x i8]* %8, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%20 = getelementptr inbounds [14 x i8], [14 x i8]* %8, i64 0, i64 0
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %21, i32** %10
%22 = load i32*, i32** %10
%23 = icmp ne i32* %22, null
br i1 %23, label %27, label %24
24: ; preds = %2
%25 = getelementptr inbounds [14 x i8], [14 x i8]* %8, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %25)
store i32 0, i32* %3
br label %73
27: ; preds = %2
%28 = load i32*, i32** %10
%29 = load i32, i32* %7
%30 = call i32 @fprintf(i32* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = mul i64 %32, 4
%34 = trunc i64 %33 to i32
%35 = call i32* @malloc(i32 %34)
store i32* %35, i32** %9
store i32 0, i32* %6
br label %36
36: ; preds = %46, %27
%37 = load i32, i32* %6
%38 = load i32, i32* %7
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %49
40: ; preds = %36
%41 = load i32, i32* %6
%42 = load i32*, i32** %9
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
store i32 %41, i32* %45
br label %46
46: ; preds = %40
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %36
49: ; preds = %36
%50 = load i32*, i32** %9
%51 = load i32, i32* %7
%52 = call i32 @shuffle(i32* %50, i32 %51)
store i32 0, i32* %6
br label %53
53: ; preds = %65, %49
%54 = load i32, i32* %6
%55 = load i32, i32* %7
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %68
57: ; preds = %53
%58 = load i32*, i32** %10
%59 = load i32*, i32** %9
%60 = load i32, i32* %6
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %59, i64 %61
%63 = load i32, i32* %62
%64 = call i32 @fprintf(i32* %58, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %57
%66 = load i32, i32* %6
%67 = add nsw i32 %66, 1
store i32 %67, i32* %6
br label %53
68: ; preds = %53
%69 = load i32*, i32** %10
%70 = call i32 @fflush(i32* %69)
%71 = load i32*, i32** %10
%72 = call i32 @fclose(i32* %71)
store i32 0, i32* %3
br label %73
73: ; preds = %68, %24
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@__const.main.filename = [14 x i8] c"./numbers.txt\00"
@.str = [13 x i8] c"RAND_MAX:%d\0A\00"
@RAND_MAX = global i32 0
@.str.1 = [43 x i8] c"How many random numbers you want in '%s': \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [25 x i8] c"create file '%s' failed!\00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [14 x i8]
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 0
%7 = tail call i64 @time(i32* null)
%8 = trunc i64 %7 to i32
%9 = tail call i32 @srand(i32 %8)
%10 = load i32, i32* @RAND_MAX
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%14 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br label %114
18: ; preds = %2
%19 = load i32, i32* %3
%20 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %3
%22 = shl i32 %21, 2
%23 = call i32* @malloc(i32 %22)
%24 = icmp sgt i32 %21, 0
br i1 %24, label %25, label %98
25: ; preds = %18
%26 = zext i32 %21 to i64
%27 = icmp ult i32 %21, 8
br i1 %27, label %90, label %28
28: ; preds = %25
%29 = and i64 %26, 4294967288
%30 = add nsw i64 %29, -8
%31 = lshr exact i64 %30, 3
%32 = add nuw nsw i64 %31, 1
%33 = and i64 %32, 3
%34 = icmp ult i64 %30, 24
br i1 %34, label %71, label %35
35: ; preds = %28
%36 = and i64 %32, 4611686018427387900
br label %37
37: ; preds = %37, %35
%38 = phi i64 [ 0, %35 ], [ %67, %37 ]
%39 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %35 ], [ %68, %37 ]
%40 = phi i64 [ 0, %35 ], [ %69, %37 ]
%41 = add <4 x i32> %39, <i32 4, i32 4, i32 4, i32 4>
%42 = getelementptr inbounds i32, i32* %23, i64 %38
%43 = bitcast i32* %42 to <4 x i32>*
store <4 x i32> %39, <4 x i32>* %43
%44 = getelementptr inbounds i32, i32* %42, i64 4
%45 = bitcast i32* %44 to <4 x i32>*
store <4 x i32> %41, <4 x i32>* %45
%46 = or i64 %38, 8
%47 = add <4 x i32> %39, <i32 8, i32 8, i32 8, i32 8>
%48 = add <4 x i32> %39, <i32 12, i32 12, i32 12, i32 12>
%49 = getelementptr inbounds i32, i32* %23, i64 %46
%50 = bitcast i32* %49 to <4 x i32>*
store <4 x i32> %47, <4 x i32>* %50
%51 = getelementptr inbounds i32, i32* %49, i64 4
%52 = bitcast i32* %51 to <4 x i32>*
store <4 x i32> %48, <4 x i32>* %52
%53 = or i64 %38, 16
%54 = add <4 x i32> %39, <i32 16, i32 16, i32 16, i32 16>
%55 = add <4 x i32> %39, <i32 20, i32 20, i32 20, i32 20>
%56 = getelementptr inbounds i32, i32* %23, i64 %53
%57 = bitcast i32* %56 to <4 x i32>*
store <4 x i32> %54, <4 x i32>* %57
%58 = getelementptr inbounds i32, i32* %56, i64 4
%59 = bitcast i32* %58 to <4 x i32>*
store <4 x i32> %55, <4 x i32>* %59
%60 = or i64 %38, 24
%61 = add <4 x i32> %39, <i32 24, i32 24, i32 24, i32 24>
%62 = add <4 x i32> %39, <i32 28, i32 28, i32 28, i32 28>
%63 = getelementptr inbounds i32, i32* %23, i64 %60
%64 = bitcast i32* %63 to <4 x i32>*
store <4 x i32> %61, <4 x i32>* %64
%65 = getelementptr inbounds i32, i32* %63, i64 4
%66 = bitcast i32* %65 to <4 x i32>*
store <4 x i32> %62, <4 x i32>* %66
%67 = add nuw i64 %38, 32
%68 = add <4 x i32> %39, <i32 32, i32 32, i32 32, i32 32>
%69 = add i64 %40, 4
%70 = icmp eq i64 %69, %36
br i1 %70, label %71, label %37
71: ; preds = %37, %28
%72 = phi i64 [ 0, %28 ], [ %67, %37 ]
%73 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %28 ], [ %68, %37 ]
%74 = icmp eq i64 %33, 0
br i1 %74, label %88, label %75
75: ; preds = %71, %75
%76 = phi i64 [ %84, %75 ], [ %72, %71 ]
%77 = phi <4 x i32> [ %85, %75 ], [ %73, %71 ]
%78 = phi i64 [ %86, %75 ], [ 0, %71 ]
%79 = add <4 x i32> %77, <i32 4, i32 4, i32 4, i32 4>
%80 = getelementptr inbounds i32, i32* %23, i64 %76
%81 = bitcast i32* %80 to <4 x i32>*
store <4 x i32> %77, <4 x i32>* %81
%82 = getelementptr inbounds i32, i32* %80, i64 4
%83 = bitcast i32* %82 to <4 x i32>*
store <4 x i32> %79, <4 x i32>* %83
%84 = add nuw i64 %76, 8
%85 = add <4 x i32> %77, <i32 8, i32 8, i32 8, i32 8>
%86 = add i64 %78, 1
%87 = icmp eq i64 %86, %33
br i1 %87, label %88, label %75
88: ; preds = %75, %71
%89 = icmp eq i64 %29, %26
br i1 %89, label %98, label %90
90: ; preds = %25, %88
%91 = phi i64 [ 0, %25 ], [ %29, %88 ]
br label %92
92: ; preds = %90, %92
%93 = phi i64 [ %96, %92 ], [ %91, %90 ]
%94 = getelementptr inbounds i32, i32* %23, i64 %93
%95 = trunc i64 %93 to i32
store i32 %95, i32* %94
%96 = add nuw nsw i64 %93, 1
%97 = icmp eq i64 %96, %26
br i1 %97, label %98, label %92
98: ; preds = %92, %88, %18
%99 = call i32 @shuffle(i32* %23, i32 %21)
%100 = load i32, i32* %3
%101 = icmp sgt i32 %100, 0
br i1 %101, label %102, label %111
102: ; preds = %98, %102
%103 = phi i64 [ %107, %102 ], [ 0, %98 ]
%104 = getelementptr inbounds i32, i32* %23, i64 %103
%105 = load i32, i32* %104
%106 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %105)
%107 = add nuw nsw i64 %103, 1
%108 = load i32, i32* %3
%109 = sext i32 %108 to i64
%110 = icmp slt i64 %107, %109
br i1 %110, label %102, label %111
111: ; preds = %102, %98
%112 = call i32 @fflush(i32* %14)
%113 = call i32 @fclose(i32* %14)
br label %114
114: ; preds = %111, %16
ret i32 0
}