#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 EINVAL;
int /*<<< orphan*/ IPC_RMID;
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int delete_shm(int shmid) {
  int r;
  if (shmid == -1) {
    fprintf(stderr, "delete_shm(%d)::shmctl: invalid id: %s\n", shmid,
            strerror(-EINVAL));
    return -EINVAL;
  }
  r = shmctl(shmid, IPC_RMID, NULL);
  if (r)
    fprintf(stderr, "delete_shm(%d)::shmctl: %s\n", shmid, strerror(errno));
  return r;
}


x86 assembly (clang, -O0):
<delete_shm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    118f <delete_shm+0x5f>
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
xor    %edi,%edi
mov    0x2e68(%rip),%rax
sub    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%edx
mov    %rax,%rcx
lea    0xe89(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
mov    0x2e43(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11ec <delete_shm+0xbc>
mov    -0x8(%rbp),%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <shmctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11e6 <delete_shm+0xb6>
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%edx
mov    %rax,%rcx
lea    0xe47(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delete_shm>:
push   %rbp
push   %r14
push   %rbx
cmp    $0xffffffff,%edi
je     1183 <delete_shm+0x53>
mov    %edi,%ebp
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edx,%edx
call   1040 <shmctl@plt>
test   %eax,%eax
je     11b8 <delete_shm+0x88>
mov    %eax,%r14d
mov    0x2e85(%rip),%rax
mov    (%rax),%ebx
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xeb6(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    %r14d,%ebx
jmp    11b8 <delete_shm+0x88>
mov    0x2e56(%rip),%rax
mov    (%rax),%ebp
mov    0x2e35(%rip),%r14
xor    %ebx,%ebx
xor    %edi,%edi
sub    (%r14),%edi
call   1050 <strerror@plt>
lea    0xe5a(%rip),%rsi
mov    %ebp,%edi
mov    $0xffffffff,%edx
mov    %rax,%rcx
call   1030 <fprintf@plt>
sub    (%r14),%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"delete_shm(%d)::shmctl: invalid id: %s\0A\00"
@EINVAL = global i32 0
@IPC_RMID = global i32 0
@.str.1 = [28 x i8] c"delete_shm(%d)::shmctl: %s\0A\00"
@errno = global i32 0
define i32 @delete_shm(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %16
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i32, i32* %3
%10 = load i32, i32* @EINVAL
%11 = sub nsw i32 0, %10
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %9, i8* %12)
%14 = load i32, i32* @EINVAL
%15 = sub nsw i32 0, %14
store i32 %15, i32* %2
br label %30
16: ; preds = %1
%17 = load i32, i32* %3
%18 = load i32, i32* @IPC_RMID
%19 = call i32 @shmctl(i32 %17, i32 %18, i32* null)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = load i32, i32* %3
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %24, i8* %26)
br label %28
28: ; preds = %22, %16
%29 = load i32, i32* %4
store i32 %29, i32* %2
br label %30
30: ; preds = %28, %7
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"delete_shm(%d)::shmctl: invalid id: %s\0A\00"
@EINVAL = global i32 0
@IPC_RMID = global i32 0
@.str.1 = [28 x i8] c"delete_shm(%d)::shmctl: %s\0A\00"
@errno = global i32 0
define i32 @delete_shm(i32 %0) {
%2 = icmp eq i32 %0, -1
br i1 %2, label %3, label %11
3: ; preds = %1
%4 = load i32, i32* @stderr
%5 = load i32, i32* @EINVAL
%6 = sub nsw i32 0, %5
%7 = tail call i8* @strerror(i32 %6)
%8 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 -1, i8* %7)
%9 = load i32, i32* @EINVAL
%10 = sub nsw i32 0, %9
br label %20
11: ; preds = %1
%12 = load i32, i32* @IPC_RMID
%13 = tail call i32 @shmctl(i32 %0, i32 %12, i32* null)
%14 = icmp eq i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %0, i8* %18)
br label %20
20: ; preds = %11, %15, %3
%21 = phi i32 [ %10, %3 ], [ %13, %15 ], [ 0, %11 ]
ret i32 %21
}