#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*/ eat();
int /*<<< orphan*/ get_left_fork(int);
int /*<<< orphan*/ get_right_fork(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ put_left_fork(int);
int /*<<< orphan*/ put_right_fork(int);
void *philosopher(void *para) {
  int mine = (int)para;
  int i = 0;
  while (i < 2) {
    i++;
    get_left_fork(mine);
    get_right_fork(mine);
    eat();
    put_left_fork(mine);
    put_right_fork(mine);
  }
  printf("%d is finished\n", mine + 1);
  return 0L;
}


x86 assembly (clang, -O0):
<philosopher>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x2,-0x10(%rbp)
jge    11b9 <philosopher+0x59>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <get_left_fork@plt>
mov    -0xc(%rbp),%edi
call   1070 <get_right_fork@plt>
mov    $0x0,%al
call   1040 <eat@plt>
mov    -0xc(%rbp),%edi
call   1080 <put_left_fork@plt>
mov    -0xc(%rbp),%edi
call   1060 <put_right_fork@plt>
jmp    117a <philosopher+0x1a>
mov    -0xc(%rbp),%esi
add    $0x1,%esi
lea    0xe3a(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<philosopher>:
push   %rbx
mov    %rdi,%rbx
call   1030 <get_left_fork@plt>
mov    %ebx,%edi
call   1070 <get_right_fork@plt>
xor    %eax,%eax
call   1040 <eat@plt>
mov    %ebx,%edi
call   1080 <put_left_fork@plt>
mov    %ebx,%edi
call   1060 <put_right_fork@plt>
mov    %ebx,%edi
call   1030 <get_left_fork@plt>
mov    %ebx,%edi
call   1070 <get_right_fork@plt>
xor    %eax,%eax
call   1040 <eat@plt>
mov    %ebx,%edi
call   1080 <put_left_fork@plt>
mov    %ebx,%edi
call   1060 <put_right_fork@plt>
add    $0x1,%ebx
lea    0xe4e(%rip),%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"%d is finished\0A\00"
define i8* @philosopher(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = ptrtoint i8* %5 to i32
store i32 %6, i32* %3
store i32 0, i32* %4
br label %7
7: ; preds = %10, %1
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %22
10: ; preds = %7
%11 = load i32, i32* %4
%12 = add nsw i32 %11, 1
store i32 %12, i32* %4
%13 = load i32, i32* %3
%14 = call i32 @get_left_fork(i32 %13)
%15 = load i32, i32* %3
%16 = call i32 @get_right_fork(i32 %15)
%17 = call i32 (...) @eat()
%18 = load i32, i32* %3
%19 = call i32 @put_left_fork(i32 %18)
%20 = load i32, i32* %3
%21 = call i32 @put_right_fork(i32 %20)
br label %7
22: ; preds = %7
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
%25 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %24)
ret i8* null
}

LLVM IR (-O2):
@.str = [16 x i8] c"%d is finished\0A\00"
define noalias i8* @philosopher(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = trunc i64 %2 to i32
%4 = tail call i32 @get_left_fork(i32 %3)
%5 = tail call i32 @get_right_fork(i32 %3)
%6 = tail call i32 (...) @eat()
%7 = tail call i32 @put_left_fork(i32 %3)
%8 = tail call i32 @put_right_fork(i32 %3)
%9 = tail call i32 @get_left_fork(i32 %3)
%10 = tail call i32 @get_right_fork(i32 %3)
%11 = tail call i32 (...) @eat()
%12 = tail call i32 @put_left_fork(i32 %3)
%13 = tail call i32 @put_right_fork(i32 %3)
%14 = add nsw i32 %3, 1
%15 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %14)
ret i8* null
}