#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*/ IPC_RMID;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
scalar_t__ shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int remove_shmid(int shmid) {
  if (shmid >= 0) {
    if (shmctl(shmid, IPC_RMID, NULL) != 0) {
      fprintf(stderr,
              "ERR: "
              "shmctl(%x, IPC_RMID) failed (%s)\n",
              shmid, strerror(errno));
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<remove_shmid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11aa <remove_shmid+0x7a>
mov    -0x8(%rbp),%edi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <shmctl@plt>
cmp    $0x0,%rax
je     11a5 <remove_shmid+0x75>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%edx
mov    %rax,%rcx
lea    0xe6c(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <remove_shmid+0x81>
jmp    11aa <remove_shmid+0x7a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_shmid>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
js     1181 <remove_shmid+0x51>
mov    %edi,%ebp
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edx,%edx
call   1040 <shmctl@plt>
test   %rax,%rax
je     1183 <remove_shmid+0x53>
mov    0x2e89(%rip),%rax
mov    (%rax),%ebx
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe92(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1183 <remove_shmid+0x53>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@IPC_RMID = global i32 0
@stderr = global i32 0
@.str = [39 x i8] c"ERR: shmctl(%x, IPC_RMID) failed (%s)\0A\00"
@errno = global i32 0
define i32 @remove_shmid(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp sge i32 %4, 0
br i1 %5, label %6, label %18
6: ; preds = %1
%7 = load i32, i32* %3
%8 = load i32, i32* @IPC_RMID
%9 = call i64 @shmctl(i32 %7, i32 %8, i32* null)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %6
%12 = load i32, i32* @stderr
%13 = load i32, i32* %3
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %13, i8* %15)
store i32 -1, i32* %2
br label %19
17: ; preds = %6
br label %18
18: ; preds = %17, %1
store i32 0, i32* %2
br label %19
19: ; preds = %18, %11
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@IPC_RMID = global i32 0
@stderr = global i32 0
@.str = [39 x i8] c"ERR: shmctl(%x, IPC_RMID) failed (%s)\0A\00"
@errno = global i32 0
define i32 @remove_shmid(i32 %0) {
%2 = icmp sgt i32 %0, -1
br i1 %2, label %3, label %12
3: ; preds = %1
%4 = load i32, i32* @IPC_RMID
%5 = tail call i64 @shmctl(i32 %0, i32 %4, i32* null)
%6 = icmp eq i64 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %10)
br label %12
12: ; preds = %1, %3, %7
%13 = phi i32 [ -1, %7 ], [ 0, %3 ], [ 0, %1 ]
ret i32 %13
}