#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 IPC_CREAT;
int IPC_EXCL;
int SHM_R;
int SHM_W;
int ftok(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int);
int shmget(int, size_t, int);
int creerSegment(size_t size, char *file, int key) {
  key_t key_sh;
  int sh = 0;
  if ((key_sh = ftok(file, key)) == -1) {
    perror("ftok");
    return -1;
  }
  if ((sh = shmget(key_sh, size, IPC_CREAT | IPC_EXCL | SHM_R | SHM_W)) == -1) {
    perror("shmget");
    return -1;
  }
  printf("ID : %d\nKEY : %d\n", sh, key);
  return sh;
}


x86 assembly (clang, -O0):
<creerSegment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <ftok@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    118a <creerSegment+0x4a>
lea    0xe87(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <creerSegment+0xb6>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
mov    0x2e4f(%rip),%rax
or     (%rax),%edx
mov    0x2e36(%rip),%rax
or     (%rax),%edx
mov    0x2e15(%rip),%rax
or     (%rax),%edx
call   1050 <shmget@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    11de <creerSegment+0x9e>
lea    0xe38(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <creerSegment+0xb6>
mov    -0x24(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe21(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<creerSegment>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %edx,%esi
call   1060 <ftok@plt>
cmp    $0xffffffff,%eax
je     11a4 <creerSegment+0x64>
mov    0x2e71(%rip),%rcx
mov    0x2e8a(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2e6f(%rip),%rcx
or     (%rcx),%edx
mov    0x2e4e(%rip),%rcx
or     (%rcx),%edx
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <shmget@plt>
cmp    $0xffffffff,%eax
je     11ad <creerSegment+0x6d>
mov    %eax,%ebp
lea    0xe78(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe55(%rip),%rdi
jmp    11b4 <creerSegment+0x74>
lea    0xe51(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%ebp
jmp    119d <creerSegment+0x5d>

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

LLVM IR (-O2):
@.str = [5 x i8] c"ftok\00"
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@SHM_R = global i32 0
@SHM_W = global i32 0
@.str.1 = [7 x i8] c"shmget\00"
@.str.2 = [18 x i8] c"ID : %d\0AKEY : %d\0A\00"
define i32 @creerSegment(i64 %0, i8* %1, i32 %2) {
%4 = tail call i32 @ftok(i8* %1, i32 %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %22
8: ; preds = %3
%9 = load i32, i32* @IPC_CREAT
%10 = load i32, i32* @IPC_EXCL
%11 = or i32 %10, %9
%12 = load i32, i32* @SHM_R
%13 = or i32 %11, %12
%14 = load i32, i32* @SHM_W
%15 = or i32 %13, %14
%16 = tail call i32 @shmget(i32 %4, i64 %0, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %8
%19 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %22
20: ; preds = %8
%21 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 %2)
br label %22
22: ; preds = %20, %18, %6
%23 = phi i32 [ -1, %6 ], [ -1, %18 ], [ %16, %20 ]
ret i32 %23
}