#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 */
scalar_t__ RAND_MAX;
int calc_trials(int, int *);
double rand();
int birthday_function(int ppl) {
  int bday[4096];
  int person, s, i = ppl - 1, *p;
  p = bday;
  for (i; i >= 0; --i) {
    person = 365 * (rand() / ((double)RAND_MAX + 1));
    bday[i] = person;
  }
  return calc_trials(ppl, p);
}


x86 assembly (clang, -O0):
<birthday_function>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4030,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x401c(%rbp)
lea    -0x4010(%rbp),%rax
mov    %rax,-0x4028(%rbp)
cmpl   $0x0,-0x401c(%rbp)
jl     11b9 <birthday_function+0x99>
mov    $0x0,%al
call   1040 <rand@plt>
movaps %xmm0,%xmm1
mov    0x2e82(%rip),%rax
cvtsi2sdq (%rax),%xmm0
movsd  0xe95(%rip),%xmm2
addsd  %xmm2,%xmm0
divsd  %xmm0,%xmm1
movsd  0xe7d(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x4014(%rbp)
mov    -0x4014(%rbp),%ecx
movslq -0x401c(%rbp),%rax
mov    %ecx,-0x4010(%rbp,%rax,4)
mov    -0x401c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x401c(%rbp)
jmp    1148 <birthday_function+0x28>
mov    -0x4(%rbp),%edi
mov    -0x4028(%rbp),%rsi
call   1030 <calc_trials@plt>
add    $0x4030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<birthday_function>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x4008,%rsp
mov    %edi,%r14d
test   %edi,%edi
jle    1187 <birthday_function+0x67>
mov    %r14d,%ebx
add    $0x1,%rbx
mov    0x2ea6(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    -0x2(%rbx),%ebp
xor    %eax,%eax
call   1040 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq (%r15),%xmm1
addsd  0xe96(%rip),%xmm1
divsd  %xmm1,%xmm0
mulsd  0xe92(%rip),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,(%rsp,%rbp,4)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1150 <birthday_function+0x30>
mov    %rsp,%rsi
mov    %r14d,%edi
call   1030 <calc_trials@plt>
add    $0x4008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define i32 @birthday_function(i32 %0) {
%2 = alloca i32
%3 = alloca [4096 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i32 %0, i32* %2
%8 = load i32, i32* %2
%9 = sub nsw i32 %8, 1
store i32 %9, i32* %6
%10 = getelementptr inbounds [4096 x i32], [4096 x i32]* %3, i64 0, i64 0
store i32* %10, i32** %7
%11 = load i32, i32* %6
br label %12
12: ; preds = %27, %1
%13 = load i32, i32* %6
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %30
15: ; preds = %12
%16 = call double (...) @rand()
%17 = load i64, i64* @RAND_MAX
%18 = sitofp i64 %17 to double
%19 = fadd double %18, 1.000000e+00
%20 = fdiv double %16, %19
%21 = fmul double 3.650000e+02, %20
%22 = fptosi double %21 to i32
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [4096 x i32], [4096 x i32]* %3, i64 0, i64 %25
store i32 %23, i32* %26
br label %27
27: ; preds = %15
%28 = load i32, i32* %6
%29 = add nsw i32 %28, -1
store i32 %29, i32* %6
br label %12
30: ; preds = %12
%31 = load i32, i32* %2
%32 = load i32*, i32** %7
%33 = call i32 @calc_trials(i32 %31, i32* %32)
ret i32 %33
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define i32 @birthday_function(i32 %0) {
%2 = alloca [4096 x i32]
%3 = bitcast [4096 x i32]* %2 to i8*
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %20
5: ; preds = %1
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ %6, %5 ], [ %9, %7 ]
%9 = add nsw i64 %8, -1
%10 = tail call double (...) @rand()
%11 = load i64, i64* @RAND_MAX
%12 = sitofp i64 %11 to double
%13 = fadd double %12, 1.000000e+00
%14 = fdiv double %10, %13
%15 = fmul double %14, 3.650000e+02
%16 = fptosi double %15 to i32
%17 = and i64 %9, 4294967295
%18 = getelementptr inbounds [4096 x i32], [4096 x i32]* %2, i64 0, i64 %17
store i32 %16, i32* %18
%19 = icmp ugt i64 %8, 1
br i1 %19, label %7, label %20
20: ; preds = %7, %1
%21 = getelementptr inbounds [4096 x i32], [4096 x i32]* %2, i64 0, i64 0
%22 = call i32 @calc_trials(i32 %0, i32* %21)
ret i32 %22
}