#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 = (intptr_t)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 i64
%7 = trunc i64 %6 to i32
store i32 %7, i32* %3
store i32 0, i32* %4
br label %8
8: ; preds = %11, %1
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %23
11: ; preds = %8
%12 = load i32, i32* %4
%13 = add nsw i32 %12, 1
store i32 %13, i32* %4
%14 = load i32, i32* %3
%15 = call i32 @get_left_fork(i32 %14)
%16 = load i32, i32* %3
%17 = call i32 @get_right_fork(i32 %16)
%18 = call i32 (...) @eat()
%19 = load i32, i32* %3
%20 = call i32 @put_left_fork(i32 %19)
%21 = load i32, i32* %3
%22 = call i32 @put_right_fork(i32 %21)
br label %8
23: ; preds = %8
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
%26 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %25)
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
}