#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 main(void) {
  int i, count, currentStock = 0;
  char string[8];
  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);
  printf("\nice cream teller machine starting\n");
  count = 30 * 10;
  while (count > 0) {
    printf("teller: got money");
    printf(" -> dispense ice cream (stock left %d)\n", currentStock);
    count--;
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
xor    %esi,%esi
call   1040 <sem_open@plt>
mov    %rax,-0x20(%rbp)
lea    0xec0(%rip),%rdi
xor    %esi,%esi
call   1040 <sem_open@plt>
mov    %rax,-0x28(%rbp)
lea    0xecd(%rip),%rdi
xor    %esi,%esi
call   1040 <sem_open@plt>
mov    %rax,-0x30(%rbp)
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x12c,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11c8 <main+0x98>
lea    0xedf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xee0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1191 <main+0x61>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xeb5(%rip),%rdi
xor    %esi,%esi
call   1050 <sem_open@plt>
lea    0xec6(%rip),%rdi
xor    %esi,%esi
call   1050 <sem_open@plt>
lea    0xed7(%rip),%rdi
xor    %esi,%esi
call   1050 <sem_open@plt>
lea    0xf22(%rip),%rdi
call   1030 <puts@plt>
mov    $0x12d,%ebp
lea    0xed7(%rip),%r14
lea    0xee2(%rip),%rbx
nopl   (%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1190 <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 = [36 x i8] c"\0Aice cream teller machine starting\0A\00"
@.str.4 = [18 x i8] c"teller: got money\00"
@.str.5 = [40 x i8] c" -> dispense ice cream (stock left %d)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [8 x i8]
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %4
%9 = call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, 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.1, i64 0, i64 0), i32 0)
store i32* %10, i32** %7
%11 = call i32* @sem_open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 0)
store i32* %11, i32** %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
store i32 300, i32* %3
br label %13
13: ; preds = %16, %0
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%18 = load i32, i32* %4
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %3
%21 = add nsw i32 %20, -1
store i32 %21, i32* %3
br label %13
22: ; preds = %13
%23 = 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 = [18 x i8] c"teller: got money\00"
@.str.5 = [40 x i8] c" -> dispense ice cream (stock left %d)\0A\00"
@str = [35 x i8] c"\0Aice cream teller machine starting\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)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ 300, %0 ], [ %9, %5 ]
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 0)
%9 = add nsw i32 %6, -1
%10 = icmp ugt i32 %6, 1
br i1 %10, label %5, label %11
11: ; preds = %5
%12 = tail call i32 @exit(i32 0)
unreachable
}