#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int mean(int *, int, int *);
int rand();
int /*<<< orphan*/ set_math_debug();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ unset_math_debug();
int main(int argc, char **argv) {
  int ints[20000];
  int cnt;
  int i;
  int r;
  int res;
  int ret;
  unset_math_debug();
  if (argc > 1) {
    fprintf(stderr, "Using debug mode\n");
    set_math_debug();
  }
  srand(time(NULL));
  for (i = 0; i < 20000; i++) {
    r = rand() % 100000;
    ints[i] = r;
  }
  for (cnt = 0; cnt < 10; cnt++) {
    ret = mean(ints, 20000, &res);
    if (ret != 0) {
      fprintf(stderr, "Failed calculating mean value (%d)\n", ret);
      return 1;
    }
  }
  fprintf(stdout, "Mean value: %d\n", res);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x138b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <unset_math_debug@plt>
cmpl   $0x1,-0x8(%rbp)
jle    11b8 <main+0x48>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1070 <set_math_debug@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,-0x13898(%rbp)
cmpl   $0x4e20,-0x13898(%rbp)
jge    121f <main+0xaf>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x186a0,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1389c(%rbp)
mov    -0x1389c(%rbp),%ecx
movslq -0x13898(%rbp),%rax
mov    %ecx,-0x13890(%rbp,%rax,4)
mov    -0x13898(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13898(%rbp)
jmp    11d2 <main+0x62>
movl   $0x0,-0x13894(%rbp)
cmpl   $0xa,-0x13894(%rbp)
jge    12a3 <main+0x133>
lea    -0x13890(%rbp),%rdi
mov    $0x4e20,%esi
lea    -0x138a0(%rbp),%rdx
call   1080 <mean@plt>
mov    %eax,-0x138a4(%rbp)
cmpl   $0x0,-0x138a4(%rbp)
je     128a <main+0x11a>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
mov    -0x138a4(%rbp),%edx
lea    0xd9b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c7 <main+0x157>
jmp    128f <main+0x11f>
mov    -0x13894(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13894(%rbp)
jmp    1229 <main+0xb9>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
mov    -0x138a0(%rbp),%edx
lea    0xd7d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x138b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x13890,%rsp
mov    %edi,%ebx
xor    %eax,%eax
call   1060 <unset_math_debug@plt>
cmp    $0x2,%ebx
jl     11a4 <main+0x34>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1070 <set_math_debug@plt>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x14f8b589,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2d,%rcx
add    %edx,%ecx
imul   $0x186a0,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x4e20,%rbx
jne    11c0 <main+0x50>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
mov    $0x4e20,%esi
call   1080 <mean@plt>
test   %eax,%eax
jne    12f6 <main+0x186>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
mov    $0x4e20,%esi
call   1080 <mean@plt>
test   %eax,%eax
jne    12f6 <main+0x186>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
mov    $0x4e20,%esi
call   1080 <mean@plt>
test   %eax,%eax
jne    12f6 <main+0x186>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
mov    $0x4e20,%esi
call   1080 <mean@plt>
test   %eax,%eax
jne    12f6 <main+0x186>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
mov    $0x4e20,%esi
call   1080 <mean@plt>
test   %eax,%eax
jne    12f6 <main+0x186>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
mov    $0x4e20,%esi
call   1080 <mean@plt>
test   %eax,%eax
jne    12f6 <main+0x186>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
mov    $0x4e20,%esi
call   1080 <mean@plt>
test   %eax,%eax
jne    12f6 <main+0x186>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
mov    $0x4e20,%esi
call   1080 <mean@plt>
test   %eax,%eax
jne    12f6 <main+0x186>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
mov    $0x4e20,%esi
call   1080 <mean@plt>
test   %eax,%eax
jne    12f6 <main+0x186>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
mov    $0x4e20,%esi
call   1080 <mean@plt>
test   %eax,%eax
je     131f <main+0x1af>
mov    0x2ce3(%rip),%rcx
mov    (%rcx),%edi
lea    0xd0c(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x13890,%rsp
pop    %rbx
ret
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
mov    0xc(%rsp),%edx
lea    0xd03(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1314 <main+0x1a4>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"Using debug mode\0A\00"
@.str.1 = [36 x i8] c"Failed calculating mean value (%d)\0A\00"
@stdout = global i32 0
@.str.2 = [16 x i8] c"Mean value: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [20000 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 (...) @unset_math_debug()
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%18 = call i32 (...) @set_math_debug()
br label %19
19: ; preds = %15, %2
%20 = call i32 @time(i32* null)
%21 = call i32 @srand(i32 %20)
store i32 0, i32* %8
br label %22
22: ; preds = %32, %19
%23 = load i32, i32* %8
%24 = icmp slt i32 %23, 20000
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = call i32 (...) @rand()
%27 = srem i32 %26, 100000
store i32 %27, i32* %9
%28 = load i32, i32* %9
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [20000 x i32], [20000 x i32]* %6, i64 0, i64 %30
store i32 %28, i32* %31
br label %32
32: ; preds = %25
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
br label %22
35: ; preds = %22
store i32 0, i32* %7
br label %36
36: ; preds = %49, %35
%37 = load i32, i32* %7
%38 = icmp slt i32 %37, 10
br i1 %38, label %39, label %52
39: ; preds = %36
%40 = getelementptr inbounds [20000 x i32], [20000 x i32]* %6, i64 0, i64 0
%41 = call i32 @mean(i32* %40, i32 20000, i32* %10)
store i32 %41, i32* %11
%42 = load i32, i32* %11
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %39
%45 = load i32, i32* @stderr
%46 = load i32, i32* %11
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %46)
store i32 1, i32* %3
br label %56
48: ; preds = %39
br label %49
49: ; preds = %48
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %36
52: ; preds = %36
%53 = load i32, i32* @stdout
%54 = load i32, i32* %10
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %54)
store i32 0, i32* %3
br label %56
56: ; preds = %52, %44
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"Using debug mode\0A\00"
@.str.1 = [36 x i8] c"Failed calculating mean value (%d)\0A\00"
@stdout = global i32 0
@.str.2 = [16 x i8] c"Mean value: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [20000 x i32]
%4 = alloca i32
%5 = bitcast [20000 x i32]* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 (...) @unset_math_debug()
%8 = icmp sgt i32 %0, 1
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 (...) @set_math_debug()
br label %13
13: ; preds = %9, %2
%14 = tail call i32 @time(i32* null)
%15 = tail call i32 @srand(i32 %14)
br label %20
16: ; preds = %20
%17 = getelementptr inbounds [20000 x i32], [20000 x i32]* %3, i64 0, i64 0
%18 = call i32 @mean(i32* %17, i32 20000, i32* %4)
%19 = icmp eq i32 %18, 0
br i1 %19, label %27, label %58
20: ; preds = %13, %20
%21 = phi i64 [ 0, %13 ], [ %25, %20 ]
%22 = tail call i32 (...) @rand()
%23 = srem i32 %22, 100000
%24 = getelementptr inbounds [20000 x i32], [20000 x i32]* %3, i64 0, i64 %21
store i32 %23, i32* %24
%25 = add nuw nsw i64 %21, 1
%26 = icmp eq i64 %25, 20000
br i1 %26, label %16, label %20
27: ; preds = %16
%28 = call i32 @mean(i32* %17, i32 20000, i32* %4)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %58
30: ; preds = %27
%31 = call i32 @mean(i32* %17, i32 20000, i32* %4)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %58
33: ; preds = %30
%34 = call i32 @mean(i32* %17, i32 20000, i32* %4)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %58
36: ; preds = %33
%37 = call i32 @mean(i32* %17, i32 20000, i32* %4)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %58
39: ; preds = %36
%40 = call i32 @mean(i32* %17, i32 20000, i32* %4)
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %58
42: ; preds = %39
%43 = call i32 @mean(i32* %17, i32 20000, i32* %4)
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %58
45: ; preds = %42
%46 = call i32 @mean(i32* %17, i32 20000, i32* %4)
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %58
48: ; preds = %45
%49 = call i32 @mean(i32* %17, i32 20000, i32* %4)
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %58
51: ; preds = %48
%52 = call i32 @mean(i32* %17, i32 20000, i32* %4)
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %51
%55 = load i32, i32* @stdout
%56 = load i32, i32* %4
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %56)
br label %62
58: ; preds = %51, %48, %45, %42, %39, %36, %33, %30, %27, %16
%59 = phi i32 [ %18, %16 ], [ %28, %27 ], [ %31, %30 ], [ %34, %33 ], [ %37, %36 ], [ %40, %39 ], [ %43, %42 ], [ %46, %45 ], [ %49, %48 ], [ %52, %51 ]
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %59)
br label %62
62: ; preds = %54, %58
%63 = phi i32 [ 1, %58 ], [ 0, %54 ]
ret i32 %63
}