#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 */
float RAND_MAX;
float exp(float);
scalar_t__ random();
int give(float lambd) {
  int k = 0;
  float L = exp(-lambd), p = 1.;
  float ura;
  do {
    k++;
    ura = (float)random() / RAND_MAX;
    p *= ura;
  } while (p > L);
  return k - 1;
}


x86 assembly (clang, -O0):
<give>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
call   1040 <exp@plt>
movss  %xmm0,-0xc(%rbp)
movss  0xea8(%rip),%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
cvtsi2ss %rax,%xmm0
mov    0x2e6f(%rip),%rax
divss  (%rax),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
mulss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
ucomiss -0xc(%rbp),%xmm0
ja     115d <give+0x3d>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<give>:
push   %r14
push   %rbx
push   %rax
xorps  0xed5(%rip),%xmm0
call   1040 <exp@plt>
movss  %xmm0,0x4(%rsp)
movss  0xed2(%rip),%xmm0
mov    $0xffffffff,%ebx
mov    0x2e9e(%rip),%r14
nopw   0x0(%rax,%rax,1)
movss  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <random@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
divss  (%r14),%xmm0
movss  (%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,(%rsp)
movss  (%rsp),%xmm0
add    $0x1,%ebx
ucomiss 0x4(%rsp),%xmm0
ja     1150 <give+0x30>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@RAND_MAX = global float 0.000000e+00
define i32 @give(float %0) {
%2 = alloca float
%3 = alloca i32
%4 = alloca float
%5 = alloca float
%6 = alloca float
store float %0, float* %2
store i32 0, i32* %3
%7 = load float, float* %2
%8 = fneg float %7
%9 = call float @exp(float %8)
store float %9, float* %4
store float 1.000000e+00, float* %5
br label %10
10: ; preds = %20, %1
%11 = load i32, i32* %3
%12 = add nsw i32 %11, 1
store i32 %12, i32* %3
%13 = call i64 (...) @random()
%14 = sitofp i64 %13 to float
%15 = load float, float* @RAND_MAX
%16 = fdiv float %14, %15
store float %16, float* %6
%17 = load float, float* %6
%18 = load float, float* %5
%19 = fmul float %18, %17
store float %19, float* %5
br label %20
20: ; preds = %10
%21 = load float, float* %5
%22 = load float, float* %4
%23 = fcmp ogt float %21, %22
br i1 %23, label %10, label %24
24: ; preds = %20
%25 = load i32, i32* %3
%26 = sub nsw i32 %25, 1
ret i32 %26
}

LLVM IR (-O2):
@RAND_MAX = global float 0.000000e+00
define i32 @give(float %0) {
%2 = fneg float %0
%3 = tail call float @exp(float %2)
br label %4
4: ; preds = %4, %1
%5 = phi float [ 1.000000e+00, %1 ], [ %12, %4 ]
%6 = phi i32 [ 0, %1 ], [ %7, %4 ]
%7 = add nuw nsw i32 %6, 1
%8 = tail call i64 (...) @random()
%9 = sitofp i64 %8 to float
%10 = load float, float* @RAND_MAX
%11 = fdiv float %9, %10
%12 = fmul float %5, %11
%13 = fcmp ogt float %12, %3
br i1 %13, label %4, label %14
14: ; preds = %4
ret i32 %6
}