#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 put_forks(int argi, char *state, int semid) {
  p_operate(semid, 5);
  state[argi] = 0;
  printf("Philosopher #%d eat O.K..Can his neighbours eat...\n", argi);
  test((5 + argi - 1) % 5, state, semid);
  test((argi + 1) % 5, state, semid);
  v_operate(semid, 5);
}


x86 assembly (clang, -O0):
<put_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   $0x0,(%rax,%rcx,1)
mov    -0x4(%rbp),%esi
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x5,%eax
sub    $0x1,%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <test@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %edx,%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>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_forks>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %edi,%ebx
mov    %edx,%edi
mov    $0x5,%esi
call   1040 <p_operate@plt>
movslq %ebx,%rbx
movb   $0x0,(%r14,%rbx,1)
lea    0xe9a(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
lea    0x4(%rbx),%eax
cltq
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rax
add    %ecx,%eax
lea    (%rax,%rax,4),%eax
neg    %eax
lea    (%rbx,%rax,1),%edi
add    $0x4,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1060 <test@plt>
mov    %ebx,%eax
add    $0x1,%eax
cltq
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rax
add    %ecx,%eax
lea    (%rax,%rax,4),%eax
neg    %eax
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1060 <test@plt>
mov    %ebp,%edi
mov    $0x5,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <v_operate@plt>

LLVM IR (-O0):
@.str = [52 x i8] c"Philosopher #%d eat O.K..Can his neighbours eat...\0A\00"
define void @put_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 0, i8* %12
%13 = load i32, i32* %4
%14 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %4
%16 = add nsw i32 5, %15
%17 = sub nsw i32 %16, 1
%18 = srem i32 %17, 5
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = call i32 @test(i32 %18, i8* %19, i32 %20)
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
%24 = srem i32 %23, 5
%25 = load i8*, i8** %5
%26 = load i32, i32* %6
%27 = call i32 @test(i32 %24, i8* %25, i32 %26)
%28 = load i32, i32* %6
%29 = call i32 @v_operate(i32 %28, i32 5)
ret void
}

LLVM IR (-O2):
@.str = [52 x i8] c"Philosopher #%d eat O.K..Can his neighbours eat...\0A\00"
define void @put_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 0, i8* %6
%7 = tail call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = add nsw i32 %0, 4
%9 = srem i32 %8, 5
%10 = tail call i32 @test(i32 %9, i8* %1, i32 %2)
%11 = add nsw i32 %0, 1
%12 = srem i32 %11, 5
%13 = tail call i32 @test(i32 %12, i8* %1, i32 %2)
%14 = tail call i32 @v_operate(i32 %2, i32 5)
ret void
}