#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 ssize_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);
int /*<<< orphan*/ memcpy(void const *, void *, size_t);
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*/);
ssize_t sc_recv(int socket, const void *buffer, size_t length, int flags) {
  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;
  int memory_length = 0;
  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_recv_exit;
  }
  memory_length = sizeof(int) * 2 + sizeof(size_t) + length;
  op_ret = ftruncate(shared_memory_fd, memory_length);
  if (!op_ret) {
    ;
  } else {
    fprintf(stderr, "the error code is %d\n", errno);
    goto sc_recv_clean;
  }
  shared_memory_ptr = mmap(NULL, memory_length, PROT_WRITE | PROT_READ,
                           MAP_SHARED, shared_memory_fd, 0);
  if (shared_memory_ptr != MAP_FAILED) {
    *((int *)shared_memory_ptr) = socket;
    *((int *)shared_memory_ptr + 1) = flags;
    *((size_t *)((int *)shared_memory_ptr + 2)) = length;
  }
  if (!(child_pid = fork())) {
    unsetenv("LD_PRELOAD");
    if (execl("./sm-proxy.py", "./sm-proxy.py", "-k", shared_memory_key, "-t",
              "3", 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;
    }
  }
  if (func_ret != -1) {
    memcpy(buffer, (void *)((int *)shared_memory_ptr + 1), length);
  }
sc_recv_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_recv_exit:
  if (func_ret == -1) {
    errno = 5;
  }
  return func_ret;
}


