#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 */
typedef int /*<<< orphan*/ sem_t;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ sem_getvalue(int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ *sem_open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sem_post(int /*<<< orphan*/ *);
int /*<<< orphan*/ sem_wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int i, myID;
  int coin_val;
  sem_t *coin, *lock;
  if (argc > 1)
    myID = atoi(argv[1]);
  else
    myID = 0;
  printf("Customer starting (%d)\n", myID);
  lock = sem_open("/my_semaphor_2_name_simple_seq", 0);
  coin = sem_open("/my_semaphor_1_name_simple_seq", 0);
  for (i = 0; i < 100 * 1000 * 1000; i++) {
    sem_wait(coin);
    printf("\t\t\tcustomer: put coin(%d)@%d\n", myID, i);
    sem_getvalue(coin, &coin_val);
    if (coin_val == 0)
      sem_post(lock);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1195 <main+0x35>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    119c <main+0x3c>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe64(%rip),%rdi
xor    %esi,%esi
call   1070 <sem_open@plt>
mov    %rax,-0x30(%rbp)
lea    0xe71(%rip),%rdi
xor    %esi,%esi
call   1070 <sem_open@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x5f5e100,-0x14(%rbp)
jge    1235 <main+0xd5>
mov    -0x28(%rbp),%rdi
call   1030 <sem_wait@plt>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1050 <sem_getvalue@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    1222 <main+0xc2>
mov    -0x30(%rbp),%rdi
call   1060 <sem_post@plt>
jmp    1227 <main+0xc7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d8 <main+0x78>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x0,%r13d
cmp    $0x2,%edi
jl     1182 <main+0x22>
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r13d
lea    0xe77(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7e(%rip),%rdi
xor    %esi,%esi
call   1070 <sem_open@plt>
mov    %rax,%r14
lea    0xe8c(%rip),%rdi
xor    %esi,%esi
call   1070 <sem_open@plt>
mov    %rax,%rbx
lea    0xe9a(%rip),%r15
lea    0x4(%rsp),%r12
xor    %ebp,%ebp
jmp    11db <main+0x7b>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
cmp    $0x5f5e100,%ebp
je     120e <main+0xae>
mov    %rbx,%rdi
call   1030 <sem_wait@plt>
mov    %r15,%rdi
mov    %r13d,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <sem_getvalue@plt>
cmpl   $0x0,0x4(%rsp)
jne    11d0 <main+0x70>
mov    %r14,%rdi
call   1060 <sem_post@plt>
jmp    11d0 <main+0x70>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Customer starting (%d)\0A\00"
@.str.1 = [31 x i8] c"/my_semaphor_2_name_simple_seq\00"
@.str.2 = [31 x i8] c"/my_semaphor_1_name_simple_seq\00"
@.str.3 = [30 x i8] c"\09\09\09customer: put coin(%d)@%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %7
br label %19
18: ; preds = %2
store i32 0, i32* %7
br label %19
19: ; preds = %18, %13
%20 = load i32, i32* %7
%21 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32* %22, i32** %10
%23 = call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 0)
store i32* %23, i32** %9
store i32 0, i32* %6
br label %24
24: ; preds = %41, %19
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 100000000
br i1 %26, label %27, label %44
27: ; preds = %24
%28 = load i32*, i32** %9
%29 = call i32 @sem_wait(i32* %28)
%30 = load i32, i32* %7
%31 = load i32, i32* %6
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 %31)
%33 = load i32*, i32** %9
%34 = call i32 @sem_getvalue(i32* %33, i32* %8)
%35 = load i32, i32* %8
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %27
%38 = load i32*, i32** %10
%39 = call i32 @sem_post(i32* %38)
br label %40
40: ; preds = %37, %27
br label %41
41: ; preds = %40
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %24
44: ; preds = %24
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str = [24 x i8] c"Customer starting (%d)\0A\00"
@.str.1 = [31 x i8] c"/my_semaphor_2_name_simple_seq\00"
@.str.2 = [31 x i8] c"/my_semaphor_1_name_simple_seq\00"
@.str.3 = [30 x i8] c"\09\09\09customer: put coin(%d)@%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
br label %10
10: ; preds = %2, %6
%11 = phi i32 [ %9, %6 ], [ 0, %2 ]
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = tail call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 0)
%14 = tail call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 0)
br label %15
15: ; preds = %10, %24
%16 = phi i32 [ 0, %10 ], [ %25, %24 ]
%17 = call i32 @sem_wait(i32* %14)
%18 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %11, i32 %16)
%19 = call i32 @sem_getvalue(i32* %14, i32* %3)
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 @sem_post(i32* %13)
br label %24
24: ; preds = %15, %22
%25 = add nuw nsw i32 %16, 1
%26 = icmp eq i32 %25, 100000000
br i1 %26, label %27, label %15
27: ; preds = %24
ret i32 0
}