#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 */
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int S_IROTH;
int S_IRUSR;
int S_IWOTH;
int S_IWUSR;
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ close(int);
int errno;
scalar_t__ execl(char *, char *, char *, char *, char *, char *,
                 int /*<<< orphan*/ *);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int ftruncate(int, int);
scalar_t__ malloc(int);
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ random_gen(char *, int);
int shm_open(char *, int, int);
int shm_unlink(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ unsetenv(char *);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int sc_connect(int socket, const struct sockaddr *address,
               socklen_t address_len) {
  pid_t child_pid;
  char *shared_memory_key = NULL;
  void *shared_memory_ptr = NULL;
  int shared_memory_fd = -1;
  int op_ret = -1;
  int child_ret = -1;
  int func_ret = -1;
  shared_memory_key = (char *)malloc(sizeof(char) * 20);
  random_gen(shared_memory_key, 20);
  shared_memory_fd = shm_open(shared_memory_key, O_CREAT | O_RDWR,
                              S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH);
  if (shared_memory_fd != -1) {
    ;
  } else {
    fprintf(stderr, "creating the shared memory failed\n");
    fprintf(stderr, "the error code is %d\n", errno);
    goto sc_connect_exit;
  }
  op_ret = ftruncate(shared_memory_fd, sizeof(int) * 3);
  if (!op_ret) {
    ;
  } else {
    fprintf(stderr, "the error code is %d\n", errno);
    goto sc_connect_clean;
  }
  shared_memory_ptr = mmap(NULL, sizeof(int) * 3, PROT_WRITE | PROT_READ,
                           MAP_SHARED, shared_memory_fd, 0);
  if (shared_memory_ptr != MAP_FAILED) {
    *((int *)shared_memory_ptr) = socket;
  }
  if (!(child_pid = fork())) {
    unsetenv("LD_PRELOAD");
    if (execl("./sm-proxy.py", "./sm-proxy.py", "-k", shared_memory_key, "-t",
              "1", NULL) < 0) {
      fprintf(stderr, "error\n");
      fprintf(stderr, "error is %d\n", errno);
    }
  } else {
    waitpid(child_pid, &child_ret, 0);
    if (WIFEXITED(child_ret)) {
      func_ret = *(int *)shared_memory_ptr;
    } else {
      errno = 3;
    }
  }
sc_connect_clean:
  op_ret = shm_unlink(shared_memory_key);
  if (!op_ret) {
    close(shared_memory_fd);
  } else {
    fprintf(stderr, "unlinking the shared memory not succeed\n");
    fprintf(stderr, "the error code is %d\n", errno);
    func_ret = op_ret;
  }
sc_connect_exit:
  if (func_ret == -1) {
    errno = 5;
  }
  return func_ret;
}


x86 assembly (clang, -O0):
<sc_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
movl   $0xffffffff,-0x30(%rbp)
movl   $0xffffffff,-0x34(%rbp)
movl   $0xffffffff,-0x38(%rbp)
mov    $0x14,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x14,%esi
call   10c0 <random_gen@plt>
mov    -0x20(%rbp),%rdi
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
mov    0x2d92(%rip),%rax
or     (%rax),%esi
mov    0x2d51(%rip),%rax
mov    (%rax),%edx
mov    0x2d78(%rip),%rax
or     (%rax),%edx
mov    0x2d4f(%rip),%rax
or     (%rax),%edx
mov    0x2d1e(%rip),%rax
or     (%rax),%edx
call   10b0 <shm_open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
je     127b <sc_connect+0xab>
jmp    12b7 <sc_connect+0xe7>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    0xd75(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
mov    0x2d0e(%rip),%rax
mov    (%rax),%edx
lea    0xd78(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    148d <sc_connect+0x2bd>
mov    -0x2c(%rbp),%edi
mov    $0xc,%esi
call   1040 <ftruncate@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jne    12d6 <sc_connect+0x106>
jmp    12fb <sc_connect+0x12b>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
mov    0x2cca(%rip),%rax
mov    (%rax),%edx
lea    0xd34(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1428 <sc_connect+0x258>
mov    0x2c9e(%rip),%rax
mov    (%rax),%edx
mov    0x2ce5(%rip),%rax
or     (%rax),%edx
mov    0x2ccc(%rip),%rax
mov    (%rax),%ecx
mov    -0x2c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0xc,%esi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2c56(%rip),%rcx
cmp    (%rcx),%rax
je     134c <sc_connect+0x17c>
mov    -0x4(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    13e3 <sc_connect+0x213>
lea    0xcd3(%rip),%rdi
call   1090 <unsetenv@plt>
mov    -0x20(%rbp),%rcx
lea    0xcce(%rip),%rsi
lea    0xcd5(%rip),%rdx
lea    0xcd1(%rip),%r8
lea    0xccd(%rip),%r9
xor    %eax,%eax
mov    %rsi,%rdi
movq   $0x0,(%rsp)
call   10d0 <execl@plt>
cmp    $0x0,%rax
jge    13de <sc_connect+0x20e>
mov    0x2c0a(%rip),%rax
mov    (%rax),%edi
lea    0xca3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2bf3(%rip),%rax
mov    (%rax),%edi
mov    0x2be2(%rip),%rax
mov    (%rax),%edx
lea    0xc8a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1423 <sc_connect+0x253>
mov    -0x18(%rbp),%edi
lea    -0x34(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
mov    -0x34(%rbp),%edi
call   10a0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1411 <sc_connect+0x241>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
jmp    141e <sc_connect+0x24e>
mov    0x2b98(%rip),%rax
movl   $0x3,(%rax)
jmp    1423 <sc_connect+0x253>
jmp    1428 <sc_connect+0x258>
mov    -0x20(%rbp),%rdi
call   10e0 <shm_unlink@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jne    144b <sc_connect+0x27b>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
jmp    1488 <sc_connect+0x2b8>
mov    0x2b66(%rip),%rax
mov    (%rax),%edi
lea    0xc13(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2b4f(%rip),%rax
mov    (%rax),%edi
mov    0x2b3e(%rip),%rax
mov    (%rax),%edx
lea    0xba8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    148d <sc_connect+0x2bd>
cmpl   $0xffffffff,-0x38(%rbp)
jne    14a4 <sc_connect+0x2d4>
mov    0x2b12(%rip),%rax
movl   $0x5,(%rax)
mov    -0x38(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sc_connect>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r14d
movl   $0xffffffff,0x14(%rsp)
ff
mov    $0x14,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x14,%esi
call   10c0 <random_gen@plt>
mov    0x2df2(%rip),%rax
mov    0x2dc3(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d80(%rip),%rax
mov    0x2da9(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d7e(%rip),%rax
or     (%rax),%edx
mov    0x2d4d(%rip),%rax
or     (%rax),%edx
mov    %rbx,%rdi
call   10b0 <shm_open@plt>
cmp    $0xffffffff,%eax
je     12cf <sc_connect+0xff>
mov    %eax,%r15d
mov    %eax,%edi
mov    $0xc,%esi
call   1040 <ftruncate@plt>
test   %eax,%eax
je     131e <sc_connect+0x14e>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
mov    0x2d43(%rip),%rax
mov    (%rax),%edx
lea    0xdad(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   10e0 <shm_unlink@plt>
test   %eax,%eax
je     1391 <sc_connect+0x1c1>
mov    %eax,%ebx
mov    0x2d1d(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xdc9(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    0x2cfa(%rip),%rax
mov    (%rax),%edx
lea    0xd64(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%ebp
cmp    $0xffffffff,%ebp
jne    1311 <sc_connect+0x141>
jmp    12ff <sc_connect+0x12f>
mov    0x2ce2(%rip),%rbx
mov    (%rbx),%edi
lea    0xd21(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
mov    0x2cc1(%rip),%rax
mov    (%rax),%edx
lea    0xd2b(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2caa(%rip),%rax
movl   $0x5,(%rax)
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c7b(%rip),%rax
mov    0x2cc4(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2ca9(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0xc,%esi
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbp
mov    0x2c3b(%rip),%rax
cmp    (%rax),%rbp
je     135e <sc_connect+0x18e>
mov    %r14d,0x0(%rbp)
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     13a7 <sc_connect+0x1d7>
lea    0x14(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1080 <waitpid@plt>
mov    0x14(%rsp),%edi
call   10a0 <WIFEXITED@plt>
test   %rax,%rax
je     1427 <sc_connect+0x257>
mov    0x0(%rbp),%ebp
jmp    1282 <sc_connect+0xb2>
mov    %r15d,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%ebp
jne    1311 <sc_connect+0x141>
jmp    12ff <sc_connect+0x12f>
lea    0xc8b(%rip),%rdi
call   1090 <unsetenv@plt>
movq   $0x0,(%rsp)
lea    0xc82(%rip),%rdi
lea    0xc89(%rip),%rdx
lea    0xc85(%rip),%r8
lea    0xc81(%rip),%r9
mov    %rdi,%rsi
mov    %rbx,%rcx
call   10d0 <execl@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jns    1282 <sc_connect+0xb2>
mov    0x2bc1(%rip),%r14
mov    (%r14),%edi
lea    0xc59(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%edi
mov    0x2b9e(%rip),%rax
mov    (%rax),%edx
lea    0xc46(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1282 <sc_connect+0xb2>
mov    0x2b82(%rip),%rax
movl   $0x3,(%rax)
jmp    127d <sc_connect+0xad>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@stderr = global i32 0
@.str = [35 x i8] c"creating the shared memory failed\0A\00"
@.str.1 = [22 x i8] c"the error code is %d\0A\00"
@errno = global i32 0
@PROT_WRITE = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [11 x i8] c"LD_PRELOAD\00"
@.str.3 = [14 x i8] c"./sm-proxy.py\00"
@.str.4 = [3 x i8] c"-k\00"
@.str.5 = [3 x i8] c"-t\00"
@.str.6 = [2 x i8] c"1\00"
@.str.7 = [7 x i8] c"error\0A\00"
@.str.8 = [13 x i8] c"error is %d\0A\00"
@.str.9 = [41 x i8] c"unlinking the shared memory not succeed\0A\00"
define i32 @sc_connect(i32 %0, %struct.sockaddr* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %4
store %struct.sockaddr* %1, %struct.sockaddr** %5
store i32 %2, i32* %6
store i8* null, i8** %8
store i8* null, i8** %9
store i32 -1, i32* %10
store i32 -1, i32* %11
store i32 -1, i32* %12
store i32 -1, i32* %13
%14 = call i64 @malloc(i32 20)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %8
%16 = load i8*, i8** %8
%17 = call i32 @random_gen(i8* %16, i32 20)
%18 = load i8*, i8** %8
%19 = load i32, i32* @O_CREAT
%20 = load i32, i32* @O_RDWR
%21 = or i32 %19, %20
%22 = load i32, i32* @S_IRUSR
%23 = load i32, i32* @S_IWUSR
%24 = or i32 %22, %23
%25 = load i32, i32* @S_IROTH
%26 = or i32 %24, %25
%27 = load i32, i32* @S_IWOTH
%28 = or i32 %26, %27
%29 = call i32 @shm_open(i8* %18, i32 %21, i32 %28)
store i32 %29, i32* %10
%30 = load i32, i32* %10
%31 = icmp ne i32 %30, -1
br i1 %31, label %32, label %33
32: ; preds = %3
br label %39
33: ; preds = %3
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %37)
br label %107
39: ; preds = %32
%40 = load i32, i32* %10
%41 = call i32 @ftruncate(i32 %40, i32 12)
store i32 %41, i32* %11
%42 = load i32, i32* %11
%43 = icmp ne i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %39
br label %49
45: ; preds = %39
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %47)
br label %91
49: ; preds = %44
%50 = load i32, i32* @PROT_WRITE
%51 = load i32, i32* @PROT_READ
%52 = or i32 %50, %51
%53 = load i32, i32* @MAP_SHARED
%54 = load i32, i32* %10
%55 = call i8* @mmap(i32* null, i32 12, i32 %52, i32 %53, i32 %54, i32 0)
store i8* %55, i8** %9
%56 = load i8*, i8** %9
%57 = load i8*, i8** @MAP_FAILED
%58 = icmp ne i8* %56, %57
br i1 %58, label %59, label %63
59: ; preds = %49
%60 = load i32, i32* %4
%61 = load i8*, i8** %9
%62 = bitcast i8* %61 to i32*
store i32 %60, i32* %62
br label %63
63: ; preds = %59, %49
%64 = call i32 (...) @fork()
store i32 %64, i32* %7
%65 = icmp ne i32 %64, 0
br i1 %65, label %78, label %66
66: ; preds = %63
%67 = call i32 @unsetenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%68 = load i8*, i8** %8
%69 = call i64 @execl(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %68, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32* null)
%70 = icmp slt i64 %69, 0
br i1 %70, label %71, label %77
71: ; preds = %66
%72 = load i32, i32* @stderr
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%74 = load i32, i32* @stderr
%75 = load i32, i32* @errno
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 %75)
br label %77
77: ; preds = %71, %66
br label %90
78: ; preds = %63
%79 = load i32, i32* %7
%80 = call i32 @waitpid(i32 %79, i32* %12, i32 0)
%81 = load i32, i32* %12
%82 = call i64 @WIFEXITED(i32 %81)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %88
84: ; preds = %78
%85 = load i8*, i8** %9
%86 = bitcast i8* %85 to i32*
%87 = load i32, i32* %86
store i32 %87, i32* %13
br label %89
88: ; preds = %78
store i32 3, i32* @errno
br label %89
89: ; preds = %88, %84
br label %90
90: ; preds = %89, %77
br label %91
91: ; preds = %90, %45
%92 = load i8*, i8** %8
%93 = call i32 @shm_unlink(i8* %92)
store i32 %93, i32* %11
%94 = load i32, i32* %11
%95 = icmp ne i32 %94, 0
br i1 %95, label %99, label %96
96: ; preds = %91
%97 = load i32, i32* %10
%98 = call i32 @close(i32 %97)
br label %106
99: ; preds = %91
%100 = load i32, i32* @stderr
%101 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0))
%102 = load i32, i32* @stderr
%103 = load i32, i32* @errno
%104 = call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %103)
%105 = load i32, i32* %11
store i32 %105, i32* %13
br label %106
106: ; preds = %99, %96
br label %107
107: ; preds = %106, %33
%108 = load i32, i32* %13
%109 = icmp eq i32 %108, -1
br i1 %109, label %110, label %111
110: ; preds = %107
store i32 5, i32* @errno
br label %111
111: ; preds = %110, %107
%112 = load i32, i32* %13
ret i32 %112
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@stderr = global i32 0
@.str = [35 x i8] c"creating the shared memory failed\0A\00"
@.str.1 = [22 x i8] c"the error code is %d\0A\00"
@errno = global i32 0
@PROT_WRITE = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [11 x i8] c"LD_PRELOAD\00"
@.str.3 = [14 x i8] c"./sm-proxy.py\00"
@.str.4 = [3 x i8] c"-k\00"
@.str.5 = [3 x i8] c"-t\00"
@.str.6 = [2 x i8] c"1\00"
@.str.7 = [7 x i8] c"error\0A\00"
@.str.8 = [13 x i8] c"error is %d\0A\00"
@.str.9 = [41 x i8] c"unlinking the shared memory not succeed\0A\00"
define i32 @sc_connect(i32 %0, %struct.sockaddr* nocapture readnone %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 -1, i32* %4
%6 = tail call i64 @malloc(i32 20)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @random_gen(i8* %7, i32 20)
%9 = load i32, i32* @O_CREAT
%10 = load i32, i32* @O_RDWR
%11 = or i32 %10, %9
%12 = load i32, i32* @S_IRUSR
%13 = load i32, i32* @S_IWUSR
%14 = or i32 %13, %12
%15 = load i32, i32* @S_IROTH
%16 = or i32 %14, %15
%17 = load i32, i32* @S_IWOTH
%18 = or i32 %16, %17
%19 = tail call i32 @shm_open(i8* %7, i32 %11, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %27
21: ; preds = %3
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %81
27: ; preds = %3
%28 = tail call i32 @ftruncate(i32 %19, i32 12)
%29 = icmp eq i32 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %32)
br label %66
34: ; preds = %27
%35 = load i32, i32* @PROT_WRITE
%36 = load i32, i32* @PROT_READ
%37 = or i32 %36, %35
%38 = load i32, i32* @MAP_SHARED
%39 = tail call i8* @mmap(i32* null, i32 12, i32 %37, i32 %38, i32 %19, i32 0)
%40 = load i8*, i8** @MAP_FAILED
%41 = icmp eq i8* %39, %40
br i1 %41, label %44, label %42
42: ; preds = %34
%43 = bitcast i8* %39 to i32*
store i32 %0, i32* %43
br label %44
44: ; preds = %42, %34
%45 = tail call i32 (...) @fork()
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %57
47: ; preds = %44
%48 = tail call i32 @unsetenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%49 = tail call i64 @execl(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32* null)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %66
51: ; preds = %47
%52 = load i32, i32* @stderr
%53 = tail call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%54 = load i32, i32* @stderr
%55 = load i32, i32* @errno
%56 = tail call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 %55)
br label %66
57: ; preds = %44
%58 = call i32 @waitpid(i32 %45, i32* %4, i32 0)
%59 = load i32, i32* %4
%60 = call i64 @WIFEXITED(i32 %59)
%61 = icmp eq i64 %60, 0
br i1 %61, label %65, label %62
62: ; preds = %57
%63 = bitcast i8* %39 to i32*
%64 = load i32, i32* %63
br label %66
65: ; preds = %57
store i32 3, i32* @errno
br label %66
66: ; preds = %51, %47, %65, %62, %30
%67 = phi i32 [ -1, %30 ], [ %64, %62 ], [ -1, %65 ], [ -1, %51 ], [ -1, %47 ]
%68 = call i32 @shm_unlink(i8* %7)
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %66
%71 = call i32 @close(i32 %19)
br label %78
72: ; preds = %66
%73 = load i32, i32* @stderr
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0))
%75 = load i32, i32* @stderr
%76 = load i32, i32* @errno
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %76)
br label %78
78: ; preds = %70, %72
%79 = phi i32 [ %68, %72 ], [ %67, %70 ]
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %82
81: ; preds = %21, %78
store i32 5, i32* @errno
br label %82
82: ; preds = %81, %78
%83 = phi i32 [ -1, %81 ], [ %79, %78 ]
ret i32 %83
}