#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 */
#define EACCES 131
#define EFAULT 130
#define EINVAL 129
#define EPERM 128
int /*<<< orphan*/ IPC_RMID;
int errno;
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int dest(int shmid) {
  if (shmctl(shmid, IPC_RMID, 0) < 0) {
    switch (errno) {
    case EACCES:
      printf("Permission issues!\n");
      break;
    case EFAULT:
      printf("False parameter to shmctl! This is no common error!\n");
      break;
    case EINVAL:
      printf("Shmid %d is not valid!\n", shmid);
      break;
    case EPERM:
      printf("Permission issues!\n");
      break;
    }
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<dest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <shmctl@plt>
cmp    $0x0,%rax
jge    11cd <dest+0xad>
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     11c1 <dest+0xa1>
mov    -0x10(%rbp),%rax
lea    0xe92(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c1 <dest+0xa1>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c1 <dest+0xa1>
mov    -0x8(%rbp),%esi
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c1 <dest+0xa1>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d4 <dest+0xb4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dest>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edx,%edx
call   1050 <shmctl@plt>
test   %rax,%rax
jns    1199 <dest+0x69>
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
mov    $0xffffffff,%ebx
add    $0xffffff80,%eax
cmp    $0x3,%eax
ja     1199 <dest+0x69>
lea    0xe97(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xee3(%rip),%rdi
jmp    1194 <dest+0x64>
lea    0xe8e(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1199 <dest+0x69>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@IPC_RMID = global i32 0
@errno = global i32 0
@.str = [20 x i8] c"Permission issues!\0A\00"
@.str.1 = [53 x i8] c"False parameter to shmctl! This is no common error!\0A\00"
@.str.2 = [24 x i8] c"Shmid %d is not valid!\0A\00"
define i32 @dest(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = load i32, i32* @IPC_RMID
%6 = call i64 @shmctl(i32 %4, i32 %5, i32 0)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %1
%9 = load i32, i32* @errno
switch i32 %9, label %19 [
i32 131, label %10
i32 130, label %12
i32 129, label %14
i32 128, label %17
]
10: ; preds = %8
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %19
12: ; preds = %8
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
br label %19
14: ; preds = %8
%15 = load i32, i32* %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %19
17: ; preds = %8
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %8, %17, %14, %12, %10
store i32 -1, i32* %2
br label %21
20: ; preds = %1
store i32 0, i32* %2
br label %21
21: ; preds = %20, %19
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@IPC_RMID = global i32 0
@errno = global i32 0
@.str.2 = [24 x i8] c"Shmid %d is not valid!\0A\00"
@str.3 = [52 x i8] c"False parameter to shmctl! This is no common error!\00"
@str.4 = [19 x i8] c"Permission issues!\00"
define i32 @dest(i32 %0) {
%2 = load i32, i32* @IPC_RMID
%3 = tail call i64 @shmctl(i32 %0, i32 %2, i32 0)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %15
5: ; preds = %1
%6 = load i32, i32* @errno
switch i32 %6, label %15 [
i32 131, label %7
i32 130, label %9
i32 129, label %11
i32 128, label %13
]
7: ; preds = %5
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.4, i64 0, i64 0))
br label %15
9: ; preds = %5
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.3, i64 0, i64 0))
br label %15
11: ; preds = %5
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %15
13: ; preds = %5
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.4, i64 0, i64 0))
br label %15
15: ; preds = %1, %7, %9, %11, %13, %5
%16 = phi i32 [ -1, %5 ], [ -1, %13 ], [ -1, %11 ], [ -1, %9 ], [ -1, %7 ], [ 0, %1 ]
ret i32 %16
}