#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;
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ O_CREAT;
int /*<<< orphan*/ execl(char *, char *, char *, int /*<<< orphan*/ *);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ *sem_open(char *, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ sem_unlink(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ waitpid(scalar_t__, int /*<<< orphan*/ *,
                           int /*<<< orphan*/);
int main(void) {
  int j;
  char string[8];
  sem_t *coin, *lock;
  pid_t tellerPID;
  sem_unlink("/my_semaphor_2_name_simple_seq");
  sem_unlink("/my_semaphor_1_name_simple_seq");
  lock = sem_open("/my_semaphor_2_name_simple_seq", O_CREAT, 0700, 0);
  coin = sem_open("/my_semaphor_1_name_simple_seq", O_CREAT, 0700, 3);
  for (j = 1; j <= 4; j++) {
    if (fork() == 0) {
      sprintf(string, "%d", j);
      execl("./customer.e", "customer.e", string, NULL);
      printf("*** could not start customer.e ***\n");
    }
  }
  if ((tellerPID = fork()) == 0) {
    execl("./coffeeTeller.e", "coffeeTeller.e", "0", NULL);
    printf("*** could not start coffeTeller ***\n");
  }
  waitpid(tellerPID, NULL, 0);
  system("killall coffeeTeller.e");
  system("killall customer.e");
  sem_unlink("/my_semaphor_2_name_simple_seq");
  sem_unlink("/my_semaphor_1_name_simple_seq");
  printf("\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
call   1090 <sem_unlink@plt>
lea    0xe7d(%rip),%rdi
call   1090 <sem_unlink@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
lea    0xe49(%rip),%rdi
mov    $0x1c0,%edx
xor    %ecx,%ecx
call   1050 <sem_open@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    0xe48(%rip),%rdi
mov    $0x1c0,%edx
mov    $0x3,%ecx
call   1050 <sem_open@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jg     1259 <main+0xd9>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%rax
jne    1246 <main+0xc6>
lea    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe24(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x10(%rbp),%rdx
lea    0xe17(%rip),%rdi
lea    0xe98(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1080 <execl@plt>
lea    0xe0d(%rip),%rdi
call   1040 <printf@plt>
jmp    124b <main+0xcb>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11f1 <main+0x71>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1298 <main+0x118>
lea    0xdfd(%rip),%rdi
lea    0xe36(%rip),%rsi
lea    0xe00(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1080 <execl@plt>
lea    0xdf2(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <waitpid@plt>
lea    0xdfc(%rip),%rdi
call   1030 <system@plt>
lea    0xe07(%rip),%rdi
call   1030 <system@plt>
lea    0xd3a(%rip),%rdi
call   1090 <sem_unlink@plt>
lea    0xd4d(%rip),%rdi
call   1090 <sem_unlink@plt>
lea    0xd92(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe60(%rip),%r15
mov    %r15,%rdi
call   10a0 <sem_unlink@plt>
lea    0xe70(%rip),%r14
mov    %r14,%rdi
call   10a0 <sem_unlink@plt>
mov    0x2e3a(%rip),%rbx
mov    (%rbx),%esi
mov    %r15,%rdi
mov    $0x1c0,%edx
xor    %ecx,%ecx
call   1060 <sem_open@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
mov    $0x1c0,%edx
mov    $0x3,%ecx
call   1060 <sem_open@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
jne    122c <main+0x9c>
lea    0xe48(%rip),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%edx
call   1080 <sprintf@plt>
lea    0xe32(%rip),%rdi
lea    0xe6a(%rip),%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1090 <execl@plt>
lea    0xe88(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
jne    1275 <main+0xe5>
lea    0xdff(%rip),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2,%edx
call   1080 <sprintf@plt>
lea    0xde9(%rip),%rdi
lea    0xe21(%rip),%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1090 <execl@plt>
lea    0xe3f(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
jne    12be <main+0x12e>
lea    0xdb6(%rip),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3,%edx
call   1080 <sprintf@plt>
lea    0xda0(%rip),%rdi
lea    0xdd8(%rip),%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1090 <execl@plt>
lea    0xdf6(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
jne    1307 <main+0x177>
lea    0xd6d(%rip),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x4,%edx
call   1080 <sprintf@plt>
lea    0xd57(%rip),%rdi
lea    0xd8f(%rip),%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1090 <execl@plt>
lea    0xdad(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    133e <main+0x1ae>
lea    0xd31(%rip),%rdi
lea    0xd45(%rip),%rsi
lea    0xd34(%rip),%rdx
xor    %ecx,%ecx
call   1090 <execl@plt>
lea    0xd52(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <waitpid@plt>
lea    0xd10(%rip),%rdi
call   1050 <system@plt>
lea    0xd1b(%rip),%rdi
call   1050 <system@plt>
lea    0xc97(%rip),%rdi
call   10a0 <sem_unlink@plt>
lea    0xcaa(%rip),%rdi
call   10a0 <sem_unlink@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [31 x i8] c"/my_semaphor_2_name_simple_seq\00"
@.str.1 = [31 x i8] c"/my_semaphor_1_name_simple_seq\00"
@O_CREAT = global i32 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [13 x i8] c"./customer.e\00"
@.str.4 = [11 x i8] c"customer.e\00"
@.str.5 = [36 x i8] c"*** could not start customer.e ***\0A\00"
@.str.6 = [17 x i8] c"./coffeeTeller.e\00"
@.str.7 = [15 x i8] c"coffeeTeller.e\00"
@.str.8 = [2 x i8] c"0\00"
@.str.9 = [37 x i8] c"*** could not start coffeTeller ***\0A\00"
@.str.10 = [23 x i8] c"killall coffeeTeller.e\00"
@.str.11 = [19 x i8] c"killall customer.e\00"
@.str.12 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [8 x i8]
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32 @sem_unlink(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @sem_unlink(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @O_CREAT
%10 = call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %9, i32 448, i32 0)
store i32* %10, i32** %5
%11 = load i32, i32* @O_CREAT
%12 = call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 448, i32 3)
store i32* %12, i32** %4
store i32 1, i32* %2
br label %13
13: ; preds = %27, %0
%14 = load i32, i32* %2
%15 = icmp sle i32 %14, 4
br i1 %15, label %16, label %30
16: ; preds = %13
%17 = call i64 (...) @fork()
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%21 = load i32, i32* %2
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%24 = call i32 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %23, i32* null)
%25 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
br label %26
26: ; preds = %19, %16
br label %27
27: ; preds = %26
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %13
30: ; preds = %13
%31 = call i64 (...) @fork()
store i64 %31, i64* %6
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = call i32 @execl(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32* null)
%35 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0))
br label %36
36: ; preds = %33, %30
%37 = load i64, i64* %6
%38 = call i32 @waitpid(i64 %37, i32* null, i32 0)
%39 = call i32 @system(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
%40 = call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
%41 = call i32 @sem_unlink(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%42 = call i32 @sem_unlink(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%43 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
@.str = [31 x i8] c"/my_semaphor_2_name_simple_seq\00"
@.str.1 = [31 x i8] c"/my_semaphor_1_name_simple_seq\00"
@O_CREAT = global i32 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [13 x i8] c"./customer.e\00"
@.str.4 = [11 x i8] c"customer.e\00"
@.str.6 = [17 x i8] c"./coffeeTeller.e\00"
@.str.7 = [15 x i8] c"coffeeTeller.e\00"
@.str.8 = [2 x i8] c"0\00"
@.str.10 = [23 x i8] c"killall coffeeTeller.e\00"
@.str.11 = [19 x i8] c"killall customer.e\00"
@str = [36 x i8] c"*** could not start coffeTeller ***\00"
@str.13 = [35 x i8] c"*** could not start customer.e ***\00"
define i32 @main() {
%1 = alloca [8 x i8]
%2 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @sem_unlink(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @sem_unlink(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%5 = load i32, i32* @O_CREAT
%6 = tail call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %5, i32 448, i32 0)
%7 = load i32, i32* @O_CREAT
%8 = tail call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 448, i32 3)
%9 = call i64 (...) @fork()
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 1)
%13 = call i32 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %2, i32* null)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.13, i64 0, i64 0))
br label %15
15: ; preds = %0, %11
%16 = call i64 (...) @fork()
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%20 = call i32 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %2, i32* null)
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.13, i64 0, i64 0))
br label %22
22: ; preds = %18, %15
%23 = call i64 (...) @fork()
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 3)
%27 = call i32 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %2, i32* null)
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.13, i64 0, i64 0))
br label %29
29: ; preds = %25, %22
%30 = call i64 (...) @fork()
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 4)
%34 = call i32 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %2, i32* null)
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.13, i64 0, i64 0))
br label %36
36: ; preds = %32, %29
%37 = call i64 (...) @fork()
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = call i32 @execl(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32* null)
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %42
42: ; preds = %39, %36
%43 = call i32 @waitpid(i64 %37, i32* null, i32 0)
%44 = call i32 @system(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
%45 = call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
%46 = call i32 @sem_unlink(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%47 = call i32 @sem_unlink(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%48 = call i32 @putchar(i32 10)
ret i32 0
}