#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_PRIVATE;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int shmget(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ system(char *);
int main(void) {
  int shm_id;
  shm_id = shmget(IPC_PRIVATE, 4096, 0666);
  if (shm_id < 0) {
    perror("shmget");
    exit(1);
  }
  printf("successfully created segment : %d \n", shm_id);
  system("ipcs -m");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    $0x1000,%esi
mov    $0x1b6,%edx
call   1060 <shmget@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    119a <main+0x4a>
lea    0xe75(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%esi
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
lea    0xe7b(%rip),%rdi
call   1030 <system@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
mov    $0x1000,%esi
mov    $0x1b6,%edx
call   1060 <shmget@plt>
test   %eax,%eax
jns    1183 <main+0x33>
lea    0xe8c(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe7d(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0xe93(%rip),%rdi
call   1030 <system@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@IPC_PRIVATE = global i32 0
@.str = [7 x i8] c"shmget\00"
@.str.1 = [36 x i8] c"successfully created segment : %d \0A\00"
@.str.2 = [8 x i8] c"ipcs -m\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @IPC_PRIVATE
%4 = call i32 @shmget(i32 %3, i32 4096, i32 438)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i32, i32* %2
%12 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@IPC_PRIVATE = global i32 0
@.str = [7 x i8] c"shmget\00"
@.str.1 = [36 x i8] c"successfully created segment : %d \0A\00"
@.str.2 = [8 x i8] c"ipcs -m\00"
define i32 @main() {
%1 = load i32, i32* @IPC_PRIVATE
%2 = tail call i32 @shmget(i32 %1, i32 4096, i32 438)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%9 = tail call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @exit(i32 0)
unreachable
}