#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ randwait(int);
int /*<<< orphan*/ sempost(int);
int /*<<< orphan*/ semwait(int);
void customer(int num) {
  printf("Customer %d is going to the barber's shop.\n", num);
  randwait(5);
  printf("Customer %d arrived at barber shop.\n", num);
  semwait(0);
  printf("Customer %d entering waiting room.\n", num);
  semwait(1);
  sempost(0);
  printf("Customer %d waking the barber.\n", num);
  sempost(2);
  semwait(3);
  sempost(1);
  printf("Customer %d leaving barber shop.\n", num);
  exit(0);
}


x86 assembly (clang, -O0):
<customer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x5,%edi
call   1060 <randwait@plt>
mov    -0x4(%rbp),%esi
lea    0xeae(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <semwait@plt>
mov    -0x4(%rbp),%esi
lea    0xebd(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <semwait@plt>
xor    %edi,%edi
call   1040 <sempost@plt>
mov    -0x4(%rbp),%esi
lea    0xec1(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1040 <sempost@plt>
mov    $0x3,%edi
call   1050 <semwait@plt>
mov    $0x1,%edi
call   1040 <sempost@plt>
mov    -0x4(%rbp),%esi
lea    0xeb4(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<customer>:
push   %rbx
mov    %edi,%ebx
lea    0xea6(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0x5,%edi
call   1060 <randwait@plt>
lea    0xeba(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <semwait@plt>
lea    0xeca(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <semwait@plt>
xor    %edi,%edi
call   1040 <sempost@plt>
lea    0xecf(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1040 <sempost@plt>
mov    $0x3,%edi
call   1050 <semwait@plt>
mov    $0x1,%edi
call   1040 <sempost@plt>
lea    0xec3(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [44 x i8] c"Customer %d is going to the barber's shop.\0A\00"
@.str.1 = [37 x i8] c"Customer %d arrived at barber shop.\0A\00"
@.str.2 = [36 x i8] c"Customer %d entering waiting room.\0A\00"
@.str.3 = [32 x i8] c"Customer %d waking the barber.\0A\00"
@.str.4 = [34 x i8] c"Customer %d leaving barber shop.\0A\00"
define void @customer(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i32 @randwait(i32 5)
%6 = load i32, i32* %2
%7 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = call i32 @semwait(i32 0)
%9 = load i32, i32* %2
%10 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = call i32 @semwait(i32 1)
%12 = call i32 @sempost(i32 0)
%13 = load i32, i32* %2
%14 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = call i32 @sempost(i32 2)
%16 = call i32 @semwait(i32 3)
%17 = call i32 @sempost(i32 1)
%18 = load i32, i32* %2
%19 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [44 x i8] c"Customer %d is going to the barber's shop.\0A\00"
@.str.1 = [37 x i8] c"Customer %d arrived at barber shop.\0A\00"
@.str.2 = [36 x i8] c"Customer %d entering waiting room.\0A\00"
@.str.3 = [32 x i8] c"Customer %d waking the barber.\0A\00"
@.str.4 = [34 x i8] c"Customer %d leaving barber shop.\0A\00"
define void @customer(i32 %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = tail call i32 @randwait(i32 5)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%5 = tail call i32 @semwait(i32 0)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%7 = tail call i32 @semwait(i32 1)
%8 = tail call i32 @sempost(i32 0)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %0)
%10 = tail call i32 @sempost(i32 2)
%11 = tail call i32 @semwait(i32 3)
%12 = tail call i32 @sempost(i32 1)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %0)
%14 = tail call i32 @exit(i32 0)
unreachable
}