#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_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;
  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_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    1185 <main+0x35>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    118c <main+0x3c>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe74(%rip),%rdi
xor    %esi,%esi
call   1060 <sem_open@plt>
mov    %rax,-0x28(%rbp)
lea    0xe81(%rip),%rdi
xor    %esi,%esi
call   1060 <sem_open@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x5f5e100,-0x14(%rbp)
jge    1209 <main+0xb9>
mov    -0x20(%rbp),%rdi
call   1030 <sem_wait@plt>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <sem_post@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c8 <main+0x78>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x0,%r14d
cmp    $0x2,%edi
jl     116f <main+0x1f>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%r14d
lea    0xe8a(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe91(%rip),%rdi
xor    %esi,%esi
call   1060 <sem_open@plt>
mov    %rax,%r12
lea    0xe9f(%rip),%rdi
xor    %esi,%esi
call   1060 <sem_open@plt>
mov    %rax,%rbp
lea    0xead(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1030 <sem_wait@plt>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
call   1050 <sem_post@plt>
add    $0x1,%ebx
cmp    $0x5f5e100,%ebx
jne    11b0 <main+0x60>
xor    %eax,%eax
pop    %rbx
pop    %r12
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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %7
br label %18
17: ; preds = %2
store i32 0, i32* %7
br label %18
18: ; preds = %17, %12
%19 = load i32, i32* %7
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32* %21, i32** %9
%22 = call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 0)
store i32* %22, i32** %8
store i32 0, i32* %6
br label %23
23: ; preds = %34, %18
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 100000000
br i1 %25, label %26, label %37
26: ; preds = %23
%27 = load i32*, i32** %8
%28 = call i32 @sem_wait(i32* %27)
%29 = load i32, i32* %7
%30 = load i32, i32* %6
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %29, i32 %30)
%32 = load i32*, i32** %9
%33 = call i32 @sem_post(i32* %32)
br label %34
34: ; preds = %26
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %23
37: ; preds = %23
%38 = load i32, i32* %3
ret i32 %38
}

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 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
br label %8
8: ; preds = %2, %4
%9 = phi i32 [ %7, %4 ], [ 0, %2 ]
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = tail call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 0)
%12 = tail call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 0)
br label %13
13: ; preds = %8, %13
%14 = phi i32 [ 0, %8 ], [ %18, %13 ]
%15 = tail call i32 @sem_wait(i32* %12)
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %9, i32 %14)
%17 = tail call i32 @sem_post(i32* %11)
%18 = add nuw nsw i32 %14, 1
%19 = icmp eq i32 %18, 100000000
br i1 %19, label %20, label %13
20: ; preds = %13
ret i32 0
}