#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 */
double drand48();
scalar_t__ floor(double);
int random7_int() {
  double min = 0.0, length = 1.0;
  while (((int)floor(7.0 * (min))) != ((int)floor(7.0 * (min + length)))) {
    length /= 5.0;
    min += ((int)floor(5.0 * drand48())) * length;
  }
  return ((int)floor(7.0 * (min)));
}


x86 assembly (clang, -O0):
<random7_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xec8(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xec3(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
call   1030 <floor@plt>
mov    %eax,-0x14(%rbp)
movsd  -0x8(%rbp),%xmm1
addsd  -0x10(%rbp),%xmm1
movsd  0xea4(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <floor@plt>
mov    %rax,%rcx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
je     11cc <random7_int+0xac>
movsd  -0x10(%rbp),%xmm0
movsd  0xe88(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1040 <drand48@plt>
movaps %xmm0,%xmm1
movsd  0xe6d(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <floor@plt>
cvtsi2sd %eax,%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    113d <random7_int+0x1d>
movsd  0xe34(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
call   1030 <floor@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random7_int>:
push   %rbx
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
xorps  %xmm0,%xmm0
call   1030 <floor@plt>
mov    %rax,%rbx
movsd  0xebf(%rip),%xmm0
call   1030 <floor@plt>
cmp    %eax,%ebx
je     11f8 <random7_int+0xd8>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0xea8(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
movsd  0xe98(%rip),%xmm1
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <drand48@plt>
mulsd  0xe79(%rip),%xmm0
call   1030 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0xe3f(%rip),%xmm0
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movapd %xmm1,%xmm0
call   1030 <floor@plt>
mov    %rax,%rbx
movsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
mulsd  0xe15(%rip),%xmm0
call   1030 <floor@plt>
cmp    %eax,%ebx
jne    1170 <random7_int+0x50>
movsd  0x18(%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
jmp    1030 <floor@plt>

LLVM IR (-O0):
define i32 @random7_int() {
%1 = alloca double
%2 = alloca double
store double 0.000000e+00, double* %1
store double 1.000000e+00, double* %2
br label %3
3: ; preds = %15, %0
%4 = load double, double* %1
%5 = fmul double 7.000000e+00, %4
%6 = call i64 @floor(double %5)
%7 = trunc i64 %6 to i32
%8 = load double, double* %1
%9 = load double, double* %2
%10 = fadd double %8, %9
%11 = fmul double 7.000000e+00, %10
%12 = call i64 @floor(double %11)
%13 = trunc i64 %12 to i32
%14 = icmp ne i32 %7, %13
br i1 %14, label %15, label %26
15: ; preds = %3
%16 = load double, double* %2
%17 = fdiv double %16, 5.000000e+00
store double %17, double* %2
%18 = call double (...) @drand48()
%19 = fmul double 5.000000e+00, %18
%20 = call i64 @floor(double %19)
%21 = trunc i64 %20 to i32
%22 = sitofp i32 %21 to double
%23 = load double, double* %2
%24 = load double, double* %1
%25 = call double @llvm.fmuladd.f64(double %22, double %23, double %24)
store double %25, double* %1
br label %3
26: ; preds = %3
%27 = load double, double* %1
%28 = fmul double 7.000000e+00, %27
%29 = call i64 @floor(double %28)
%30 = trunc i64 %29 to i32
ret i32 %30
}

LLVM IR (-O2):
define i32 @random7_int() {
%1 = tail call i64 @floor(double 0.000000e+00)
%2 = trunc i64 %1 to i32
%3 = tail call i64 @floor(double 7.000000e+00)
%4 = trunc i64 %3 to i32
%5 = icmp eq i32 %2, %4
br i1 %5, label %24, label %6
6: ; preds = %0, %6
%7 = phi double [ %9, %6 ], [ 1.000000e+00, %0 ]
%8 = phi double [ %15, %6 ], [ 0.000000e+00, %0 ]
%9 = fdiv double %7, 5.000000e+00
%10 = tail call double (...) @drand48()
%11 = fmul double %10, 5.000000e+00
%12 = tail call i64 @floor(double %11)
%13 = trunc i64 %12 to i32
%14 = sitofp i32 %13 to double
%15 = tail call double @llvm.fmuladd.f64(double %14, double %9, double %8)
%16 = fmul double %15, 7.000000e+00
%17 = tail call i64 @floor(double %16)
%18 = trunc i64 %17 to i32
%19 = fadd double %15, %9
%20 = fmul double %19, 7.000000e+00
%21 = tail call i64 @floor(double %20)
%22 = trunc i64 %21 to i32
%23 = icmp eq i32 %18, %22
br i1 %23, label %24, label %6
24: ; preds = %6, %0
%25 = phi double [ 0.000000e+00, %0 ], [ %16, %6 ]
%26 = tail call i64 @floor(double %25)
%27 = trunc i64 %26 to i32
ret i32 %27
}