#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*/ free_2fork(int);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ printf(char *, int);
int rand();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ wait_for_2fork(int);
void philosopere(int no) {
  srand(getpid());
  for (;;) {
    printf("%d is thinking\n", no);
    sleep((rand() % 5 + 1));
    printf("%d is hungry\n", no);
    wait_for_2fork(no);
    printf("%d is eating\n", no);
    sleep((rand() % 5 + 1));
    free_2fork(no);
  }
}


x86 assembly (clang, -O0):
<philosopere>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    -0x4(%rbp),%esi
lea    0xe6d(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
add    $0x1,%edi
mov    %edi,-0xc(%rbp)
call   1080 <sleep@plt>
mov    -0x4(%rbp),%esi
lea    0xe52(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
call   1060 <wait_for_2fork@plt>
mov    -0x4(%rbp),%esi
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
add    $0x1,%edi
mov    %edi,-0x8(%rbp)
call   1080 <sleep@plt>
mov    -0x4(%rbp),%edi
call   1040 <free_2fork@plt>
jmp    1189 <philosopere+0x19>

x86 assembly (clang, -O2):
<philosopere>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%edi
call   1070 <srand@plt>
lea    0xe71(%rip),%r14
lea    0xe7a(%rip),%r15
lea    0xe81(%rip),%r12
nopl   (%rax)
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%edi
add    $0x1,%edi
call   1080 <sleep@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <wait_for_2fork@plt>
mov    %r12,%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%edi
add    $0x1,%edi
call   1080 <sleep@plt>
mov    %ebx,%edi
call   1040 <free_2fork@plt>
jmp    11a0 <philosopere+0x30>

LLVM IR (-O0):
@.str = [16 x i8] c"%d is thinking\0A\00"
@.str.1 = [14 x i8] c"%d is hungry\0A\00"
@.str.2 = [14 x i8] c"%d is eating\0A\00"
define void @philosopere(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i32 (...) @getpid()
%4 = call i32 @srand(i32 %3)
br label %5
5: ; preds = %5, %1
%6 = load i32, i32* %2
%7 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 5
%10 = add nsw i32 %9, 1
%11 = call i32 @sleep(i32 %10)
%12 = load i32, i32* %2
%13 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %2
%15 = call i32 @wait_for_2fork(i32 %14)
%16 = load i32, i32* %2
%17 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = call i32 (...) @rand()
%19 = srem i32 %18, 5
%20 = add nsw i32 %19, 1
%21 = call i32 @sleep(i32 %20)
%22 = load i32, i32* %2
%23 = call i32 @free_2fork(i32 %22)
br label %5
}

LLVM IR (-O2):
@.str = [16 x i8] c"%d is thinking\0A\00"
@.str.1 = [14 x i8] c"%d is hungry\0A\00"
@.str.2 = [14 x i8] c"%d is eating\0A\00"
define void @philosopere(i32 %0) {
%2 = tail call i32 (...) @getpid()
%3 = tail call i32 @srand(i32 %2)
br label %4
4: ; preds = %4, %1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 5
%8 = add nsw i32 %7, 1
%9 = tail call i32 @sleep(i32 %8)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%11 = tail call i32 @wait_for_2fork(i32 %0)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%13 = tail call i32 (...) @rand()
%14 = srem i32 %13, 5
%15 = add nsw i32 %14, 1
%16 = tail call i32 @sleep(i32 %15)
%17 = tail call i32 @free_2fork(i32 %0)
br label %4
}