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

/* Variables and functions */
int /*<<< orphan*/ IPC_CREAT;
int /*<<< orphan*/ IPC_PRIVATE;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ perror(char *);
scalar_t__ shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int shmget(int /*<<< orphan*/, int, int /*<<< orphan*/);
int _shm(char const *progname) {
  key_t id;
  if ((id = shmget(IPC_PRIVATE, 4096, IPC_CREAT)) == -1) {
    perror("shmget");
    return 2;
  }
  if (shmctl(id, IPC_RMID, NULL) != 0) {
    perror("shmctl");
    return 2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<_shm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%edi
mov    0x2e84(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   1050 <shmget@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    117c <_shm+0x4c>
lea    0xe95(%rip),%rdi
call   1040 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    11ba <_shm+0x8a>
mov    -0x14(%rbp),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <shmctl@plt>
cmp    $0x0,%rax
je     11b3 <_shm+0x83>
lea    0xe65(%rip),%rdi
call   1040 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    11ba <_shm+0x8a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_shm>:
push   %rbx
mov    0x2eb0(%rip),%rax
mov    (%rax),%edi
mov    0x2e8f(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   1050 <shmget@plt>
cmp    $0xffffffff,%eax
je     116f <_shm+0x3f>
mov    0x2e7f(%rip),%rcx
mov    (%rcx),%esi
xor    %ebx,%ebx
mov    %eax,%edi
xor    %edx,%edx
call   1030 <shmctl@plt>
test   %rax,%rax
jne    1178 <_shm+0x48>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe8a(%rip),%rdi
jmp    117f <_shm+0x4f>
lea    0xe88(%rip),%rdi
call   1040 <perror@plt>
mov    $0x2,%ebx
jmp    116b <_shm+0x3b>

LLVM IR (-O0):
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@.str = [7 x i8] c"shmget\00"
@IPC_RMID = global i32 0
@.str.1 = [7 x i8] c"shmctl\00"
define i32 @_shm(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i32, i32* @IPC_PRIVATE
%6 = load i32, i32* @IPC_CREAT
%7 = call i32 @shmget(i32 %5, i32 4096, i32 %6)
store i32 %7, i32* %4
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %2
br label %19
11: ; preds = %1
%12 = load i32, i32* %4
%13 = load i32, i32* @IPC_RMID
%14 = call i64 @shmctl(i32 %12, i32 %13, i32* null)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %2
br label %19
18: ; preds = %11
store i32 0, i32* %2
br label %19
19: ; preds = %18, %16, %9
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@.str = [7 x i8] c"shmget\00"
@IPC_RMID = global i32 0
@.str.1 = [7 x i8] c"shmctl\00"
define i32 @_shm(i8* nocapture readnone %0) {
%2 = load i32, i32* @IPC_PRIVATE
%3 = load i32, i32* @IPC_CREAT
%4 = tail call i32 @shmget(i32 %2, i32 4096, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = load i32, i32* @IPC_RMID
%8 = tail call i64 @shmctl(i32 %4, i32 %7, i32* null)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %6, %1
%11 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %6 ]
%12 = tail call i32 @perror(i8* %11)
br label %13
13: ; preds = %10, %6
%14 = phi i32 [ 0, %6 ], [ 2, %10 ]
ret i32 %14
}