#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 *, void const *, 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_send(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_send_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_send_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;
    memcpy((void *)(((size_t *)((int *)shared_memory_ptr + 2)) + 1), buffer,
           length);
  }
  if (!(child_pid = fork())) {
    unsetenv("LD_PRELOAD");
    if (execl("./sm-proxy.py", "./sm-proxy.py", "-k", shared_memory_key, "-t",
              "2", 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_send_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_send_exit:
  if (func_ret == -1) {
    errno = 5;
  }
  return func_ret;
}


x86 assembly (clang, -O0):
<sc_send>:
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_send+0xb6>
jmp    12d2 <sc_send+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    14de <sc_send+0x2fe>
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_send+0x11a>
jmp    131f <sc_send+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    1479 <sc_send+0x299>
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     139d <sc_send+0x1bd>
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    -0x30(%rbp),%rdi
add    $0x8,%rdi
add    $0x8,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <memcpy@plt>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jne    1434 <sc_send+0x254>
lea    0xc82(%rip),%rdi
call   10a0 <unsetenv@plt>
mov    -0x28(%rbp),%rcx
lea    0xc7d(%rip),%rsi
lea    0xc84(%rip),%rdx
lea    0xc80(%rip),%r8
lea    0xc7c(%rip),%r9
xor    %eax,%eax
mov    %rsi,%rdi
movq   $0x0,(%rsp)
call   10e0 <execl@plt>
cmp    $0x0,%rax
jge    142f <sc_send+0x24f>
mov    0x2bb9(%rip),%rax
mov    (%rax),%edi
lea    0xc52(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2ba2(%rip),%rax
mov    (%rax),%edi
mov    0x2b91(%rip),%rax
mov    (%rax),%edx
lea    0xc39(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1474 <sc_send+0x294>
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     1462 <sc_send+0x282>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
jmp    146f <sc_send+0x28f>
mov    0x2b47(%rip),%rax
movl   $0x3,(%rax)
jmp    1474 <sc_send+0x294>
jmp    1479 <sc_send+0x299>
mov    -0x28(%rbp),%rdi
call   10f0 <shm_unlink@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    149c <sc_send+0x2bc>
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
jmp    14d9 <sc_send+0x2f9>
mov    0x2b15(%rip),%rax
mov    (%rax),%edi
lea    0xbc2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2afe(%rip),%rax
mov    (%rax),%edi
mov    0x2aed(%rip),%rax
mov    (%rax),%edx
lea    0xb57(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    14de <sc_send+0x2fe>
cmpl   $0xffffffff,-0x40(%rbp)
jne    14f5 <sc_send+0x315>
mov    0x2ac1(%rip),%rax
movl   $0x5,(%rax)
mov    -0x40(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sc_send>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebp
mov    %rdx,%r12
mov    %rsi,%r15
mov    %edi,%ebx
movl   $0xffffffff,0x8(%rsp)
ff
mov    $0x14,%edi
call   1080 <malloc@plt>
mov    %rax,%r13
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    %r13,%rdi
call   10c0 <shm_open@plt>
cmp    $0xffffffff,%eax
je     12f0 <sc_send+0x110>
mov    %eax,%r14d
mov    %ebp,0xc(%rsp)
lea    0x10(%r12),%ebp
mov    %eax,%edi
mov    %ebp,%esi
call   1040 <ftruncate@plt>
test   %eax,%eax
je     1343 <sc_send+0x163>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
mov    0x2d22(%rip),%rax
mov    (%rax),%edx
lea    0xd8c(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %r13,%rdi
call   10f0 <shm_unlink@plt>
test   %eax,%eax
je     13d7 <sc_send+0x1f7>
mov    %eax,%ebx
mov    0x2cfc(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xda8(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    0x2cd9(%rip),%rax
mov    (%rax),%edx
lea    0xd43(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%ebp
cmp    $0xffffffff,%ebp
jne    1332 <sc_send+0x152>
jmp    1320 <sc_send+0x140>
mov    0x2cc1(%rip),%rbx
mov    (%rbx),%edi
lea    0xd00(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
mov    0x2ca0(%rip),%rax
mov    (%rax),%edx
lea    0xd0a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2c89(%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    0x2c51(%rip),%rax
mov    0x2c9a(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2c7f(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebp,%esi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%r15
mov    0x2c14(%rip),%rax
cmp    (%rax),%r15
je     13a4 <sc_send+0x1c4>
mov    %ebx,(%r15)
mov    0xc(%rsp),%eax
mov    %eax,0x4(%r15)
mov    %r12,0x8(%r15)
mov    %r15,%rdi
add    $0x10,%rdi
mov    0x10(%rsp),%rsi
mov    %r12,%rdx
call   1070 <memcpy@plt>
xor    %eax,%eax
call   1100 <fork@plt>
test   %eax,%eax
je     13ed <sc_send+0x20d>
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     146d <sc_send+0x28d>
mov    (%r15),%ebp
jmp    12a3 <sc_send+0xc3>
mov    %r14d,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%ebp
jne    1332 <sc_send+0x152>
jmp    1320 <sc_send+0x140>
lea    0xc45(%rip),%rdi
call   10a0 <unsetenv@plt>
movq   $0x0,(%rsp)
lea    0xc3c(%rip),%rdi
lea    0xc43(%rip),%rdx
lea    0xc3f(%rip),%r8
lea    0xc3b(%rip),%r9
mov    %rdi,%rsi
mov    %r13,%rcx
call   10e0 <execl@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jns    12a3 <sc_send+0xc3>
mov    0x2b7b(%rip),%r15
mov    (%r15),%edi
lea    0xc13(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r15),%edi
mov    0x2b58(%rip),%rax
mov    (%rax),%edx
lea    0xc00(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12a3 <sc_send+0xc3>
mov    0x2b3c(%rip),%rax
movl   $0x3,(%rax)
jmp    129e <sc_send+0xbe>

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"2\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_send(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 %133
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 %117
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 %89
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
%80 = load i8*, i8** %11
%81 = bitcast i8* %80 to i32*
%82 = getelementptr inbounds i32, i32* %81, i64 2
%83 = bitcast i32* %82 to i64*
%84 = getelementptr inbounds i64, i64* %83, i64 1
%85 = bitcast i64* %84 to i8*
%86 = load i8*, i8** %6
%87 = load i64, i64* %7
%88 = call i32 @memcpy(i8* %85, i8* %86, i64 %87)
br label %89
89: ; preds = %67, %56
%90 = call i32 (...) @fork()
store i32 %90, i32* %9
%91 = icmp ne i32 %90, 0
br i1 %91, label %104, label %92
92: ; preds = %89
%93 = call i32 @unsetenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%94 = load i8*, i8** %10
%95 = 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* %94, 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)
%96 = icmp slt i64 %95, 0
br i1 %96, label %97, label %103
97: ; preds = %92
%98 = load i32, i32* @stderr
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%100 = load i32, i32* @stderr
%101 = load i32, i32* @errno
%102 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 %101)
br label %103
103: ; preds = %97, %92
br label %116
104: ; preds = %89
%105 = load i32, i32* %9
%106 = call i32 @waitpid(i32 %105, i32* %14, i32 0)
%107 = load i32, i32* %14
%108 = call i64 @WIFEXITED(i32 %107)
%109 = icmp ne i64 %108, 0
br i1 %109, label %110, label %114
110: ; preds = %104
%111 = load i8*, i8** %11
%112 = bitcast i8* %111 to i32*
%113 = load i32, i32* %112
store i32 %113, i32* %15
br label %115
114: ; preds = %104
store i32 3, i32* @errno
br label %115
115: ; preds = %114, %110
br label %116
116: ; preds = %115, %103
br label %117
117: ; preds = %116, %52
%118 = load i8*, i8** %10
%119 = call i32 @shm_unlink(i8* %118)
store i32 %119, i32* %13
%120 = load i32, i32* %13
%121 = icmp ne i32 %120, 0
br i1 %121, label %125, label %122
122: ; preds = %117
%123 = load i32, i32* %12
%124 = call i32 @close(i32 %123)
br label %132
125: ; preds = %117
%126 = load i32, i32* @stderr
%127 = call i32 (i32, i8*, ...) @fprintf(i32 %126, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0))
%128 = load i32, i32* @stderr
%129 = load i32, i32* @errno
%130 = call i32 (i32, i8*, ...) @fprintf(i32 %128, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %129)
%131 = load i32, i32* %13
store i32 %131, i32* %15
br label %132
132: ; preds = %125, %122
br label %133
133: ; preds = %132, %36
%134 = load i32, i32* %15
%135 = icmp eq i32 %134, -1
br i1 %135, label %136, label %137
136: ; preds = %133
store i32 5, i32* @errno
br label %137
137: ; preds = %136, %133
%138 = load i32, i32* %15
ret i32 %138
}

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"2\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_send(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 %90
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 %75
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 %53, 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
%51 = getelementptr inbounds i8, i8* %42, i64 16
%52 = tail call i32 @memcpy(i8* %51, i8* %1, i64 %2)
br label %53
53: ; preds = %45, %37
%54 = tail call i32 (...) @fork()
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %66
56: ; preds = %53
%57 = tail call i32 @unsetenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%58 = 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)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %75
60: ; preds = %56
%61 = load i32, i32* @stderr
%62 = tail call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%63 = load i32, i32* @stderr
%64 = load i32, i32* @errno
%65 = tail call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 %64)
br label %75
66: ; preds = %53
%67 = call i32 @waitpid(i32 %54, i32* %5, i32 0)
%68 = load i32, i32* %5
%69 = call i64 @WIFEXITED(i32 %68)
%70 = icmp eq i64 %69, 0
br i1 %70, label %74, label %71
71: ; preds = %66
%72 = bitcast i8* %42 to i32*
%73 = load i32, i32* %72
br label %75
74: ; preds = %66
store i32 3, i32* @errno
br label %75
75: ; preds = %60, %56, %74, %71, %33
%76 = phi i32 [ -1, %33 ], [ %73, %71 ], [ -1, %74 ], [ -1, %60 ], [ -1, %56 ]
%77 = call i32 @shm_unlink(i8* %8)
%78 = icmp eq i32 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %75
%80 = call i32 @close(i32 %20)
br label %87
81: ; preds = %75
%82 = load i32, i32* @stderr
%83 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0))
%84 = load i32, i32* @stderr
%85 = load i32, i32* @errno
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %85)
br label %87
87: ; preds = %79, %81
%88 = phi i32 [ %77, %81 ], [ %76, %79 ]
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %91
90: ; preds = %22, %87
store i32 5, i32* @errno
br label %91
91: ; preds = %90, %87
%92 = phi i32 [ -1, %90 ], [ %88, %87 ]
ret i32 %92
}