#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 */
int IPC_CREAT;
int /*<<< orphan*/ IPC_NOWAIT;
int atoi(int /*<<< orphan*/);
int 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) {
  int ch;
  int num = 1;
  int key = 0x8888;
  int id;
  int error;
  struct sembuf buf;
  while ((ch = getopt(argc, argv, "k:-n:")) != -1) {
    switch ((char)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    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11e5 <main+0x95>
movsbl -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x6b,%eax
je     11b9 <main+0x69>
jmp    11a8 <main+0x58>
mov    -0x3c(%rbp),%eax
sub    $0x6e,%eax
je     11cf <main+0x7f>
jmp    11e0 <main+0x90>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    11e0 <main+0x90>
mov    0x2e22(%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    0x2dde(%rip),%rax
mov    (%rax),%edx
or     $0x1ff,%edx
call   1030 <semget@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1218 <main+0xc8>
movl   $0x1,-0x4(%rbp)
jmp    125c <main+0x10c>
movq   $0x0,-0x30(%rbp)
movl   $0x1,-0x38(%rbp)
mov    0x2dba(%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    0xdb5(%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    $0x8888,%r15d
mov    $0x1,%r12d
cmp    $0xffffffff,%eax
je     11c6 <main+0x76>
mov    0x2e71(%rip),%r14
lea    0xe72(%rip),%r13
jmp    11ad <main+0x5d>
mov    (%r14),%edi
call   1060 <atoi@plt>
mov    %eax,%r12d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1050 <getopt@plt>
cmp    $0xffffffff,%eax
je     11c6 <main+0x76>
cmp    $0x6e,%al
je     1190 <main+0x40>
movsbl %al,%eax
cmp    $0x6b,%eax
jne    119b <main+0x4b>
mov    (%r14),%edi
call   1060 <atoi@plt>
mov    %eax,%r15d
jmp    119b <main+0x4b>
mov    0x2e03(%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     1228 <main+0xd8>
movq   $0x0,0x10(%rsp)
movl   $0x1,0x8(%rsp)
mov    0x2de7(%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    0xde5(%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

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

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