#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 */
struct sembuf {
  int sem_op;
  int /*<<< orphan*/ sem_flg;
  scalar_t__ sem_num;
};

/* Variables and functions */
char EOF;
int IPC_CREAT;
int /*<<< orphan*/ IPC_NOWAIT;
int atoi(int /*<<< orphan*/);
char getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, int);
int semget(int, int, int);
int semop(int, struct sembuf *, int);
int main(int argc, char **argv) {
  char ch;
  int num = 1;
  int key = 0x8888;
  int id;
  int error;
  struct sembuf buf;
  while ((ch = getopt(argc, argv, "k:-n:")) != EOF) {
    switch (ch) {
    case 'k':
      key = atoi(optarg);
      break;
    case 'n':
      num = atoi(optarg);
      break;
    }
  }
  id = semget(key, num, IPC_CREAT | 0777);
  if (id == -1)
    return 1;
  buf.sem_num = 0;
  buf.sem_op = 1;
  buf.sem_flg = IPC_NOWAIT;
  error = semop(id, &buf, 1);
  printf("semop: returned %d\n", error);
  return error;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x8888,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe7e(%rip),%rdx
call   1050 <getopt@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2e44(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11f1 <main+0xa1>
movsbl -0x11(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x6b,%eax
je     11c5 <main+0x75>
jmp    11b4 <main+0x64>
mov    -0x3c(%rbp),%eax
sub    $0x6e,%eax
je     11db <main+0x8b>
jmp    11ec <main+0x9c>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    11ec <main+0x9c>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    1174 <main+0x24>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    0x2dca(%rip),%rax
mov    (%rax),%edx
or     $0x1ff,%edx
call   1030 <semget@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1224 <main+0xd4>
movl   $0x1,-0x4(%rbp)
jmp    1268 <main+0x118>
movq   $0x0,-0x30(%rbp)
movl   $0x1,-0x38(%rbp)
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x1,%edx
call   1070 <semop@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xda9(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe96(%rip),%rdx
call   1050 <getopt@plt>
mov    0x2e62(%rip),%r14
mov    $0x8888,%r15d
mov    $0x1,%r12d
cmp    (%r14),%al
jne    11fa <main+0xaa>
mov    0x2e3a(%rip),%rax
mov    $0x1ff,%edx
or     (%rax),%edx
mov    %r15d,%edi
mov    %r12d,%esi
call   1030 <semget@plt>
cmp    $0xffffffff,%eax
mov    $0x1,%ebx
je     11e9 <main+0x99>
movq   $0x0,0x10(%rsp)
movl   $0x1,0x8(%rsp)
mov    0x2e26(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0xc(%rsp)
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1070 <semop@plt>
mov    %eax,%ebx
lea    0xe24(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x8888,%r15d
mov    $0x1,%r12d
lea    0xdf3(%rip),%r13
jmp    1237 <main+0xe7>
nop
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,%r12d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1050 <getopt@plt>
cmp    (%r14),%al
je     1187 <main+0x37>
movsbl %al,%eax
cmp    $0x6e,%eax
je     1210 <main+0xc0>
cmp    $0x6b,%eax
jne    1221 <main+0xd1>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,%r15d
jmp    1221 <main+0xd1>

LLVM IR (-O0):
%struct.sembuf = type { i32, i32, i64 }
@.str = [6 x i8] c"k:-n:\00"
@EOF = global i8 0
@optarg = global i32 0
@IPC_CREAT = global i32 0
@IPC_NOWAIT = global i32 0
@.str.1 = [20 x i8] c"semop: returned %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sembuf
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
store i32 34952, i32* %8
br label %12
12: ; preds = %29, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call signext i8 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8 %15, i8* %6
%16 = sext i8 %15 to i32
%17 = load i8, i8* @EOF
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %16, %18
br i1 %19, label %20, label %30
20: ; preds = %12
%21 = load i8, i8* %6
%22 = sext i8 %21 to i32
switch i32 %22, label %29 [
i32 107, label %23
i32 110, label %26
]
23: ; preds = %20
%24 = load i32, i32* @optarg
%25 = call i32 @atoi(i32 %24)
store i32 %25, i32* %8
br label %29
26: ; preds = %20
%27 = load i32, i32* @optarg
%28 = call i32 @atoi(i32 %27)
store i32 %28, i32* %7
br label %29
29: ; preds = %20, %26, %23
br label %12
30: ; preds = %12
%31 = load i32, i32* %8
%32 = load i32, i32* %7
%33 = load i32, i32* @IPC_CREAT
%34 = or i32 %33, 511
%35 = call i32 @semget(i32 %31, i32 %32, i32 %34)
store i32 %35, i32* %9
%36 = load i32, i32* %9
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %39
38: ; preds = %30
store i32 1, i32* %3
br label %49
39: ; preds = %30
%40 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %11, i32 0, i32 2
store i64 0, i64* %40
%41 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %11, i32 0, i32 0
store i32 1, i32* %41
%42 = load i32, i32* @IPC_NOWAIT
%43 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %11, i32 0, i32 1
store i32 %42, i32* %43
%44 = load i32, i32* %9
%45 = call i32 @semop(i32 %44, %struct.sembuf* %11, i32 1)
store i32 %45, i32* %10
%46 = load i32, i32* %10
%47 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %10
store i32 %48, i32* %3
br label %49
49: ; preds = %39, %38
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i32, i64 }
@.str = [6 x i8] c"k:-n:\00"
@EOF = global i8 0
@optarg = global i32 0
@IPC_CREAT = global i32 0
@IPC_NOWAIT = global i32 0
@.str.1 = [20 x i8] c"semop: returned %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.sembuf
%4 = bitcast %struct.sembuf* %3 to i8*
%5 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = load i8, i8* @EOF
%7 = icmp eq i8 %5, %6
br i1 %7, label %25, label %8
8: ; preds = %2, %19
%9 = phi i8 [ %22, %19 ], [ %5, %2 ]
%10 = phi i32 [ %21, %19 ], [ 1, %2 ]
%11 = phi i32 [ %20, %19 ], [ 34952, %2 ]
%12 = sext i8 %9 to i32
switch i32 %12, label %19 [
i32 107, label %13
i32 110, label %16
]
13: ; preds = %8
%14 = load i32, i32* @optarg
%15 = tail call i32 @atoi(i32 %14)
br label %19
16: ; preds = %8
%17 = load i32, i32* @optarg
%18 = tail call i32 @atoi(i32 %17)
br label %19
19: ; preds = %8, %16, %13
%20 = phi i32 [ %11, %8 ], [ %11, %16 ], [ %15, %13 ]
%21 = phi i32 [ %10, %8 ], [ %18, %16 ], [ %10, %13 ]
%22 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%23 = load i8, i8* @EOF
%24 = icmp eq i8 %22, %23
br i1 %24, label %25, label %8
25: ; preds = %19, %2
%26 = phi i32 [ 34952, %2 ], [ %20, %19 ]
%27 = phi i32 [ 1, %2 ], [ %21, %19 ]
%28 = load i32, i32* @IPC_CREAT
%29 = or i32 %28, 511
%30 = tail call i32 @semget(i32 %26, i32 %27, i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %39, label %32
32: ; preds = %25
%33 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i64 0, i32 2
store i64 0, i64* %33
%34 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i64 0, i32 0
store i32 1, i32* %34
%35 = load i32, i32* @IPC_NOWAIT
%36 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i64 0, i32 1
store i32 %35, i32* %36
%37 = call i32 @semop(i32 %30, %struct.sembuf* %3, i32 1)
%38 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %25, %32
%40 = phi i32 [ %37, %32 ], [ 1, %25 ]
ret i32 %40
}