#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*/ p_operate(int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ test(int, char *, int);
int /*<<< orphan*/ v_operate(int, int);
void take_forks(int argi, char *state, int semid) {
  p_operate(semid, 5);
  state[argi] = 1;
  printf("Philosopher #%d is hungry.Can he eat...\n", argi);
  test(argi, state, semid);
  v_operate(semid, 5);
  p_operate(semid, argi);
}


x86 assembly (clang, -O0):
<take_forks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1040 <p_operate@plt>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
mov    -0x4(%rbp),%esi
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <test@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1050 <v_operate@plt>
mov    -0x14(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1040 <p_operate@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<take_forks>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%ebp
mov    %edx,%edi
mov    $0x5,%esi
call   1040 <p_operate@plt>
movslq %ebp,%rbp
movb   $0x1,(%r14,%rbp,1)
lea    0xe9a(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <test@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   1050 <v_operate@plt>
mov    %ebx,%edi
mov    %ebp,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <p_operate@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"Philosopher #%d is hungry.Can he eat...\0A\00"
define void @take_forks(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = call i32 @p_operate(i32 %7, i32 5)
%9 = load i8*, i8** %5
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
store i8 1, i8* %12
%13 = load i32, i32* %4
%14 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %4
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = call i32 @test(i32 %15, i8* %16, i32 %17)
%19 = load i32, i32* %6
%20 = call i32 @v_operate(i32 %19, i32 5)
%21 = load i32, i32* %6
%22 = load i32, i32* %4
%23 = call i32 @p_operate(i32 %21, i32 %22)
ret void
}

LLVM IR (-O2):
@.str = [41 x i8] c"Philosopher #%d is hungry.Can he eat...\0A\00"
define void @take_forks(i32 %0, i8* %1, i32 %2) {
%4 = tail call i32 @p_operate(i32 %2, i32 5)
%5 = sext i32 %0 to i64
%6 = getelementptr inbounds i8, i8* %1, i64 %5
store i8 1, i8* %6
%7 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = tail call i32 @test(i32 %0, i8* %1, i32 %2)
%9 = tail call i32 @v_operate(i32 %2, i32 5)
%10 = tail call i32 @p_operate(i32 %2, i32 %0)
ret void
}