#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);
int /*<<< orphan*/ put_forks(int);
int rand();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ take_forks(int);
void philosopher(void *param) {
  int i;
  i = *((int *)(param));
  printf("Philosopher %d is thinking...\n", i);
  sleep(rand() % 3);
  while (1) {
    printf("Philosopher %d is hungry!\n", i);
    take_forks(i);
    printf("\tPhilosopher %d is eating.\n", i);
    sleep(rand() % 5);
    put_forks(i);
    printf("Philosopher %d is thinking...\n", i);
    sleep(rand() % 3);
  }
}


x86 assembly (clang, -O0):
<philosopher>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1060 <sleep@plt>
mov    -0xc(%rbp),%esi
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <take_forks@plt>
mov    -0xc(%rbp),%esi
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1060 <sleep@plt>
mov    -0xc(%rbp),%edi
call   1040 <put_forks@plt>
mov    -0xc(%rbp),%esi
lea    0xe28(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1060 <sleep@plt>
jmp    118a <philosopher+0x3a>

x86 assembly (clang, -O2):
<philosopher>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%ebx
lea    0xe9f(%rip),%r14
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rdi
imul   $0x55555556,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%edi
call   1060 <sleep@plt>
lea    0xe85(%rip),%r15
lea    0xe99(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %ebx,%edi
call   1050 <take_forks@plt>
mov    %r12,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
sar    %eax
add    %ecx,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
call   1060 <sleep@plt>
mov    %ebx,%edi
call   1040 <put_forks@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rdi
imul   $0x55555556,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%edi
call   1060 <sleep@plt>
jmp    11b0 <philosopher+0x60>

LLVM IR (-O0):
@.str = [31 x i8] c"Philosopher %d is thinking...\0A\00"
@.str.1 = [27 x i8] c"Philosopher %d is hungry!\0A\00"
@.str.2 = [28 x i8] c"\09Philosopher %d is eating.\0A\00"
define void @philosopher(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = bitcast i8* %4 to i32*
%6 = load i32, i32* %5
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i32 (...) @rand()
%10 = srem i32 %9, 3
%11 = call i32 @sleep(i32 %10)
br label %12
12: ; preds = %1, %12
%13 = load i32, i32* %3
%14 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %3
%16 = call i32 @take_forks(i32 %15)
%17 = load i32, i32* %3
%18 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = call i32 (...) @rand()
%20 = srem i32 %19, 5
%21 = call i32 @sleep(i32 %20)
%22 = load i32, i32* %3
%23 = call i32 @put_forks(i32 %22)
%24 = load i32, i32* %3
%25 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = call i32 (...) @rand()
%27 = srem i32 %26, 3
%28 = call i32 @sleep(i32 %27)
br label %12
}

LLVM IR (-O2):
@.str = [31 x i8] c"Philosopher %d is thinking...\0A\00"
@.str.1 = [27 x i8] c"Philosopher %d is hungry!\0A\00"
@.str.2 = [28 x i8] c"\09Philosopher %d is eating.\0A\00"
define void @philosopher(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = load i32, i32* %2
%4 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 3
%7 = tail call i32 @sleep(i32 %6)
br label %8
8: ; preds = %8, %1
%9 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%10 = tail call i32 @take_forks(i32 %3)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%12 = tail call i32 (...) @rand()
%13 = srem i32 %12, 5
%14 = tail call i32 @sleep(i32 %13)
%15 = tail call i32 @put_forks(i32 %3)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %3)
%17 = tail call i32 (...) @rand()
%18 = srem i32 %17, 3
%19 = tail call i32 @sleep(i32 %18)
br label %8
}