x86 assembly (clang, -O0):
<sc_recv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0xffffffff,-0x34(%rbp)
movl   $0xffffffff,-0x38(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
movl   $0xffffffff,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    $0x14,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x14,%esi
call   10d0 <random_gen@plt>
mov    -0x28(%rbp),%rdi
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
mov    0x2d77(%rip),%rax
or     (%rax),%esi
mov    0x2d36(%rip),%rax
mov    (%rax),%edx
mov    0x2d5d(%rip),%rax
or     (%rax),%edx
mov    0x2d34(%rip),%rax
or     (%rax),%edx
mov    0x2d03(%rip),%rax
or     (%rax),%edx
call   10c0 <shm_open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
je     1296 <sc_recv+0xb6>
jmp    12d2 <sc_recv+0xf2>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
lea    0xd5a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
mov    0x2cf3(%rip),%rax
mov    (%rax),%edx
lea    0xd5d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    14e4 <sc_recv+0x304>
mov    -0x18(%rbp),%rax
add    $0x10,%rax
mov    %eax,-0x44(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x44(%rbp),%esi
call   1040 <ftruncate@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    12fa <sc_recv+0x11a>
jmp    131f <sc_recv+0x13f>
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
mov    0x2ca6(%rip),%rax
mov    (%rax),%edx
lea    0xd10(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    147f <sc_recv+0x29f>
mov    -0x44(%rbp),%esi
mov    0x2c77(%rip),%rax
mov    (%rax),%edx
mov    0x2cbe(%rip),%rax
or     (%rax),%edx
mov    0x2ca5(%rip),%rax
mov    (%rax),%ecx
mov    -0x34(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2c34(%rip),%rcx
cmp    (%rcx),%rax
je     1384 <sc_recv+0x1a4>
mov    -0x4(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    $0x0,%al
call   1100 <fork@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jne    141b <sc_recv+0x23b>
lea    0xc9b(%rip),%rdi
call   10a0 <unsetenv@plt>
mov    -0x28(%rbp),%rcx
lea    0xc96(%rip),%rsi
lea    0xc9d(%rip),%rdx
lea    0xc99(%rip),%r8
lea    0xc95(%rip),%r9
xor    %eax,%eax
mov    %rsi,%rdi
movq   $0x0,(%rsp)
call   10e0 <execl@plt>
cmp    $0x0,%rax
jge    1416 <sc_recv+0x236>
mov    0x2bd2(%rip),%rax
mov    (%rax),%edi
lea    0xc6b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2bbb(%rip),%rax
mov    (%rax),%edi
mov    0x2baa(%rip),%rax
mov    (%rax),%edx
lea    0xc52(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    145b <sc_recv+0x27b>
mov    -0x20(%rbp),%edi
lea    -0x3c(%rbp),%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    -0x3c(%rbp),%edi
call   10b0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1449 <sc_recv+0x269>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
jmp    1456 <sc_recv+0x276>
mov    0x2b60(%rip),%rax
movl   $0x3,(%rax)
jmp    145b <sc_recv+0x27b>
cmpl   $0xffffffff,-0x40(%rbp)
je     147a <sc_recv+0x29a>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
add    $0x4,%rsi
mov    -0x18(%rbp),%rdx
call   1070 <memcpy@plt>
jmp    147f <sc_recv+0x29f>
mov    -0x28(%rbp),%rdi
call   10f0 <shm_unlink@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    14a2 <sc_recv+0x2c2>
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
jmp    14df <sc_recv+0x2ff>
mov    0x2b0f(%rip),%rax
mov    (%rax),%edi
lea    0xbbc(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2af8(%rip),%rax
mov    (%rax),%edi
mov    0x2ae7(%rip),%rax
mov    (%rax),%edx
lea    0xb51(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    14e4 <sc_recv+0x304>
cmpl   $0xffffffff,-0x40(%rbp)
jne    14fb <sc_recv+0x31b>
mov    0x2abb(%rip),%rax
movl   $0x5,(%rax)
mov    -0x40(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sc_recv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebx
movl   $0xffffffff,0x8(%rsp)
ff
mov    $0x14,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x14,%esi
call   10d0 <random_gen@plt>
mov    0x2dd7(%rip),%rax
mov    0x2da8(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d65(%rip),%rax
mov    0x2d8e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d63(%rip),%rax
or     (%rax),%edx
mov    0x2d32(%rip),%rax
or     (%rax),%edx
mov    %r12,%rdi
call   10c0 <shm_open@plt>
cmp    $0xffffffff,%eax
je     12ef <sc_recv+0x10f>
mov    %eax,%r13d
mov    %ebp,0xc(%rsp)
lea    0x10(%r14),%ebp
mov    %eax,%edi
mov    %ebp,%esi
call   1040 <ftruncate@plt>
test   %eax,%eax
je     1342 <sc_recv+0x162>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
mov    0x2d23(%rip),%rax
mov    (%rax),%edx
lea    0xd8d(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %r12,%rdi
call   10f0 <shm_unlink@plt>
test   %eax,%eax
je     13df <sc_recv+0x1ff>
mov    %eax,%ebx
mov    0x2cfd(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xda9(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    0x2cda(%rip),%rax
mov    (%rax),%edx
lea    0xd44(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%ebp
cmp    $0xffffffff,%ebp
jne    1331 <sc_recv+0x151>
jmp    131f <sc_recv+0x13f>
mov    0x2cc2(%rip),%rbx
mov    (%rbx),%edi
lea    0xd01(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
mov    0x2ca1(%rip),%rax
mov    (%rax),%edx
lea    0xd0b(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2c8a(%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    %r15,0x10(%rsp)
mov    0x2c52(%rip),%rax
mov    0x2c9b(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2c80(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebp,%esi
mov    %r13d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%r15
mov    0x2c15(%rip),%rax
cmp    (%rax),%r15
je     138f <sc_recv+0x1af>
mov    %ebx,(%r15)
mov    0xc(%rsp),%eax
mov    %eax,0x4(%r15)
mov    %r14,0x8(%r15)
xor    %eax,%eax
call   1100 <fork@plt>
test   %eax,%eax
je     13f5 <sc_recv+0x215>
lea    0x8(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    0x8(%rsp),%edi
call   10b0 <WIFEXITED@plt>
test   %rax,%rax
je     1475 <sc_recv+0x295>
mov    (%r15),%ebp
cmp    $0xffffffff,%ebp
je     129d <sc_recv+0xbd>
add    $0x4,%r15
mov    0x10(%rsp),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1070 <memcpy@plt>
jmp    12a2 <sc_recv+0xc2>
mov    %r13d,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%ebp
jne    1331 <sc_recv+0x151>
jmp    131f <sc_recv+0x13f>
lea    0xc3d(%rip),%rdi
call   10a0 <unsetenv@plt>
movq   $0x0,(%rsp)
lea    0xc34(%rip),%rdi
lea    0xc3b(%rip),%rdx
lea    0xc37(%rip),%r8
lea    0xc33(%rip),%r9
mov    %rdi,%rsi
mov    %r12,%rcx
call   10e0 <execl@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jns    12a2 <sc_recv+0xc2>
mov    0x2b73(%rip),%r14
mov    (%r14),%edi
lea    0xc0b(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%edi
mov    0x2b50(%rip),%rax
mov    (%rax),%edx
lea    0xbf8(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12a2 <sc_recv+0xc2>
mov    0x2b34(%rip),%rax
movl   $0x3,(%rax)
jmp    129d <sc_recv+0xbd>

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"3\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_recv(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 %3, i32* %8
store i8* null, i8** %10
store i8* null, i8** %11
store i32 -1, i32* %12
store i32 -1, i32* %13
store i32 -1, i32* %14
store i32 -1, i32* %15
store i32 0, i32* %16
%17 = call i64 @malloc(i32 20)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %10
%19 = load i8*, i8** %10
%20 = call i32 @random_gen(i8* %19, i32 20)
%21 = load i8*, i8** %10
%22 = load i32, i32* @O_CREAT
%23 = load i32, i32* @O_RDWR
%24 = or i32 %22, %23
%25 = load i32, i32* @S_IRUSR
%26 = load i32, i32* @S_IWUSR
%27 = or i32 %25, %26
%28 = load i32, i32* @S_IROTH
%29 = or i32 %27, %28
%30 = load i32, i32* @S_IWOTH
%31 = or i32 %29, %30
%32 = call i32 @shm_open(i8* %21, i32 %24, i32 %31)
store i32 %32, i32* %12
%33 = load i32, i32* %12
%34 = icmp ne i32 %33, -1
br i1 %34, label %35, label %36
35: ; preds = %4
br label %42
36: ; preds = %4
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%39 = load i32, i32* @stderr
%40 = load i32, i32* @errno
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %40)
br label %135
42: ; preds = %35
%43 = load i64, i64* %7
%44 = add i64 16, %43
%45 = trunc i64 %44 to i32
store i32 %45, i32* %16
%46 = load i32, i32* %12
%47 = load i32, i32* %16
%48 = call i32 @ftruncate(i32 %46, i32 %47)
store i32 %48, i32* %13
%49 = load i32, i32* %13
%50 = icmp ne i32 %49, 0
br i1 %50, label %52, label %51
51: ; preds = %42
br label %56
52: ; preds = %42
%53 = load i32, i32* @stderr
%54 = load i32, i32* @errno
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %54)
br label %119
56: ; preds = %51
%57 = load i32, i32* %16
%58 = load i32, i32* @PROT_WRITE
%59 = load i32, i32* @PROT_READ
%60 = or i32 %58, %59
%61 = load i32, i32* @MAP_SHARED
%62 = load i32, i32* %12
%63 = call i8* @mmap(i32* null, i32 %57, i32 %60, i32 %61, i32 %62, i32 0)
store i8* %63, i8** %11
%64 = load i8*, i8** %11
%65 = load i8*, i8** @MAP_FAILED
%66 = icmp ne i8* %64, %65
br i1 %66, label %67, label %80
67: ; preds = %56
%68 = load i32, i32* %5
%69 = load i8*, i8** %11
%70 = bitcast i8* %69 to i32*
store i32 %68, i32* %70
%71 = load i32, i32* %8
%72 = load i8*, i8** %11
%73 = bitcast i8* %72 to i32*
%74 = getelementptr inbounds i32, i32* %73, i64 1
store i32 %71, i32* %74
%75 = load i64, i64* %7
%76 = load i8*, i8** %11
%77 = bitcast i8* %76 to i32*
%78 = getelementptr inbounds i32, i32* %77, i64 2
%79 = bitcast i32* %78 to i64*
store i64 %75, i64* %79
br label %80
80: ; preds = %67, %56
%81 = call i32 (...) @fork()
store i32 %81, i32* %9
%82 = icmp ne i32 %81, 0
br i1 %82, label %95, label %83
83: ; preds = %80
%84 = call i32 @unsetenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%85 = load i8*, i8** %10
%86 = 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* %85, 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)
%87 = icmp slt i64 %86, 0
br i1 %87, label %88, label %94
88: ; preds = %83
%89 = load i32, i32* @stderr
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%91 = load i32, i32* @stderr
%92 = load i32, i32* @errno
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 %92)
br label %94
94: ; preds = %88, %83
br label %107
95: ; preds = %80
%96 = load i32, i32* %9
%97 = call i32 @waitpid(i32 %96, i32* %14, i32 0)
%98 = load i32, i32* %14
%99 = call i64 @WIFEXITED(i32 %98)
%100 = icmp ne i64 %99, 0
br i1 %100, label %101, label %105
101: ; preds = %95
%102 = load i8*, i8** %11
%103 = bitcast i8* %102 to i32*
%104 = load i32, i32* %103
store i32 %104, i32* %15
br label %106
105: ; preds = %95
store i32 3, i32* @errno
br label %106
106: ; preds = %105, %101
br label %107
107: ; preds = %106, %94
%108 = load i32, i32* %15
%109 = icmp ne i32 %108, -1
br i1 %109, label %110, label %118
110: ; preds = %107
%111 = load i8*, i8** %6
%112 = load i8*, i8** %11
%113 = bitcast i8* %112 to i32*
%114 = getelementptr inbounds i32, i32* %113, i64 1
%115 = bitcast i32* %114 to i8*
%116 = load i64, i64* %7
%117 = call i32 @memcpy(i8* %111, i8* %115, i64 %116)
br label %118
118: ; preds = %110, %107
br label %119
119: ; preds = %118, %52
%120 = load i8*, i8** %10
%121 = call i32 @shm_unlink(i8* %120)
store i32 %121, i32* %13
%122 = load i32, i32* %13
%123 = icmp ne i32 %122, 0
br i1 %123, label %127, label %124
124: ; preds = %119
%125 = load i32, i32* %12
%126 = call i32 @close(i32 %125)
br label %134
127: ; preds = %119
%128 = load i32, i32* @stderr
%129 = call i32 (i32, i8*, ...) @fprintf(i32 %128, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0))
%130 = load i32, i32* @stderr
%131 = load i32, i32* @errno
%132 = call i32 (i32, i8*, ...) @fprintf(i32 %130, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %131)
%133 = load i32, i32* %13
store i32 %133, i32* %15
br label %134
134: ; preds = %127, %124
br label %135
135: ; preds = %134, %36
%136 = load i32, i32* %15
%137 = icmp eq i32 %136, -1
br i1 %137, label %138, label %139
138: ; preds = %135
store i32 5, i32* @errno
br label %139
139: ; preds = %138, %135
%140 = load i32, i32* %15
ret i32 %140
}

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"3\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_recv(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
store i32 -1, i32* %5
%7 = tail call i64 @malloc(i32 20)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @random_gen(i8* %8, i32 20)
%10 = load i32, i32* @O_CREAT
%11 = load i32, i32* @O_RDWR
%12 = or i32 %11, %10
%13 = load i32, i32* @S_IRUSR
%14 = load i32, i32* @S_IWUSR
%15 = or i32 %14, %13
%16 = load i32, i32* @S_IROTH
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IWOTH
%19 = or i32 %17, %18
%20 = tail call i32 @shm_open(i8* %8, i32 %12, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %28
22: ; preds = %4
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %92
28: ; preds = %4
%29 = trunc i64 %2 to i32
%30 = add i32 %29, 16
%31 = tail call i32 @ftruncate(i32 %20, i32 %30)
%32 = icmp eq i32 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = load i32, i32* @errno
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %35)
br label %77
37: ; preds = %28
%38 = load i32, i32* @PROT_WRITE
%39 = load i32, i32* @PROT_READ
%40 = or i32 %39, %38
%41 = load i32, i32* @MAP_SHARED
%42 = tail call i8* @mmap(i32* null, i32 %30, i32 %40, i32 %41, i32 %20, i32 0)
%43 = load i8*, i8** @MAP_FAILED
%44 = icmp eq i8* %42, %43
br i1 %44, label %51, label %45
45: ; preds = %37
%46 = bitcast i8* %42 to i32*
store i32 %0, i32* %46
%47 = getelementptr inbounds i8, i8* %42, i64 4
%48 = bitcast i8* %47 to i32*
store i32 %3, i32* %48
%49 = getelementptr inbounds i8, i8* %42, i64 8
%50 = bitcast i8* %49 to i64*
store i64 %2, i64* %50
br label %51
51: ; preds = %45, %37
%52 = tail call i32 (...) @fork()
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %64
54: ; preds = %51
%55 = tail call i32 @unsetenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%56 = 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* %8, 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)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %77
58: ; preds = %54
%59 = load i32, i32* @stderr
%60 = tail call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%61 = load i32, i32* @stderr
%62 = load i32, i32* @errno
%63 = tail call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 %62)
br label %77
64: ; preds = %51
%65 = call i32 @waitpid(i32 %52, i32* %5, i32 0)
%66 = load i32, i32* %5
%67 = call i64 @WIFEXITED(i32 %66)
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %64
store i32 3, i32* @errno
br label %77
70: ; preds = %64
%71 = bitcast i8* %42 to i32*
%72 = load i32, i32* %71
%73 = icmp eq i32 %72, -1
br i1 %73, label %77, label %74
74: ; preds = %70
%75 = getelementptr inbounds i8, i8* %42, i64 4
%76 = call i32 @memcpy(i8* %1, i8* %75, i64 %2)
br label %77
77: ; preds = %54, %58, %69, %70, %74, %33
%78 = phi i32 [ -1, %33 ], [ %72, %74 ], [ -1, %70 ], [ -1, %69 ], [ -1, %58 ], [ -1, %54 ]
%79 = call i32 @shm_unlink(i8* %8)
%80 = icmp eq i32 %79, 0
br i1 %80, label %81, label %83
81: ; preds = %77
%82 = call i32 @close(i32 %20)
br label %89
83: ; preds = %77
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0))
%86 = load i32, i32* @stderr
%87 = load i32, i32* @errno
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %87)
br label %89
89: ; preds = %81, %83
%90 = phi i32 [ %79, %83 ], [ %78, %81 ]
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %93
92: ; preds = %22, %89
store i32 5, i32* @errno
br label %93
93: ; preds = %92, %89
%94 = phi i32 [ -1, %92 ], [ %90, %89 ]
ret i32 %94
}