#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *sem_open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int main(void) {
  int i, flag, refills;
  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);
  refills = 0;
  flag = 1;
  while (flag > 0) {
    sleep(3);
    printf("\n********************************");
    printf("\n* refilling items (refill %3d) *", ++refills);
    printf("\n********************************\n");
    if (refills == 30)
      flag = 0;
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
xor    %esi,%esi
call   1040 <sem_open@plt>
mov    %rax,-0x18(%rbp)
lea    0xeb7(%rip),%rdi
xor    %esi,%esi
call   1040 <sem_open@plt>
mov    %rax,-0x20(%rbp)
lea    0xec4(%rip),%rdi
xor    %esi,%esi
call   1040 <sem_open@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11f0 <main+0xb0>
mov    $0x3,%edi
call   1060 <sleep@plt>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1e,-0x10(%rbp)
jne    11eb <main+0xab>
movl   $0x0,-0xc(%rbp)
jmp    1193 <main+0x53>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%rdi
xor    %esi,%esi
call   1050 <sem_open@plt>
lea    0xeb5(%rip),%rdi
xor    %esi,%esi
call   1050 <sem_open@plt>
lea    0xec6(%rip),%rdi
xor    %esi,%esi
call   1050 <sem_open@plt>
mov    $0x1,%ebx
lea    0xef4(%rip),%r14
lea    0xecb(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x3,%edi
call   1070 <sleep@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
add    $0x1,%ebx
cmp    $0x1f,%ebx
jne    11a0 <main+0x50>
xor    %edi,%edi
call   1060 <exit@plt>

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 = [34 x i8] c"\0A********************************\00"
@.str.4 = [34 x i8] c"\0A* refilling items (refill %3d) *\00"
@.str.5 = [35 x i8] c"\0A********************************\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
store i32 0, i32* %1
%8 = call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 0)
store i32* %8, i32** %5
%9 = call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32* %9, i32** %6
%10 = call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 0)
store i32* %10, i32** %7
store i32 0, i32* %4
store i32 1, i32* %3
br label %11
11: ; preds = %24, %0
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %11
%15 = call i32 @sleep(i32 3)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 30
br i1 %22, label %23, label %24
23: ; preds = %14
store i32 0, i32* %3
br label %24
24: ; preds = %23, %14
br label %11
25: ; preds = %11
%26 = 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.4 = [34 x i8] c"\0A* refilling items (refill %3d) *\00"
@str = [34 x i8] c"\0A********************************\00"
define i32 @main() {
%1 = tail call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 0)
%2 = tail call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 0)
%3 = tail call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 0)
br label %4
4: ; preds = %0, %4
%5 = phi i32 [ 0, %0 ], [ %8, %4 ]
%6 = tail call i32 @sleep(i32 3)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%8 = add nuw nsw i32 %5, 1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %8)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%11 = icmp eq i32 %8, 30
br i1 %11, label %12, label %4
12: ; preds = %4
%13 = tail call i32 @exit(i32 0)
unreachable
}