#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 rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int throw_die(void) {
  static int is_seeded = 0;
  int value;
  if (!is_seeded) {
    is_seeded = 1;
    srand((unsigned int)time(NULL));
  }
  do {
    value = rand();
  } while (value > (int)((((long)RAND_MAX + 1) / 6) * 6 - 1));
  return value % 6 + 1;
}


x86 assembly (clang, -O0):
<throw_die>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpl   $0x0,0x2f01(%rip)
jne    115f <throw_die+0x2f>
movl   $0x1,0x2ef1(%rip)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
jmp    1164 <throw_die+0x34>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%rax
add    $0x1,%rax
mov    $0x6,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x8(%rbp),%eax
imul   $0x6,%rcx,%rcx
sub    $0x1,%rcx
cmp    %ecx,%eax
jg     1164 <throw_die+0x34>
mov    -0x4(%rbp),%eax
mov    $0x6,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
add    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<throw_die>:
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,0x2f05(%rip)
jne    1152 <throw_die+0x22>
movb   $0x1,0x2efc(%rip)
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    0x2e8f(%rip),%r14
movabs $0x2aaaaaaaaaaaaaab,%rbx
aa aa 2a
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1050 <rand@plt>
mov    %eax,%ecx
mov    (%r14),%rdi
lea    0x1(%rdi),%rsi
mov    %rsi,%rax
imul   %rbx
mov    %rdx,%rax
shr    $0x3f,%rax
add    %edx,%eax
add    %eax,%eax
lea    (%rax,%rax,2),%eax
sub    %esi,%eax
add    %eax,%edi
cmp    %edi,%ecx
jg     1170 <throw_die+0x40>
movslq %ecx,%rax
imul   $0x2aaaaaab,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rax
add    %edx,%eax
add    %eax,%eax
lea    (%rax,%rax,2),%eax
neg    %eax
add    %ecx,%eax
add    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@throw_die.is_seeded = internal global i32 0
@RAND_MAX = global i64 0
define i32 @throw_die() {
%1 = alloca i32
%2 = load i32, i32* @throw_die.is_seeded
%3 = icmp ne i32 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %0
store i32 1, i32* @throw_die.is_seeded
%5 = call i64 @time(i32* null)
%6 = trunc i64 %5 to i32
%7 = call i32 @srand(i32 %6)
br label %8
8: ; preds = %4, %0
br label %9
9: ; preds = %11, %8
%10 = call i32 (...) @rand()
store i32 %10, i32* %1
br label %11
11: ; preds = %9
%12 = load i32, i32* %1
%13 = load i64, i64* @RAND_MAX
%14 = add nsw i64 %13, 1
%15 = sdiv i64 %14, 6
%16 = mul nsw i64 %15, 6
%17 = sub nsw i64 %16, 1
%18 = trunc i64 %17 to i32
%19 = icmp sgt i32 %12, %18
br i1 %19, label %9, label %20
20: ; preds = %11
%21 = load i32, i32* %1
%22 = srem i32 %21, 6
%23 = add nsw i32 %22, 1
ret i32 %23
}

LLVM IR (-O2):
@throw_die.is_seeded = internal unnamed_addr global i1 false
@RAND_MAX = global i64 0
define i32 @throw_die() {
%1 = load i1, i1* @throw_die.is_seeded
br i1 %1, label %6, label %2
2: ; preds = %0
store i1 true, i1* @throw_die.is_seeded
%3 = tail call i64 @time(i32* null)
%4 = trunc i64 %3 to i32
%5 = tail call i32 @srand(i32 %4)
br label %6
6: ; preds = %2, %0
br label %7
7: ; preds = %6, %7
%8 = tail call i32 (...) @rand()
%9 = load i64, i64* @RAND_MAX
%10 = add nsw i64 %9, 1
%11 = srem i64 %10, 6
%12 = sub i64 %9, %11
%13 = trunc i64 %12 to i32
%14 = icmp sgt i32 %8, %13
br i1 %14, label %7, label %15
15: ; preds = %7
%16 = srem i32 %8, 6
%17 = add nsw i32 %16, 1
ret i32 %17
}