#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int IPC_CREAT;
int IPC_EXCL;
int /*<<< orphan*/ IPC_PRIVATE;
long LONG_MAX;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fatal(char *);
int /*<<< orphan*/ helpAndExit(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pexit(char *);
int /*<<< orphan*/ printf(char *, int);
int shmget(int /*<<< orphan*/, size_t, int);
long strtol(char *, char **, int);
int main(int argc, char *argv[]) {
  int shmid;
  long size;
  char *endptr;
  if (argc != 2)
    helpAndExit(argv[0], EXIT_FAILURE);
  size = strtol(argv[1], &endptr, 10);
  if (size <= 0 || size == LONG_MAX || *endptr != '\0')
    fatal("Invalid size argument.");
  shmid = shmget(IPC_PRIVATE, (size_t)size,
                 IPC_CREAT | IPC_EXCL | (S_IRUSR | S_IWUSR));
  if (shmid == -1)
    pexit("shmget");
  printf("%d\n", shmid);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a5 <main+0x35>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
call   1050 <helpAndExit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jle    11ee <main+0x7e>
mov    -0x20(%rbp),%rax
mov    0x2df3(%rip),%rcx
cmp    (%rcx),%rax
je     11ee <main+0x7e>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11fa <main+0x8a>
lea    0xe0b(%rip),%rdi
call   1090 <fatal@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
mov    0x2d9a(%rip),%rax
mov    (%rax),%edx
mov    0x2dd9(%rip),%rax
or     (%rax),%edx
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    0x2daf(%rip),%rcx
or     (%rcx),%eax
or     %eax,%edx
call   1060 <shmget@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    124b <main+0xdb>
lea    0xdd1(%rip),%rdi
call   1080 <pexit@plt>
mov    -0x14(%rbp),%esi
lea    0xdc9(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     118e <main+0x1e>
mov    (%rbx),%rdi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
call   1050 <helpAndExit@plt>
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rbx
test   %rax,%rax
jle    11bf <main+0x4f>
mov    0x2e18(%rip),%rax
cmp    (%rax),%rbx
je     11bf <main+0x4f>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     11cb <main+0x5b>
lea    0xe3a(%rip),%rdi
call   1090 <fatal@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    0x2dcd(%rip),%rax
mov    0x2e0e(%rip),%rcx
mov    (%rcx),%edx
mov    0x2dcd(%rip),%rcx
mov    0x2de6(%rip),%rsi
or     (%rax),%edx
or     (%rcx),%edx
or     (%rsi),%edx
mov    %rbx,%rsi
call   1060 <shmget@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1213 <main+0xa3>
lea    0xe09(%rip),%rdi
call   1080 <pexit@plt>
lea    0xe04(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@LONG_MAX = global i64 0
@.str = [23 x i8] c"Invalid size argument.\00"
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [7 x i8] c"shmget\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @helpAndExit(i8* %14, i32 %15)
br label %17
17: ; preds = %11, %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @strtol(i8* %20, i8** %8, i32 10)
store i64 %21, i64* %7
%22 = load i64, i64* %7
%23 = icmp sle i64 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %17
%25 = load i64, i64* %7
%26 = load i64, i64* @LONG_MAX
%27 = icmp eq i64 %25, %26
br i1 %27, label %33, label %28
28: ; preds = %24
%29 = load i8*, i8** %8
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28, %24, %17
%34 = call i32 @fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %33, %28
%36 = load i32, i32* @IPC_PRIVATE
%37 = load i64, i64* %7
%38 = load i32, i32* @IPC_CREAT
%39 = load i32, i32* @IPC_EXCL
%40 = or i32 %38, %39
%41 = load i32, i32* @S_IRUSR
%42 = load i32, i32* @S_IWUSR
%43 = or i32 %41, %42
%44 = or i32 %40, %43
%45 = call i32 @shmget(i32 %36, i64 %37, i32 %44)
store i32 %45, i32* %6
%46 = load i32, i32* %6
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %35
%49 = call i32 @pexit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %50
50: ; preds = %48, %35
%51 = load i32, i32* %6
%52 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %51)
%53 = load i32, i32* @EXIT_SUCCESS
%54 = call i32 @exit(i32 %53)
unreachable
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@LONG_MAX = global i64 0
@.str = [23 x i8] c"Invalid size argument.\00"
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [7 x i8] c"shmget\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @helpAndExit(i8* %7, i32 %8)
br label %10
10: ; preds = %6, %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i64 @strtol(i8* %12, i8** %3, i32 10)
%14 = icmp slt i64 %13, 1
%15 = load i64, i64* @LONG_MAX
%16 = icmp eq i64 %13, %15
%17 = select i1 %14, i1 true, i1 %16
br i1 %17, label %22, label %18
18: ; preds = %10
%19 = load i8*, i8** %3
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %18, %10
%23 = tail call i32 @fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
%25 = load i32, i32* @IPC_PRIVATE
%26 = load i32, i32* @IPC_CREAT
%27 = load i32, i32* @IPC_EXCL
%28 = load i32, i32* @S_IRUSR
%29 = load i32, i32* @S_IWUSR
%30 = or i32 %27, %26
%31 = or i32 %30, %28
%32 = or i32 %31, %29
%33 = tail call i32 @shmget(i32 %25, i64 %13, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %24
%36 = tail call i32 @pexit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %24
%38 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%39 = load i32, i32* @EXIT_SUCCESS
%40 = tail call i32 @exit(i32 %39)
unreachable
}