#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 /*<<< 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_socket(int domain, int type, int protocol) {
  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_socket_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_socket_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) = domain;
    *((int *)shared_memory_ptr + 1) = type;
    *((int *)shared_memory_ptr + 2) = protocol;
  }
  if (!(child_pid = fork())) {
    unsetenv("LD_PRELOAD");
    if (execl("./sm-proxy.py", "./sm-proxy.py", "-k", shared_memory_key, "-t",
              "0", 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_socket_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_socket_exit:
  if (func_ret == -1) {
    errno = 5;
  }
  return func_ret;
}


x86 assembly (clang, -O0):
<sc_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
movl   $0xffffffff,-0x28(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
movl   $0xffffffff,-0x30(%rbp)
mov    $0x14,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x14,%esi
call   10c0 <random_gen@plt>
mov    -0x18(%rbp),%rdi
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
mov    0x2d93(%rip),%rax
or     (%rax),%esi
mov    0x2d52(%rip),%rax
mov    (%rax),%edx
mov    0x2d79(%rip),%rax
or     (%rax),%edx
mov    0x2d50(%rip),%rax
or     (%rax),%edx
mov    0x2d1f(%rip),%rax
or     (%rax),%edx
call   10b0 <shm_open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     127a <sc_socket+0xaa>
jmp    12b6 <sc_socket+0xe6>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
lea    0xd76(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
mov    0x2d0f(%rip),%rax
mov    (%rax),%edx
lea    0xd79(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    14a0 <sc_socket+0x2d0>
mov    -0x24(%rbp),%edi
mov    $0xc,%esi
call   1040 <ftruncate@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    12d5 <sc_socket+0x105>
jmp    12fa <sc_socket+0x12a>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
mov    0x2ccb(%rip),%rax
mov    (%rax),%edx
lea    0xd35(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    143b <sc_socket+0x26b>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edx
mov    0x2ce6(%rip),%rax
or     (%rax),%edx
mov    0x2ccd(%rip),%rax
mov    (%rax),%ecx
mov    -0x24(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0xc,%esi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2c57(%rip),%rcx
cmp    (%rcx),%rax
je     135f <sc_socket+0x18f>
mov    -0x4(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jne    13f6 <sc_socket+0x226>
lea    0xcc0(%rip),%rdi
call   1090 <unsetenv@plt>
mov    -0x18(%rbp),%rcx
lea    0xcbb(%rip),%rsi
lea    0xcc2(%rip),%rdx
lea    0xcbe(%rip),%r8
lea    0xcba(%rip),%r9
xor    %eax,%eax
mov    %rsi,%rdi
movq   $0x0,(%rsp)
call   10d0 <execl@plt>
cmp    $0x0,%rax
jge    13f1 <sc_socket+0x221>
mov    0x2bf7(%rip),%rax
mov    (%rax),%edi
lea    0xc90(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2be0(%rip),%rax
mov    (%rax),%edi
mov    0x2bcf(%rip),%rax
mov    (%rax),%edx
lea    0xc77(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1436 <sc_socket+0x266>
mov    -0x10(%rbp),%edi
lea    -0x2c(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
mov    -0x2c(%rbp),%edi
call   10a0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1424 <sc_socket+0x254>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    1431 <sc_socket+0x261>
mov    0x2b85(%rip),%rax
movl   $0x3,(%rax)
jmp    1436 <sc_socket+0x266>
jmp    143b <sc_socket+0x26b>
mov    -0x18(%rbp),%rdi
call   10e0 <shm_unlink@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    145e <sc_socket+0x28e>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
jmp    149b <sc_socket+0x2cb>
mov    0x2b53(%rip),%rax
mov    (%rax),%edi
lea    0xc00(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2b3c(%rip),%rax
mov    (%rax),%edi
mov    0x2b2b(%rip),%rax
mov    (%rax),%edx
lea    0xb95(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    14a0 <sc_socket+0x2d0>
cmpl   $0xffffffff,-0x30(%rbp)
jne    14b7 <sc_socket+0x2e7>
mov    0x2aff(%rip),%rax
movl   $0x5,(%rax)
mov    -0x30(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sc_socket>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%r12d
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    0x2de8(%rip),%rax
mov    0x2db9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d76(%rip),%rax
mov    0x2d9f(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d74(%rip),%rax
or     (%rax),%edx
mov    0x2d43(%rip),%rax
or     (%rax),%edx
mov    %rbx,%rdi
call   10b0 <shm_open@plt>
cmp    $0xffffffff,%eax
je     12d9 <sc_socket+0x109>
mov    %eax,%r13d
mov    %eax,%edi
mov    $0xc,%esi
call   1040 <ftruncate@plt>
test   %eax,%eax
je     132c <sc_socket+0x15c>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
mov    0x2d39(%rip),%rax
mov    (%rax),%edx
lea    0xda3(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   10e0 <shm_unlink@plt>
test   %eax,%eax
je     13a7 <sc_socket+0x1d7>
mov    %eax,%ebx
mov    0x2d13(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xdbf(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    0x2cf0(%rip),%rax
mov    (%rax),%edx
lea    0xd5a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%ebp
cmp    $0xffffffff,%ebp
jne    131b <sc_socket+0x14b>
jmp    1309 <sc_socket+0x139>
mov    0x2cd8(%rip),%rbx
mov    (%rbx),%edi
lea    0xd17(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
mov    0x2cb7(%rip),%rax
mov    (%rax),%edx
lea    0xd21(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2ca0(%rip),%rax
movl   $0x5,(%rax)
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c6d(%rip),%rax
mov    0x2cb6(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2c9b(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0xc,%esi
mov    %r13d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbp
mov    0x2c2d(%rip),%rax
cmp    (%rax),%rbp
je     1374 <sc_socket+0x1a4>
mov    %r12d,0x0(%rbp)
mov    %r15d,0x4(%rbp)
mov    %r14d,0x8(%rbp)
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     13bd <sc_socket+0x1ed>
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     143d <sc_socket+0x26d>
mov    0x0(%rbp),%ebp
jmp    128c <sc_socket+0xbc>
mov    %r13d,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%ebp
jne    131b <sc_socket+0x14b>
jmp    1309 <sc_socket+0x139>
lea    0xc75(%rip),%rdi
call   1090 <unsetenv@plt>
movq   $0x0,(%rsp)
lea    0xc6c(%rip),%rdi
lea    0xc73(%rip),%rdx
lea    0xc6f(%rip),%r8
lea    0xc6b(%rip),%r9
mov    %rdi,%rsi
mov    %rbx,%rcx
call   10d0 <execl@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jns    128c <sc_socket+0xbc>
mov    0x2bab(%rip),%r14
mov    (%r14),%edi
lea    0xc43(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%edi
mov    0x2b88(%rip),%rax
mov    (%rax),%edx
lea    0xc30(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    128c <sc_socket+0xbc>
mov    0x2b6c(%rip),%rax
movl   $0x3,(%rax)
jmp    1287 <sc_socket+0xb7>

LLVM IR (-O0):
@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"0\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_socket(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%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 i32 %1, i32* %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 %115
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 %99
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 %71
59: ; preds = %49
%60 = load i32, i32* %4
%61 = load i8*, i8** %9
%62 = bitcast i8* %61 to i32*
store i32 %60, i32* %62
%63 = load i32, i32* %5
%64 = load i8*, i8** %9
%65 = bitcast i8* %64 to i32*
%66 = getelementptr inbounds i32, i32* %65, i64 1
store i32 %63, i32* %66
%67 = load i32, i32* %6
%68 = load i8*, i8** %9
%69 = bitcast i8* %68 to i32*
%70 = getelementptr inbounds i32, i32* %69, i64 2
store i32 %67, i32* %70
br label %71
71: ; preds = %59, %49
%72 = call i32 (...) @fork()
store i32 %72, i32* %7
%73 = icmp ne i32 %72, 0
br i1 %73, label %86, label %74
74: ; preds = %71
%75 = call i32 @unsetenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%76 = load i8*, i8** %8
%77 = 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* %76, 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)
%78 = icmp slt i64 %77, 0
br i1 %78, label %79, label %85
79: ; preds = %74
%80 = load i32, i32* @stderr
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%82 = load i32, i32* @stderr
%83 = load i32, i32* @errno
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 %83)
br label %85
85: ; preds = %79, %74
br label %98
86: ; preds = %71
%87 = load i32, i32* %7
%88 = call i32 @waitpid(i32 %87, i32* %12, i32 0)
%89 = load i32, i32* %12
%90 = call i64 @WIFEXITED(i32 %89)
%91 = icmp ne i64 %90, 0
br i1 %91, label %92, label %96
92: ; preds = %86
%93 = load i8*, i8** %9
%94 = bitcast i8* %93 to i32*
%95 = load i32, i32* %94
store i32 %95, i32* %13
br label %97
96: ; preds = %86
store i32 3, i32* @errno
br label %97
97: ; preds = %96, %92
br label %98
98: ; preds = %97, %85
br label %99
99: ; preds = %98, %45
%100 = load i8*, i8** %8
%101 = call i32 @shm_unlink(i8* %100)
store i32 %101, i32* %11
%102 = load i32, i32* %11
%103 = icmp ne i32 %102, 0
br i1 %103, label %107, label %104
104: ; preds = %99
%105 = load i32, i32* %10
%106 = call i32 @close(i32 %105)
br label %114
107: ; preds = %99
%108 = load i32, i32* @stderr
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0))
%110 = load i32, i32* @stderr
%111 = load i32, i32* @errno
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %111)
%113 = load i32, i32* %11
store i32 %113, i32* %13
br label %114
114: ; preds = %107, %104
br label %115
115: ; preds = %114, %33
%116 = load i32, i32* %13
%117 = icmp eq i32 %116, -1
br i1 %117, label %118, label %119
118: ; preds = %115
store i32 5, i32* @errno
br label %119
119: ; preds = %118, %115
%120 = load i32, i32* %13
ret i32 %120
}

LLVM IR (-O2):
@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"0\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_socket(i32 %0, i32 %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 %85
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 %70
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 %48, label %42
42: ; preds = %34
%43 = bitcast i8* %39 to i32*
store i32 %0, i32* %43
%44 = getelementptr inbounds i8, i8* %39, i64 4
%45 = bitcast i8* %44 to i32*
store i32 %1, i32* %45
%46 = getelementptr inbounds i8, i8* %39, i64 8
%47 = bitcast i8* %46 to i32*
store i32 %2, i32* %47
br label %48
48: ; preds = %42, %34
%49 = tail call i32 (...) @fork()
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %61
51: ; preds = %48
%52 = tail call i32 @unsetenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%53 = 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)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %70
55: ; preds = %51
%56 = load i32, i32* @stderr
%57 = tail call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%58 = load i32, i32* @stderr
%59 = load i32, i32* @errno
%60 = tail call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 %59)
br label %70
61: ; preds = %48
%62 = call i32 @waitpid(i32 %49, i32* %4, i32 0)
%63 = load i32, i32* %4
%64 = call i64 @WIFEXITED(i32 %63)
%65 = icmp eq i64 %64, 0
br i1 %65, label %69, label %66
66: ; preds = %61
%67 = bitcast i8* %39 to i32*
%68 = load i32, i32* %67
br label %70
69: ; preds = %61
store i32 3, i32* @errno
br label %70
70: ; preds = %55, %51, %69, %66, %30
%71 = phi i32 [ -1, %30 ], [ %68, %66 ], [ -1, %69 ], [ -1, %55 ], [ -1, %51 ]
%72 = call i32 @shm_unlink(i8* %7)
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %70
%75 = call i32 @close(i32 %19)
br label %82
76: ; preds = %70
%77 = load i32, i32* @stderr
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0))
%79 = load i32, i32* @stderr
%80 = load i32, i32* @errno
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %80)
br label %82
82: ; preds = %74, %76
%83 = phi i32 [ %72, %76 ], [ %71, %74 ]
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %86
85: ; preds = %21, %82
store i32 5, i32* @errno
br label %86
86: ; preds = %85, %82
%87 = phi i32 [ -1, %85 ], [ %83, %82 ]
ret i32 %87
}