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

/* Variables and functions */
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int semctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int main(int argc, char *argv[]) {
  key_t key;
  int semid;
  int id;
  int tt;
  sscanf(argv[1], "%d", &tt);
  sscanf(argv[2], "%d", &id);
  if (tt == 0) {
    if (semctl(id, 0, IPC_RMID) == -1) {
      perror("semctl");
      exit(1);
    }
  } else {
    if (shmctl(id, 0, IPC_RMID) == -1) {
      perror("semctl");
      exit(1);
    }
  }
  return 0;
}


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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8b(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1030 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe73(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <sscanf@plt>
cmpl   $0x0,-0x20(%rbp)
jne    11d7 <main+0x87>
mov    -0x1c(%rbp),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <semctl@plt>
cmp    $0xffffffff,%eax
jne    11d2 <main+0x82>
lea    0xe40(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    120e <main+0xbe>
mov    -0x1c(%rbp),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <shmctl@plt>
cmp    $0xffffffff,%eax
jne    1209 <main+0xb9>
lea    0xe09(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    120e <main+0xbe>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe9e(%rip),%r14
mov    %rsp,%rdx
mov    %r14,%rsi
call   1030 <sscanf@plt>
mov    0x10(%rbx),%rdi
lea    0x4(%rsp),%rdx
mov    %r14,%rsi
call   1030 <sscanf@plt>
cmpl   $0x0,(%rsp)
mov    0x4(%rsp),%edi
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
je     11a7 <main+0x57>
xor    %esi,%esi
call   1040 <shmctl@plt>
cmp    $0xffffffff,%eax
je     11b3 <main+0x63>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %esi,%esi
call   1060 <semctl@plt>
cmp    $0xffffffff,%eax
jne    119d <main+0x4d>
lea    0xe49(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@IPC_RMID = global i32 0
@.str.1 = [7 x i8] c"semctl\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %9)
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%18 = load i32, i32* %9
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %2
%21 = load i32, i32* %8
%22 = load i32, i32* @IPC_RMID
%23 = call i32 @semctl(i32 %21, i32 0, i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %20
br label %38
29: ; preds = %2
%30 = load i32, i32* %8
%31 = load i32, i32* @IPC_RMID
%32 = call i32 @shmctl(i32 %30, i32 0, i32 %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %29
br label %38
38: ; preds = %37, %28
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@IPC_RMID = global i32 0
@.str.1 = [7 x i8] c"semctl\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 0
%15 = load i32, i32* %3
%16 = load i32, i32* @IPC_RMID
br i1 %14, label %17, label %23
17: ; preds = %2
%18 = call i32 @semctl(i32 %15, i32 0, i32 %16)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %29
20: ; preds = %17
%21 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = call i32 @shmctl(i32 %15, i32 0, i32 %16)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %23, %17
ret i32 0
}