#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_SUCCESS;
int /*<<< orphan*/ condReserveSemaphore(int /*<<< orphan*/);
int /*<<< orphan*/ createSemaphore();
int /*<<< orphan*/ destroySemaphore(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char getopt(int, char **, char *);
int /*<<< orphan*/ helpAndExit(char *, int /*<<< orphan*/);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ releaseSemaphore(int /*<<< orphan*/);
int /*<<< orphan*/ reserveSemaphore(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char opt;
  if (argc == 1) {
    helpAndExit(argv[0], EXIT_SUCCESS);
  }
  while ((opt = getopt(argc, argv, "+cr:x:q:d:h")) != -1) {
    switch (opt) {
    case 'c':
      createSemaphore();
      break;
    case 'r':
      reserveSemaphore(optarg);
      break;
    case 'x':
      releaseSemaphore(optarg);
      break;
    case 'q':
      condReserveSemaphore(optarg);
      break;
    case 'd':
      destroySemaphore(optarg);
      break;
    case 'h':
      helpAndExit(argv[0], EXIT_SUCCESS);
      break;
    }
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11b5 <main+0x35>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
call   1080 <helpAndExit@plt>
jmp    11ba <main+0x3a>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe90(%rip),%rdx
call   1070 <getopt@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     1278 <main+0xf8>
movsbl -0x11(%rbp),%eax
add    $0xffffff9d,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x15,%eax
ja     1273 <main+0xf3>
mov    -0x20(%rbp),%rax
lea    0xe03(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1030 <createSemaphore@plt>
jmp    1273 <main+0xf3>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1060 <reserveSemaphore@plt>
jmp    1273 <main+0xf3>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   1040 <releaseSemaphore@plt>
jmp    1273 <main+0xf3>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   10a0 <condReserveSemaphore@plt>
jmp    1273 <main+0xf3>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
call   1050 <destroySemaphore@plt>
jmp    1273 <main+0xf3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2d6c(%rip),%rax
mov    (%rax),%esi
call   1080 <helpAndExit@plt>
jmp    11ba <main+0x3a>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r15d
cmp    $0x1,%edi
jne    11a7 <main+0x27>
mov    (%rbx),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
call   1080 <helpAndExit@plt>
lea    0xeaa(%rip),%rdx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1070 <getopt@plt>
cmp    $0xff,%al
jne    11cb <main+0x4b>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe86(%rip),%r14
lea    0xe27(%rip),%rbp
mov    0x2e18(%rip),%r12
mov    0x2df1(%rip),%r13
jmp    1212 <main+0x92>
mov    (%rbx),%rdi
mov    0x0(%r13),%esi
call   1080 <helpAndExit@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1070 <getopt@plt>
cmp    $0xff,%al
je     11bd <main+0x3d>
movsbl %al,%eax
add    $0xffffff9d,%eax
cmp    $0x15,%eax
ja     1200 <main+0x80>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
xor    %eax,%eax
call   1030 <createSemaphore@plt>
jmp    1200 <main+0x80>
mov    (%r12),%edi
call   1050 <destroySemaphore@plt>
jmp    1200 <main+0x80>
mov    (%r12),%edi
call   10a0 <condReserveSemaphore@plt>
jmp    1200 <main+0x80>
mov    (%r12),%edi
call   1060 <reserveSemaphore@plt>
jmp    1200 <main+0x80>
mov    (%r12),%edi
call   1040 <releaseSemaphore@plt>
jmp    1200 <main+0x80>

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
@.str = [12 x i8] c"+cr:x:q:d:h\00"
@optarg = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = load i32, i32* @EXIT_SUCCESS
%14 = call i32 @helpAndExit(i8* %12, i32 %13)
br label %15
15: ; preds = %9, %2
br label %16
16: ; preds = %45, %15
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call signext i8 @getopt(i32 %17, i8** %18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8 %19, i8* %6
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, -1
br i1 %21, label %22, label %46
22: ; preds = %16
%23 = load i8, i8* %6
%24 = sext i8 %23 to i32
switch i32 %24, label %45 [
i32 99, label %25
i32 114, label %27
i32 120, label %30
i32 113, label %33
i32 100, label %36
i32 104, label %39
]
25: ; preds = %22
%26 = call i32 (...) @createSemaphore()
br label %45
27: ; preds = %22
%28 = load i32, i32* @optarg
%29 = call i32 @reserveSemaphore(i32 %28)
br label %45
30: ; preds = %22
%31 = load i32, i32* @optarg
%32 = call i32 @releaseSemaphore(i32 %31)
br label %45
33: ; preds = %22
%34 = load i32, i32* @optarg
%35 = call i32 @condReserveSemaphore(i32 %34)
br label %45
36: ; preds = %22
%37 = load i32, i32* @optarg
%38 = call i32 @destroySemaphore(i32 %37)
br label %45
39: ; preds = %22
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = load i32, i32* @EXIT_SUCCESS
%44 = call i32 @helpAndExit(i8* %42, i32 %43)
br label %45
45: ; preds = %22, %39, %36, %33, %30, %27, %25
br label %16
46: ; preds = %16
%47 = load i32, i32* @EXIT_SUCCESS
%48 = call i32 @exit(i32 %47)
unreachable
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@.str = [12 x i8] c"+cr:x:q:d:h\00"
@optarg = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = load i32, i32* @EXIT_SUCCESS
%7 = tail call i32 @helpAndExit(i8* %5, i32 %6)
br label %8
8: ; preds = %4, %2
%9 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8 %9, -1
br i1 %10, label %35, label %11
11: ; preds = %8, %32
%12 = phi i8 [ %33, %32 ], [ %9, %8 ]
%13 = sext i8 %12 to i32
switch i32 %13, label %32 [
i32 99, label %14
i32 114, label %16
i32 120, label %19
i32 113, label %22
i32 100, label %25
i32 104, label %28
]
14: ; preds = %11
%15 = tail call i32 (...) @createSemaphore()
br label %32
16: ; preds = %11
%17 = load i32, i32* @optarg
%18 = tail call i32 @reserveSemaphore(i32 %17)
br label %32
19: ; preds = %11
%20 = load i32, i32* @optarg
%21 = tail call i32 @releaseSemaphore(i32 %20)
br label %32
22: ; preds = %11
%23 = load i32, i32* @optarg
%24 = tail call i32 @condReserveSemaphore(i32 %23)
br label %32
25: ; preds = %11
%26 = load i32, i32* @optarg
%27 = tail call i32 @destroySemaphore(i32 %26)
br label %32
28: ; preds = %11
%29 = load i8*, i8** %1
%30 = load i32, i32* @EXIT_SUCCESS
%31 = tail call i32 @helpAndExit(i8* %29, i32 %30)
br label %32
32: ; preds = %11, %28, %25, %22, %19, %16, %14
%33 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%34 = icmp eq i8 %33, -1
br i1 %34, label %35, label %11
35: ; preds = %32, %8
%36 = load i32, i32* @EXIT_SUCCESS
%37 = tail call i32 @exit(i32 %36)
unreachable
}