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

/* Variables and functions */
int IPC_CREAT;
int /*<<< orphan*/ exit(int);
scalar_t__ ftok(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int shmget(scalar_t__, int, int);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("error args!\n");
    exit(0);
  }
  key_t skey = ftok(argv[1], 1);
  if (skey < 0) {
    perror("ftok");
    exit(-1);
  }
  printf("skey: %#x\n", skey);
  int shmid = shmget(skey, 1 << 12, IPC_CREAT | 0600);
  if (shmid < 0) {
    perror("shmget");
    exit(-1);
  }
  printf("shmid: %d\n", shmid);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1185 <main+0x35>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x1,%esi
call   1070 <ftok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11bc <main+0x6c>
lea    0xe60(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rsi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
or     $0x180,%edx
mov    $0x1000,%esi
call   1050 <shmget@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    120e <main+0xbe>
lea    0xe1e(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x1c(%rbp),%esi
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    11c0 <main+0x60>
mov    0x8(%rsi),%rdi
mov    $0x1,%esi
call   1080 <ftok@plt>
test   %rax,%rax
js     11d3 <main+0x73>
mov    %rax,%rbx
lea    0xe82(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e4c(%rip),%rax
mov    $0x180,%edx
or     (%rax),%edx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1060 <shmget@plt>
test   %eax,%eax
js     11dc <main+0x7c>
lea    0xe64(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>
lea    0xe26(%rip),%rdi
jmp    11e3 <main+0x83>
lea    0xe2d(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"error args!\0A\00"
@.str.1 = [5 x i8] c"ftok\00"
@.str.2 = [11 x i8] c"skey: %#x\0A\00"
@IPC_CREAT = global i32 0
@.str.3 = [7 x i8] c"shmget\00"
@.str.4 = [11 x i8] c"shmid: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @ftok(i8* %16, i32 1)
store i64 %17, i64* %6
%18 = load i64, i64* %6
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %13
%24 = load i64, i64* %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %24)
%26 = load i64, i64* %6
%27 = load i32, i32* @IPC_CREAT
%28 = or i32 %27, 384
%29 = call i32 @shmget(i64 %26, i32 4096, i32 %28)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %23
%33 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %23
%36 = load i32, i32* %7
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %36)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"ftok\00"
@.str.2 = [11 x i8] c"skey: %#x\0A\00"
@IPC_CREAT = global i32 0
@.str.3 = [7 x i8] c"shmget\00"
@.str.4 = [11 x i8] c"shmid: %d\0A\00"
@str = [12 x i8] c"error args!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @ftok(i8* %9, i32 1)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %7
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %10)
%17 = load i32, i32* @IPC_CREAT
%18 = or i32 %17, 384
%19 = tail call i32 @shmget(i64 %10, i32 4096, i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%23 = tail call i32 @exit(i32 -1)
unreachable
24: ; preds = %15
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %19)
ret i32 0
}