#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 IPC_CREAT;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmget(int, int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void createIntSharedMemory(int *shared_mem_id, int shared_mem_key,
                           int **shared_mem_address) {
  if ((*shared_mem_id =
           shmget(shared_mem_key, sizeof(int), IPC_CREAT | 0666)) == -1) {
    fprintf(stderr,
            "Impossivel criar o segmento de memoria compartilhada. Erro: %s\n",
            strerror(errno));
    exit(1);
  }
  if ((*shared_mem_address = (int *)shmat(*shared_mem_id, NULL, 0)) ==
      (int *)-1) {
    fprintf(
        stderr,
        "Impossivel associar o segmento de memoria compartilhada! Erro: %s\n",
        strerror(errno));
    exit(1);
  }
  **shared_mem_address = 0;
}


x86 assembly (clang, -O0):
<createIntSharedMemory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x4,%esi
call   1050 <shmget@plt>
mov    -0x8(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0xffffffff,%eax
jne    11c4 <createIntSharedMemory+0x74>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe4b(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <shmat@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    1222 <createIntSharedMemory+0xd2>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe2d(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movl   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createIntSharedMemory>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
mov    0x2e6f(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    %esi,%edi
mov    $0x4,%esi
call   1050 <shmget@plt>
mov    %eax,(%rbx)
cmp    $0xffffffff,%eax
je     119d <createIntSharedMemory+0x4d>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <shmat@plt>
mov    %rax,(%r14)
cmp    $0xffffffffffffffff,%rax
je     11bd <createIntSharedMemory+0x6d>
movl   $0x0,(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e3c(%rip),%rax
mov    (%rax),%ebx
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe45(%rip),%rsi
jmp    11db <createIntSharedMemory+0x8b>
mov    0x2e1c(%rip),%rax
mov    (%rax),%ebx
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe65(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@stderr = global i32 0
@.str = [64 x i8] c"Impossivel criar o segmento de memoria compartilhada. Erro: %s\0A\00"
@errno = global i32 0
@.str.1 = [67 x i8] c"Impossivel associar o segmento de memoria compartilhada! Erro: %s\0A\00"
define void @createIntSharedMemory(i32* %0, i32 %1, i32** %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32**
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32** %2, i32*** %6
%7 = load i32, i32* %5
%8 = load i32, i32* @IPC_CREAT
%9 = or i32 %8, 438
%10 = call i32 @shmget(i32 %7, i32 4, i32 %9)
%11 = load i32*, i32** %4
store i32 %10, i32* %11
%12 = icmp eq i32 %10, -1
br i1 %12, label %13, label %19
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %3
%20 = load i32*, i32** %4
%21 = load i32, i32* %20
%22 = call i64 @shmat(i32 %21, i32* null, i32 0)
%23 = inttoptr i64 %22 to i32*
%24 = load i32**, i32*** %6
store i32* %23, i32** %24
%25 = icmp eq i32* %23, inttoptr (i64 -1 to i32*)
br i1 %25, label %26, label %32
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %19
%33 = load i32**, i32*** %6
%34 = load i32*, i32** %33
store i32 0, i32* %34
ret void
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@stderr = global i32 0
@.str = [64 x i8] c"Impossivel criar o segmento de memoria compartilhada. Erro: %s\0A\00"
@errno = global i32 0
@.str.1 = [67 x i8] c"Impossivel associar o segmento de memoria compartilhada! Erro: %s\0A\00"
define void @createIntSharedMemory(i32* nocapture writeonly %0, i32 %1, i32** nocapture writeonly %2) {
%4 = load i32, i32* @IPC_CREAT
%5 = or i32 %4, 438
%6 = tail call i32 @shmget(i32 %1, i32 4, i32 %5)
store i32 %6, i32* %0
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %14
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %3
%15 = tail call i64 @shmat(i32 %6, i32* null, i32 0)
%16 = inttoptr i64 %15 to i32*
store i32* %16, i32** %2
%17 = icmp eq i32* %16, inttoptr (i64 -1 to i32*)
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = tail call i8* @strerror(i32 %20)
%22 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %14
store i32 0, i32* %16
ret void
}