#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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ SIGKILL;
int S_IROTH;
int S_IRUSR;
int S_IWOTH;
int S_IWUSR;
int errno;
scalar_t__ execl(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int ftruncate(int, int);
int /*<<< orphan*/ getchar();
scalar_t__ kill(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ malloc(int);
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ random_gen(char *, int);
int shm_open(char *, int, int);
scalar_t__ shm_unlink(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  pid_t my_pid;
  char *my_string;
  int size;
  FILE *fp = NULL;
  int sfd = -1;
  int socket_args[3] = {2, 1, 0};
  int ret = -1;
  void *shared_memory_ptr = NULL;
  int *temp_ptr = NULL;
  int a;
  my_string = (char *)malloc(sizeof(char) * 20);
  random_gen(my_string, 20);
  printf("my random string is %s\n", my_string);
  sfd = shm_open(my_string, O_CREAT | O_RDWR,
                 S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH);
  if (sfd != -1) {
    fprintf(stderr, "the shared memory descriptor is %d\n", sfd);
    fprintf(stderr, "creating the shared memory succeed\n");
  } else {
    fprintf(stderr, "the error code is %d\n", errno);
    goto error_exit;
  }
  ret = ftruncate(sfd, sizeof(int));
  if (!ret) {
    fprintf(stderr, "truncating the shared memory succeed\n");
  } else {
    fprintf(stderr, "the error code is %d\n", errno);
    goto error_exit;
  }
  shared_memory_ptr =
      mmap(NULL, sizeof(int) * 2, PROT_WRITE | PROT_READ, MAP_SHARED, sfd, 0);
  if (shared_memory_ptr != MAP_FAILED) {
    *((int *)shared_memory_ptr) = 2;
    *((int *)shared_memory_ptr + 1) = 1;
    *((int *)shared_memory_ptr + 2) = 0;
  }
  for (a = 0; a < 1000; a += 1) {
    printf("%d\n", a);
    *((int *)shared_memory_ptr + a) = a;
  }
  ret = ftruncate(sfd, sizeof(int) * 4096);
  if (!ret) {
    fprintf(stderr, "truncating the shared memory succeed\n");
  } else {
    fprintf(stderr, "the error code is %d\n", errno);
    goto error_exit;
  }
  if (shared_memory_ptr != MAP_FAILED) {
    *((int *)shared_memory_ptr) = 3;
    *((int *)shared_memory_ptr + 1) = 2;
    *((int *)shared_memory_ptr + 2) = 1;
  }
  shared_memory_ptr =
      mmap(NULL, sizeof(int) * 2, PROT_WRITE | PROT_READ, MAP_SHARED, sfd, 0);
  printf("the %d parameter is %d %d %d \n", 3, *((int *)shared_memory_ptr),
         *((int *)shared_memory_ptr + 1), *((int *)shared_memory_ptr + 2));
  printf("then I will unlink the shared memory\n");
  if (shm_unlink(my_string)) {
    printf("unlink error with %d", errno);
  }
  printf("the %d parameter is %d %d %d \n", 3, *((int *)shared_memory_ptr),
         *((int *)shared_memory_ptr + 1), *((int *)shared_memory_ptr + 2));
  getchar();
  my_pid = fork();
  if (!my_pid) {
    if (execl("./should-be-killed.py", "./should-be-killed.py", NULL) < 0) {
      printf("error\n");
      printf("error is %d\n", errno);
    }
  } else {
    sleep(5);
    if (kill(my_pid, SIGKILL)) {
      printf("error with %d\n", errno);
    }
  }
  return EXIT_SUCCESS;
error_exit:
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0xffffffff,-0x34(%rbp)
mov    0xe04(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe02(%rip),%eax
mov    %eax,-0x38(%rbp)
movl   $0xffffffff,-0x44(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
mov    $0x14,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x14,%esi
call   10b0 <random_gen@plt>
mov    -0x20(%rbp),%rsi
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
mov    0x2d6e(%rip),%rax
or     (%rax),%esi
mov    0x2d25(%rip),%rax
mov    (%rax),%edx
mov    0x2d54(%rip),%rax
or     (%rax),%edx
mov    0x2d2b(%rip),%rax
or     (%rax),%edx
mov    0x2ce2(%rip),%rax
or     (%rax),%edx
call   10a0 <shm_open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
je     12d0 <main+0x100>
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%edx
lea    0xd77(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2cfd(%rip),%rax
mov    (%rax),%edi
lea    0xd84(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    12f5 <main+0x125>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
mov    0x2cd0(%rip),%rax
mov    (%rax),%edx
lea    0xd83(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    15f8 <main+0x428>
mov    -0x34(%rbp),%edi
mov    $0x4,%esi
call   1050 <ftruncate@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jne    132b <main+0x15b>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
lea    0xd63(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1350 <main+0x180>
mov    0x2c86(%rip),%rax
mov    (%rax),%edi
mov    0x2c75(%rip),%rax
mov    (%rax),%edx
lea    0xd28(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    15f8 <main+0x428>
mov    0x2c41(%rip),%rax
mov    (%rax),%edx
mov    0x2c90(%rip),%rax
or     (%rax),%edx
mov    0x2c77(%rip),%rax
mov    (%rax),%ecx
mov    -0x34(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x8,%esi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    0x2be9(%rip),%rcx
cmp    (%rcx),%rax
je     13b8 <main+0x1e8>
mov    -0x50(%rbp),%rax
movl   $0x2,(%rax)
mov    -0x50(%rbp),%rax
movl   $0x1,0x4(%rax)
mov    -0x50(%rbp),%rax
movl   $0x0,0x8(%rax)
movl   $0x0,-0x5c(%rbp)
cmpl   $0x3e8,-0x5c(%rbp)
jge    13f9 <main+0x229>
mov    -0x5c(%rbp),%esi
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x5c(%rbp),%edx
mov    -0x50(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    13bf <main+0x1ef>
mov    -0x34(%rbp),%edi
mov    $0x4000,%esi
call   1050 <ftruncate@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jne    142f <main+0x25f>
mov    0x2b9e(%rip),%rax
mov    (%rax),%edi
lea    0xc5f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1454 <main+0x284>
mov    0x2b82(%rip),%rax
mov    (%rax),%edi
mov    0x2b71(%rip),%rax
mov    (%rax),%edx
lea    0xc24(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    15f8 <main+0x428>
mov    -0x50(%rbp),%rax
mov    0x2b19(%rip),%rcx
cmp    (%rcx),%rax
je     1488 <main+0x2b8>
mov    -0x50(%rbp),%rax
movl   $0x3,(%rax)
mov    -0x50(%rbp),%rax
movl   $0x2,0x4(%rax)
mov    -0x50(%rbp),%rax
movl   $0x1,0x8(%rax)
mov    0x2b09(%rip),%rax
mov    (%rax),%edx
mov    0x2b58(%rip),%rax
or     (%rax),%edx
mov    0x2b3f(%rip),%rax
mov    (%rax),%ecx
mov    -0x34(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x8,%esi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    (%rax),%edx
mov    -0x50(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%r8d
lea    0xbd0(%rip),%rdi
mov    $0x3,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xbdc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   10d0 <shm_unlink@plt>
cmp    $0x0,%rax
je     151c <main+0x34c>
mov    0x2aa4(%rip),%rax
mov    (%rax),%esi
lea    0xbd8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x50(%rbp),%rax
mov    (%rax),%edx
mov    -0x50(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%r8d
lea    0xb70(%rip),%rdi
mov    $0x3,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    15a6 <main+0x3d6>
lea    0xb9c(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   10c0 <execl@plt>
cmp    $0x0,%rax
jge    15a1 <main+0x3d1>
lea    0xb95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2a1f(%rip),%rax
mov    (%rax),%esi
lea    0xb85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    15e7 <main+0x417>
mov    $0x5,%edi
call   10e0 <sleep@plt>
mov    -0x14(%rbp),%edi
mov    0x29ce(%rip),%rax
mov    (%rax),%esi
call   1080 <kill@plt>
cmp    $0x0,%rax
je     15e2 <main+0x412>
mov    0x29de(%rip),%rax
mov    (%rax),%esi
lea    0xb51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    15e7 <main+0x417>
mov    0x2992(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1604 <main+0x434>
mov    0x29a1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x14,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x14,%esi
call   10c0 <random_gen@plt>
lea    0xdf4(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2ddb(%rip),%rax
mov    0x2dac(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d61(%rip),%rax
mov    0x2d92(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d67(%rip),%rax
or     (%rax),%edx
mov    0x2d1e(%rip),%rax
or     (%rax),%edx
mov    %r14,%rdi
call   10b0 <shm_open@plt>
mov    0x2d5d(%rip),%r13
mov    0x0(%r13),%edi
cmp    $0xffffffff,%eax
je     1341 <main+0x161>
mov    %eax,%r15d
lea    0xda6(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xdb6(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r15d,%edi
mov    $0x4,%esi
call   1060 <ftruncate@plt>
mov    0x0(%r13),%edi
test   %eax,%eax
jne    1341 <main+0x161>
lea    0xdc9(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2cdd(%rip),%rax
mov    0x2d2e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d13(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x8,%esi
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    0x2c8d(%rip),%rax
cmp    (%rax),%rbx
je     1304 <main+0x124>
movabs $0x100000002,%rax
mov    %rax,(%rbx)
movl   $0x0,0x8(%rbx)
lea    0xdf3(%rip),%r12
xor    %ebp,%ebp
nopl   (%rax)
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    $0x3e8,%rbp
jne    1310 <main+0x130>
mov    %r15d,%edi
mov    $0x4000,%esi
call   1060 <ftruncate@plt>
mov    0x0(%r13),%edi
test   %eax,%eax
je     1370 <main+0x190>
mov    0x2c68(%rip),%rax
mov    (%rax),%edx
lea    0xd0f(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2c41(%rip),%rbx
mov    (%rbx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcff(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2bf3(%rip),%rax
cmp    (%rax),%rbx
je     139e <main+0x1be>
movabs $0x200000003,%rax
mov    %rax,(%rbx)
movl   $0x1,0x8(%rbx)
mov    0x2c4b(%rip),%rax
mov    (%rax),%edx
mov    0x2bea(%rip),%rax
or     (%rax),%edx
mov    0x2c29(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x8,%esi
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    (%rax),%edx
mov    0x4(%rax),%ecx
mov    0x8(%rax),%r8d
lea    0xcbe(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd11(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   10e0 <shm_unlink@plt>
test   %rax,%rax
je     141a <main+0x23a>
mov    0x2ba6(%rip),%rax
mov    (%rax),%esi
lea    0xca8(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%edx
mov    0x4(%rbx),%ecx
mov    0x8(%rbx),%r8d
lea    0xc72(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
xor    %eax,%eax
call   1100 <fork@plt>
test   %eax,%eax
je     1486 <main+0x2a6>
mov    %eax,%ebx
mov    $0x5,%edi
call   10f0 <sleep@plt>
mov    0x2b2d(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1090 <kill@plt>
mov    0x2b15(%rip),%rbx
test   %rax,%rax
je     135f <main+0x17f>
mov    0x2b35(%rip),%rax
mov    (%rax),%esi
lea    0xc6f(%rip),%rdi
jmp    14c3 <main+0x2e3>
lea    0xc43(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   10d0 <execl@plt>
mov    0x2ae2(%rip),%rbx
test   %rax,%rax
jns    135f <main+0x17f>
lea    0xc79(%rip),%rdi
call   1030 <puts@plt>
mov    0x2af6(%rip),%rax
mov    (%rax),%esi
lea    0xc23(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    135f <main+0x17f>

LLVM IR (-O0):
@__const.main.socket_args = [3 x i32] [i32 2, i32 1, i32 0]
@.str = [24 x i8] c"my random string is %s\0A\00"
@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.1 = [36 x i8] c"the shared memory descriptor is %d\0A\00"
@.str.2 = [36 x i8] c"creating the shared memory succeed\0A\00"
@.str.3 = [22 x i8] c"the error code is %d\0A\00"
@errno = global i32 0
@.str.4 = [38 x i8] c"truncating the shared memory succeed\0A\00"
@PROT_WRITE = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.5 = [4 x i8] c"%d\0A\00"
@.str.6 = [31 x i8] c"the %d parameter is %d %d %d \0A\00"
@.str.7 = [38 x i8] c"then I will unlink the shared memory\0A\00"
@.str.8 = [21 x i8] c"unlink error with %d\00"
@.str.9 = [22 x i8] c"./should-be-killed.py\00"
@.str.10 = [7 x i8] c"error\0A\00"
@.str.11 = [13 x i8] c"error is %d\0A\00"
@SIGKILL = global i32 0
@.str.12 = [15 x i8] c"error with %d\0A\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca [3 x i32]
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32*
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %9
store i32 -1, i32* %10
%16 = bitcast [3 x i32]* %11 to i8*
store i32 -1, i32* %12
store i8* null, i8** %13
store i32* null, i32** %14
%17 = call i64 @malloc(i32 20)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = call i32 @random_gen(i8* %19, i32 20)
%21 = load i8*, i8** %7
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %7
%24 = load i32, i32* @O_CREAT
%25 = load i32, i32* @O_RDWR
%26 = or i32 %24, %25
%27 = load i32, i32* @S_IRUSR
%28 = load i32, i32* @S_IWUSR
%29 = or i32 %27, %28
%30 = load i32, i32* @S_IROTH
%31 = or i32 %29, %30
%32 = load i32, i32* @S_IWOTH
%33 = or i32 %31, %32
%34 = call i32 @shm_open(i8* %23, i32 %26, i32 %33)
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = icmp ne i32 %35, -1
br i1 %36, label %37, label %43
37: ; preds = %2
%38 = load i32, i32* @stderr
%39 = load i32, i32* %10
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %47
43: ; preds = %2
%44 = load i32, i32* @stderr
%45 = load i32, i32* @errno
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %45)
br label %182
47: ; preds = %37
%48 = load i32, i32* %10
%49 = call i32 @ftruncate(i32 %48, i32 4)
store i32 %49, i32* %12
%50 = load i32, i32* %12
%51 = icmp ne i32 %50, 0
br i1 %51, label %55, label %52
52: ; preds = %47
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
br label %59
55: ; preds = %47
%56 = load i32, i32* @stderr
%57 = load i32, i32* @errno
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %57)
br label %182
59: ; preds = %52
%60 = load i32, i32* @PROT_WRITE
%61 = load i32, i32* @PROT_READ
%62 = or i32 %60, %61
%63 = load i32, i32* @MAP_SHARED
%64 = load i32, i32* %10
%65 = call i8* @mmap(i32* null, i32 8, i32 %62, i32 %63, i32 %64, i32 0)
store i8* %65, i8** %13
%66 = load i8*, i8** %13
%67 = load i8*, i8** @MAP_FAILED
%68 = icmp ne i8* %66, %67
br i1 %68, label %69, label %78
69: ; preds = %59
%70 = load i8*, i8** %13
%71 = bitcast i8* %70 to i32*
store i32 2, i32* %71
%72 = load i8*, i8** %13
%73 = bitcast i8* %72 to i32*
%74 = getelementptr inbounds i32, i32* %73, i64 1
store i32 1, i32* %74
%75 = load i8*, i8** %13
%76 = bitcast i8* %75 to i32*
%77 = getelementptr inbounds i32, i32* %76, i64 2
store i32 0, i32* %77
br label %78
78: ; preds = %69, %59
store i32 0, i32* %15
br label %79
79: ; preds = %91, %78
%80 = load i32, i32* %15
%81 = icmp slt i32 %80, 1000
br i1 %81, label %82, label %94
82: ; preds = %79
%83 = load i32, i32* %15
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %83)
%85 = load i32, i32* %15
%86 = load i8*, i8** %13
%87 = bitcast i8* %86 to i32*
%88 = load i32, i32* %15
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i32, i32* %87, i64 %89
store i32 %85, i32* %90
br label %91
91: ; preds = %82
%92 = load i32, i32* %15
%93 = add nsw i32 %92, 1
store i32 %93, i32* %15
br label %79
94: ; preds = %79
%95 = load i32, i32* %10
%96 = call i32 @ftruncate(i32 %95, i32 16384)
store i32 %96, i32* %12
%97 = load i32, i32* %12
%98 = icmp ne i32 %97, 0
br i1 %98, label %102, label %99
99: ; preds = %94
%100 = load i32, i32* @stderr
%101 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
br label %106
102: ; preds = %94
%103 = load i32, i32* @stderr
%104 = load i32, i32* @errno
%105 = call i32 (i32, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %104)
br label %182
106: ; preds = %99
%107 = load i8*, i8** %13
%108 = load i8*, i8** @MAP_FAILED
%109 = icmp ne i8* %107, %108
br i1 %109, label %110, label %119
110: ; preds = %106
%111 = load i8*, i8** %13
%112 = bitcast i8* %111 to i32*
store i32 3, i32* %112
%113 = load i8*, i8** %13
%114 = bitcast i8* %113 to i32*
%115 = getelementptr inbounds i32, i32* %114, i64 1
store i32 2, i32* %115
%116 = load i8*, i8** %13
%117 = bitcast i8* %116 to i32*
%118 = getelementptr inbounds i32, i32* %117, i64 2
store i32 1, i32* %118
br label %119
119: ; preds = %110, %106
%120 = load i32, i32* @PROT_WRITE
%121 = load i32, i32* @PROT_READ
%122 = or i32 %120, %121
%123 = load i32, i32* @MAP_SHARED
%124 = load i32, i32* %10
%125 = call i8* @mmap(i32* null, i32 8, i32 %122, i32 %123, i32 %124, i32 0)
store i8* %125, i8** %13
%126 = load i8*, i8** %13
%127 = bitcast i8* %126 to i32*
%128 = load i32, i32* %127
%129 = load i8*, i8** %13
%130 = bitcast i8* %129 to i32*
%131 = getelementptr inbounds i32, i32* %130, i64 1
%132 = load i32, i32* %131
%133 = load i8*, i8** %13
%134 = bitcast i8* %133 to i32*
%135 = getelementptr inbounds i32, i32* %134, i64 2
%136 = load i32, i32* %135
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 3, i32 %128, i32 %132, i32 %136)
%138 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0))
%139 = load i8*, i8** %7
%140 = call i64 @shm_unlink(i8* %139)
%141 = icmp ne i64 %140, 0
br i1 %141, label %142, label %145
142: ; preds = %119
%143 = load i32, i32* @errno
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i32 %143)
br label %145
145: ; preds = %142, %119
%146 = load i8*, i8** %13
%147 = bitcast i8* %146 to i32*
%148 = load i32, i32* %147
%149 = load i8*, i8** %13
%150 = bitcast i8* %149 to i32*
%151 = getelementptr inbounds i32, i32* %150, i64 1
%152 = load i32, i32* %151
%153 = load i8*, i8** %13
%154 = bitcast i8* %153 to i32*
%155 = getelementptr inbounds i32, i32* %154, i64 2
%156 = load i32, i32* %155
%157 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 3, i32 %148, i32 %152, i32 %156)
%158 = call i32 (...) @getchar()
%159 = call i32 (...) @fork()
store i32 %159, i32* %6
%160 = load i32, i32* %6
%161 = icmp ne i32 %160, 0
br i1 %161, label %170, label %162
162: ; preds = %145
%163 = call i64 @execl(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32* null)
%164 = icmp slt i64 %163, 0
br i1 %164, label %165, label %169
165: ; preds = %162
%166 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
%167 = load i32, i32* @errno
%168 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i32 %167)
br label %169
169: ; preds = %165, %162
br label %180
170: ; preds = %145
%171 = call i32 @sleep(i32 5)
%172 = load i32, i32* %6
%173 = load i32, i32* @SIGKILL
%174 = call i64 @kill(i32 %172, i32 %173)
%175 = icmp ne i64 %174, 0
br i1 %175, label %176, label %179
176: ; preds = %170
%177 = load i32, i32* @errno
%178 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i32 %177)
br label %179
179: ; preds = %176, %170
br label %180
180: ; preds = %179, %169
%181 = load i32, i32* @EXIT_SUCCESS
store i32 %181, i32* %3
br label %184
182: ; preds = %102, %55, %43
%183 = load i32, i32* @EXIT_FAILURE
store i32 %183, i32* %3
br label %184
184: ; preds = %182, %180
%185 = load i32, i32* %3
ret i32 %185
}

LLVM IR (-O2):
@.str = [24 x i8] c"my random string is %s\0A\00"
@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.1 = [36 x i8] c"the shared memory descriptor is %d\0A\00"
@.str.2 = [36 x i8] c"creating the shared memory succeed\0A\00"
@.str.3 = [22 x i8] c"the error code is %d\0A\00"
@errno = global i32 0
@.str.4 = [38 x i8] c"truncating the shared memory succeed\0A\00"
@PROT_WRITE = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.5 = [4 x i8] c"%d\0A\00"
@.str.6 = [31 x i8] c"the %d parameter is %d %d %d \0A\00"
@.str.8 = [21 x i8] c"unlink error with %d\00"
@.str.9 = [22 x i8] c"./should-be-killed.py\00"
@.str.11 = [13 x i8] c"error is %d\0A\00"
@SIGKILL = global i32 0
@.str.12 = [15 x i8] c"error with %d\0A\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@str = [37 x i8] c"then I will unlink the shared memory\00"
@str.13 = [6 x i8] c"error\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 20)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @random_gen(i8* %4, i32 20)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %4)
%7 = load i32, i32* @O_CREAT
%8 = load i32, i32* @O_RDWR
%9 = or i32 %8, %7
%10 = load i32, i32* @S_IRUSR
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %11, %10
%13 = load i32, i32* @S_IROTH
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IWOTH
%16 = or i32 %14, %15
%17 = tail call i32 @shm_open(i8* %4, i32 %9, i32 %16)
%18 = icmp eq i32 %17, -1
%19 = load i32, i32* @stderr
br i1 %18, label %27, label %20
20: ; preds = %2
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @ftruncate(i32 %17, i32 4)
%25 = icmp eq i32 %24, 0
%26 = load i32, i32* @stderr
br i1 %25, label %30, label %39
27: ; preds = %2
%28 = load i32, i32* @errno
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %28)
br label %117
30: ; preds = %20
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
%32 = load i32, i32* @PROT_WRITE
%33 = load i32, i32* @PROT_READ
%34 = or i32 %33, %32
%35 = load i32, i32* @MAP_SHARED
%36 = tail call i8* @mmap(i32* null, i32 8, i32 %34, i32 %35, i32 %17, i32 0)
%37 = load i8*, i8** @MAP_FAILED
%38 = icmp eq i8* %36, %37
br i1 %38, label %48, label %42
39: ; preds = %20
%40 = load i32, i32* @errno
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %40)
br label %117
42: ; preds = %30
%43 = bitcast i8* %36 to i32*
store i32 2, i32* %43
%44 = getelementptr inbounds i8, i8* %36, i64 4
%45 = bitcast i8* %44 to i32*
store i32 1, i32* %45
%46 = getelementptr inbounds i8, i8* %36, i64 8
%47 = bitcast i8* %46 to i32*
store i32 0, i32* %47
br label %48
48: ; preds = %30, %42
%49 = bitcast i8* %36 to i32*
br label %50
50: ; preds = %48, %50
%51 = phi i64 [ 0, %48 ], [ %55, %50 ]
%52 = trunc i64 %51 to i32
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %52)
%54 = getelementptr inbounds i32, i32* %49, i64 %51
store i32 %52, i32* %54
%55 = add nuw nsw i64 %51, 1
%56 = icmp eq i64 %55, 1000
br i1 %56, label %57, label %50
57: ; preds = %50
%58 = tail call i32 @ftruncate(i32 %17, i32 16384)
%59 = icmp eq i32 %58, 0
%60 = load i32, i32* @stderr
br i1 %59, label %61, label %65
61: ; preds = %57
%62 = tail call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
%63 = load i8*, i8** @MAP_FAILED
%64 = icmp eq i8* %36, %63
br i1 %64, label %73, label %68
65: ; preds = %57
%66 = load i32, i32* @errno
%67 = tail call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %66)
br label %117
68: ; preds = %61
store i32 3, i32* %49
%69 = getelementptr inbounds i8, i8* %36, i64 4
%70 = bitcast i8* %69 to i32*
store i32 2, i32* %70
%71 = getelementptr inbounds i8, i8* %36, i64 8
%72 = bitcast i8* %71 to i32*
store i32 1, i32* %72
br label %73
73: ; preds = %68, %61
%74 = load i32, i32* @PROT_WRITE
%75 = load i32, i32* @PROT_READ
%76 = or i32 %75, %74
%77 = load i32, i32* @MAP_SHARED
%78 = tail call i8* @mmap(i32* null, i32 8, i32 %76, i32 %77, i32 %17, i32 0)
%79 = bitcast i8* %78 to i32*
%80 = load i32, i32* %79
%81 = getelementptr inbounds i8, i8* %78, i64 4
%82 = bitcast i8* %81 to i32*
%83 = load i32, i32* %82
%84 = getelementptr inbounds i8, i8* %78, i64 8
%85 = bitcast i8* %84 to i32*
%86 = load i32, i32* %85
%87 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 3, i32 %80, i32 %83, i32 %86)
%88 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%89 = tail call i64 @shm_unlink(i8* %4)
%90 = icmp eq i64 %89, 0
br i1 %90, label %94, label %91
91: ; preds = %73
%92 = load i32, i32* @errno
%93 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i32 %92)
br label %94
94: ; preds = %91, %73
%95 = load i32, i32* %79
%96 = load i32, i32* %82
%97 = load i32, i32* %85
%98 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 3, i32 %95, i32 %96, i32 %97)
%99 = tail call i32 (...) @getchar()
%100 = tail call i32 (...) @fork()
%101 = icmp eq i32 %100, 0
br i1 %101, label %102, label %109
102: ; preds = %94
%103 = tail call i64 @execl(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32* null)
%104 = icmp slt i64 %103, 0
br i1 %104, label %105, label %117
105: ; preds = %102
%106 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.13, i64 0, i64 0))
%107 = load i32, i32* @errno
%108 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i32 %107)
br label %117
109: ; preds = %94
%110 = tail call i32 @sleep(i32 5)
%111 = load i32, i32* @SIGKILL
%112 = tail call i64 @kill(i32 %100, i32 %111)
%113 = icmp eq i64 %112, 0
br i1 %113, label %117, label %114
114: ; preds = %109
%115 = load i32, i32* @errno
%116 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i32 %115)
br label %117
117: ; preds = %27, %39, %65, %105, %102, %114, %109
%118 = phi i32* [ @EXIT_SUCCESS, %109 ], [ @EXIT_SUCCESS, %114 ], [ @EXIT_SUCCESS, %102 ], [ @EXIT_SUCCESS, %105 ], [ @EXIT_FAILURE, %65 ], [ @EXIT_FAILURE, %39 ], [ @EXIT_FAILURE, %27 ]
%119 = load i32, i32* %118
ret i32 %119
}