#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*/ printf(char *);
int rand();
int /*<<< orphan*/ sleep(unsigned int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int coin_flip(void) {
  int result = 0;
  srand(time(NULL));
  result = rand() % 2 + 1;
  sleep((unsigned int)(((rand() % 10) / 2) + 1));
  if (result == 1) {
    printf("H ");
  } else {
    printf("T ");
  }
  return result;
}


x86 assembly (clang, -O0):
<coin_flip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x4(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
add    $0x1,%edi
call   1060 <sleep@plt>
cmpl   $0x1,-0x4(%rbp)
jne    11c2 <coin_flip+0x72>
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
jmp    11ce <coin_flip+0x7e>
lea    0xe3a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<coin_flip>:
push   %rbp
push   %r14
push   %rbx
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%r14d
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
and    $0xfffffffe,%ebx
mov    %eax,%ebp
sub    %ebx,%ebp
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    %eax,%ecx
shr    $0x7,%cl
add    %al,%cl
sar    %cl
add    $0x1,%cl
movsbl %cl,%edi
call   1060 <sleep@plt>
test   %ebp,%ebp
lea    0xe45(%rip),%rax
lea    0xe41(%rip),%rdi
cmove  %rax,%rdi
call   1030 <printf@plt>
neg    %ebx
lea    (%r14,%rbx,1),%eax
add    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"H \00"
@.str.1 = [3 x i8] c"T \00"
define i32 @coin_flip() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 @time(i32* null)
%3 = call i32 @srand(i32 %2)
%4 = call i32 (...) @rand()
%5 = srem i32 %4, 2
%6 = add nsw i32 %5, 1
store i32 %6, i32* %1
%7 = call i32 (...) @rand()
%8 = srem i32 %7, 10
%9 = sdiv i32 %8, 2
%10 = add nsw i32 %9, 1
%11 = call i32 @sleep(i32 %10)
%12 = load i32, i32* %1
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %18
16: ; preds = %0
%17 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %14
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [3 x i8] c"H \00"
@.str.1 = [3 x i8] c"T \00"
define i32 @coin_flip() {
%1 = tail call i32 @time(i32* null)
%2 = tail call i32 @srand(i32 %1)
%3 = tail call i32 (...) @rand()
%4 = srem i32 %3, 2
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 10
%7 = trunc i32 %6 to i8
%8 = sdiv i8 %7, 2
%9 = add nsw i8 %8, 1
%10 = sext i8 %9 to i32
%11 = tail call i32 @sleep(i32 %10)
%12 = icmp eq i32 %4, 0
%13 = select i1 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%14 = tail call i32 @printf(i8* dereferenceable(1) %13)
%15 = add nsw i32 %4, 1
ret i32 %15
}