#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*/ printf(char *, int);
int /*<<< orphan*/ v_operate(int, int);
void test(int argi, char *state, int semid) {
  if (state[argi] == 1 && state[(5 + argi - 1) % 5] != 2 &&
      state[(argi + 1) % 5] != 2) {
    state[argi] = 2;
    printf("Hehe,philosopher #%d can eat now\n", argi);
    v_operate(semid, argi);
  } else if (state[argi] != 1)
    printf("Faint,philosopher #%d don't want to eat\n", argi);
  else
    printf("Oh,philosopher #%d can't eat now!\n", argi);
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x1,%eax
jne    11c9 <test+0xa9>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
add    $0x5,%eax
sub    $0x1,%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%rax
movslq %edx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2,%eax
je     11c9 <test+0xa9>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    -0x28(%rbp),%rax
movslq %edx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2,%eax
je     11c9 <test+0xa9>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movb   $0x2,(%rax,%rcx,1)
mov    -0x4(%rbp),%esi
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1040 <v_operate@plt>
jmp    1206 <test+0xe6>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x1,%eax
je     11f2 <test+0xd2>
mov    -0x4(%rbp),%esi
lea    0xe3a(%rip),%rdi
call   1030 <printf@plt>
jmp    1201 <test+0xe1>
mov    -0x4(%rbp),%esi
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
jmp    1206 <test+0xe6>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
movslq %edi,%rax
cmpb   $0x1,(%rsi,%rax,1)
jne    1189 <test+0x69>
mov    %edx,%ebp
lea    0x4(%rbx),%ecx
movslq %ecx,%rcx
imul   $0x66666667,%rcx,%rdx
mov    %rdx,%rdi
shr    $0x3f,%rdi
sar    $0x21,%rdx
add    %edi,%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%ecx
movslq %ecx,%rcx
cmpb   $0x2,(%rsi,%rcx,1)
je     1180 <test+0x60>
lea    0x1(%rbx),%ecx
movslq %ecx,%rcx
imul   $0x66666667,%rcx,%rdx
mov    %rdx,%rdi
shr    $0x3f,%rdi
sar    $0x21,%rdx
add    %edi,%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%ecx
movslq %ecx,%rcx
cmpb   $0x2,(%rsi,%rcx,1)
jne    119d <test+0x7d>
lea    0xec4(%rip),%rdi
jmp    1190 <test+0x70>
lea    0xe92(%rip),%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printf@plt>
movb   $0x2,(%rsi,%rax,1)
lea    0xe58(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %ebp,%edi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <v_operate@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"Hehe,philosopher #%d can eat now\0A\00"
@.str.1 = [41 x i8] c"Faint,philosopher #%d don't want to eat\0A\00"
@.str.2 = [35 x i8] c"Oh,philosopher #%d can't eat now!\0A\00"
define void @test(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 i8*, i8** %5
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %45
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = load i32, i32* %4
%17 = add nsw i32 5, %16
%18 = sub nsw i32 %17, 1
%19 = srem i32 %18, 5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %15, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 2
br i1 %24, label %25, label %45
25: ; preds = %14
%26 = load i8*, i8** %5
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
%29 = srem i32 %28, 5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %26, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 2
br i1 %34, label %35, label %45
35: ; preds = %25
%36 = load i8*, i8** %5
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 2, i8* %39
%40 = load i32, i32* %4
%41 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %6
%43 = load i32, i32* %4
%44 = call i32 @v_operate(i32 %42, i32 %43)
br label %60
45: ; preds = %25, %14, %3
%46 = load i8*, i8** %5
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %51, 1
br i1 %52, label %53, label %56
53: ; preds = %45
%54 = load i32, i32* %4
%55 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %54)
br label %59
56: ; preds = %45
%57 = load i32, i32* %4
%58 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %56, %53
br label %60
60: ; preds = %59, %35
ret void
}

LLVM IR (-O2):
@.str = [34 x i8] c"Hehe,philosopher #%d can eat now\0A\00"
@.str.1 = [41 x i8] c"Faint,philosopher #%d don't want to eat\0A\00"
@.str.2 = [35 x i8] c"Oh,philosopher #%d can't eat now!\0A\00"
define void @test(i32 %0, i8* nocapture %1, i32 %2) {
%4 = sext i32 %0 to i64
%5 = getelementptr inbounds i8, i8* %1, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 1
br i1 %7, label %8, label %25
8: ; preds = %3
%9 = add nsw i32 %0, 4
%10 = srem i32 %9, 5
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %1, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 2
br i1 %14, label %27, label %15
15: ; preds = %8
%16 = add nsw i32 %0, 1
%17 = srem i32 %16, 5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 2
br i1 %21, label %27, label %22
22: ; preds = %15
store i8 2, i8* %5
%23 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %0)
%24 = tail call i32 @v_operate(i32 %2, i32 %0)
br label %29
25: ; preds = %3
%26 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %29
27: ; preds = %15, %8
%28 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %29
29: ; preds = %25, %27, %22
ret void
}