#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ randomNumber(int, int);
int /*<<< orphan*/ *sem_open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ usleep(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int i, flag, myID;
  sem_t *teller, *supplier, *coin;
  teller = sem_open("/my_semaphor_1_name_simple_seq", 0);
  supplier = sem_open("/my_semaphor_2_name_simple_seq", 0);
  coin = sem_open("/my_semaphor_3_name_simple_seq", 0);
  if (argc > 1)
    myID = atoi(argv[1]);
  else
    myID = -1;
  flag = 1;
  while (flag > 0) {
    printf("\t\t>> customer: %1d\tgot ice\n\n", myID);
    usleep(randomNumber(2000000, 400000));
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
xor    %esi,%esi
call   1040 <sem_open@plt>
mov    %rax,-0x28(%rbp)
lea    0xe90(%rip),%rdi
xor    %esi,%esi
call   1040 <sem_open@plt>
mov    %rax,-0x30(%rbp)
lea    0xe9d(%rip),%rdi
xor    %esi,%esi
call   1040 <sem_open@plt>
mov    %rax,-0x38(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11cb <main+0x6b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    11d2 <main+0x72>
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    120d <main+0xad>
mov    -0x1c(%rbp),%esi
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1e8480,%edi
mov    $0x61a80,%esi
call   1050 <randomNumber@plt>
mov    %eax,%edi
call   1080 <usleep@plt>
jmp    11d9 <main+0x79>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xea0(%rip),%rdi
xor    %esi,%esi
call   1040 <sem_open@plt>
lea    0xeb1(%rip),%rdi
xor    %esi,%esi
call   1040 <sem_open@plt>
lea    0xec2(%rip),%rdi
xor    %esi,%esi
call   1040 <sem_open@plt>
mov    $0xffffffff,%ebx
cmp    $0x2,%ebp
jl     1198 <main+0x48>
mov    0x8(%r14),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
lea    0xebe(%rip),%r14
nop
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0x1e8480,%edi
mov    $0x61a80,%esi
call   1050 <randomNumber@plt>
mov    %eax,%edi
call   1070 <usleep@plt>
jmp    11a0 <main+0x50>

LLVM IR (-O0):
@.str = [31 x i8] c"/my_semaphor_1_name_simple_seq\00"
@.str.1 = [31 x i8] c"/my_semaphor_2_name_simple_seq\00"
@.str.2 = [31 x i8] c"/my_semaphor_3_name_simple_seq\00"
@.str.3 = [29 x i8] c"\09\09>> customer: %1d\09got ice\0A\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*
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 0)
store i32* %12, i32** %9
%13 = call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32* %13, i32** %10
%14 = call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 0)
store i32* %14, i32** %11
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %8
br label %23
22: ; preds = %2
store i32 -1, i32* %8
br label %23
23: ; preds = %22, %17
store i32 1, i32* %7
br label %24
24: ; preds = %27, %23
%25 = load i32, i32* %7
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i32, i32* %8
%29 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = call i32 @randomNumber(i32 2000000, i32 400000)
%31 = call i32 @usleep(i32 %30)
br label %24
32: ; preds = %24
%33 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [31 x i8] c"/my_semaphor_1_name_simple_seq\00"
@.str.1 = [31 x i8] c"/my_semaphor_2_name_simple_seq\00"
@.str.2 = [31 x i8] c"/my_semaphor_3_name_simple_seq\00"
@.str.3 = [29 x i8] c"\09\09>> customer: %1d\09got ice\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 0)
%4 = tail call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 0)
%5 = tail call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 0)
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
br label %11
11: ; preds = %2, %7
%12 = phi i32 [ %10, %7 ], [ -1, %2 ]
br label %13
13: ; preds = %13, %11
%14 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%15 = tail call i32 @randomNumber(i32 2000000, i32 400000)
%16 = tail call i32 @usleep(i32 %15)
br label %13
}