#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;
int /*<<< orphan*/ SEEK_SET;
int errno;
scalar_t__ execl(char *, char *, char *, char *, char *, char *,
                 int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(void *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ random_gen(char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  pid_t my_pid;
  char *my_string;
  int size;
  FILE *fp = NULL;
  int socket_args[3] = {2, 1, 0};
  int ret = -1;
  my_string = (char *)malloc(sizeof(char) * 20);
  random_gen(my_string, 20);
  printf("my random string is %s\n", my_string);
  fp = fopen("hehe", "w+");
  if (fp == NULL) {
    printf("error is %d\n", errno);
    goto failed_exit;
  }
  fwrite((void *)socket_args, sizeof(int), 3, fp);
  fflush(fp);
  my_pid = fork();
  if (!my_pid) {
    if (execl("./py-proxy.py", "./py-proxy.py", "-f", "hehe", "-t", "0", NULL) <
        0) {
      printf("error\n");
      printf("error is %d\n", errno);
    }
  } else {
    sleep(3);
    waitpid(my_pid, NULL, 0);
  }
  fseek(fp, 0, SEEK_SET);
  fread(&ret, sizeof(int), 1, fp);
  printf("the return value is %d\n", ret);
  if (ret > 0) {
    return EXIT_SUCCESS;
  } else {
  failed_exit:
    return EXIT_FAILURE;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
mov    0xe1b(%rip),%rax
mov    %rax,-0x3c(%rbp)
mov    0xe19(%rip),%eax
mov    %eax,-0x34(%rbp)
movl   $0xffffffff,-0x40(%rbp)
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x14,%esi
call   10b0 <random_gen@plt>
mov    -0x20(%rbp),%rsi
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdf6(%rip),%rdi
lea    0xdf4(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1265 <main+0xa5>
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1376 <main+0x1b6>
lea    -0x3c(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x4,%esi
mov    $0x3,%edx
call   10a0 <fwrite@plt>
mov    -0x30(%rbp),%rdi
call   1060 <fflush@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1302 <main+0x142>
lea    0xd99(%rip),%rsi
lea    0xda0(%rip),%rdx
lea    0xd76(%rip),%rcx
lea    0xd95(%rip),%r8
lea    0xd91(%rip),%r9
xor    %eax,%eax
mov    %rsi,%rdi
movq   $0x0,(%rsp)
call   10c0 <execl@plt>
cmp    $0x0,%rax
jge    12fd <main+0x13d>
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2cf3(%rip),%rax
mov    (%rax),%esi
lea    0xd36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    131a <main+0x15a>
mov    $0x3,%edi
call   10d0 <sleep@plt>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1080 <waitpid@plt>
mov    -0x30(%rbp),%rdi
mov    0x2cb3(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x30(%rbp),%rcx
lea    -0x40(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x40(%rbp),%esi
lea    0xd07(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x40(%rbp)
jle    1371 <main+0x1b1>
mov    0x2c61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1382 <main+0x1c2>
jmp    1376 <main+0x1b6>
mov    0x2c53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    0xe2c(%rip),%eax
mov    %eax,0x20(%rsp)
mov    0xe19(%rip),%rax
mov    %rax,0x18(%rsp)
movl   $0xffffffff,0x14(%rsp)
ff
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x14,%esi
call   10c0 <random_gen@plt>
lea    0xdf7(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdfe(%rip),%rdi
lea    0xdfc(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     127d <main+0xad>
mov    %rax,%rbx
lea    0x18(%rsp),%rdi
mov    $0x4,%esi
mov    $0x3,%edx
mov    %rax,%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     1299 <main+0xc9>
mov    %eax,%ebp
mov    $0x3,%edi
call   10e0 <sleep@plt>
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <waitpid@plt>
jmp    12f4 <main+0x124>
mov    0x2d5c(%rip),%rax
mov    (%rax),%esi
lea    0xd9f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    133f <main+0x16f>
movq   $0x0,(%rsp)
lea    0xd91(%rip),%rdi
lea    0xd98(%rip),%rdx
lea    0xd6e(%rip),%rcx
lea    0xd8d(%rip),%r8
lea    0xd89(%rip),%r9
mov    %rdi,%rsi
call   10d0 <execl@plt>
test   %rax,%rax
jns    12f4 <main+0x124>
lea    0xd8f(%rip),%rdi
call   1030 <puts@plt>
mov    0x2cfc(%rip),%rax
mov    (%rax),%esi
lea    0xd3f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2cdd(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
lea    0x14(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    0x14(%rsp),%ebx
lea    0xd26(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
jle    133f <main+0x16f>
mov    0x2c8b(%rip),%rax
jmp    1346 <main+0x176>
mov    0x2c8a(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

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"
@.str.1 = [5 x i8] c"hehe\00"
@.str.2 = [3 x i8] c"w+\00"
@.str.3 = [13 x i8] c"error is %d\0A\00"
@errno = global i32 0
@.str.4 = [14 x i8] c"./py-proxy.py\00"
@.str.5 = [3 x i8] c"-f\00"
@.str.6 = [3 x i8] c"-t\00"
@.str.7 = [2 x i8] c"0\00"
@.str.8 = [7 x i8] c"error\0A\00"
@SEEK_SET = global i32 0
@.str.9 = [24 x i8] c"the return value is %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 [3 x i32]
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %9
%12 = bitcast [3 x i32]* %10 to i8*
store i32 -1, i32* %11
%13 = call i64 @malloc(i32 20)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = call i32 @random_gen(i8* %15, i32 20)
%17 = load i8*, i8** %7
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %19, i32** %9
%20 = load i32*, i32** %9
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = load i32, i32* @errno
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %23)
br label %60
25: ; preds = %2
%26 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 0
%27 = bitcast i32* %26 to i8*
%28 = load i32*, i32** %9
%29 = call i32 @fwrite(i8* %27, i32 4, i32 3, i32* %28)
%30 = load i32*, i32** %9
%31 = call i32 @fflush(i32* %30)
%32 = call i32 (...) @fork()
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp ne i32 %33, 0
br i1 %34, label %43, label %35
35: ; preds = %25
%36 = call i64 @execl(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32* null)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%40 = load i32, i32* @errno
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %38, %35
br label %47
43: ; preds = %25
%44 = call i32 @sleep(i32 3)
%45 = load i32, i32* %6
%46 = call i32 @waitpid(i32 %45, i32* null, i32 0)
br label %47
47: ; preds = %43, %42
%48 = load i32*, i32** %9
%49 = load i32, i32* @SEEK_SET
%50 = call i32 @fseek(i32* %48, i32 0, i32 %49)
%51 = load i32*, i32** %9
%52 = call i32 @fread(i32* %11, i32 4, i32 1, i32* %51)
%53 = load i32, i32* %11
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i32 %53)
%55 = load i32, i32* %11
%56 = icmp sgt i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %47
%58 = load i32, i32* @EXIT_SUCCESS
store i32 %58, i32* %3
br label %62
59: ; preds = %47
br label %60
60: ; preds = %59, %22
%61 = load i32, i32* @EXIT_FAILURE
store i32 %61, i32* %3
br label %62
62: ; preds = %60, %57
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@__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"
@.str.1 = [5 x i8] c"hehe\00"
@.str.2 = [3 x i8] c"w+\00"
@.str.3 = [13 x i8] c"error is %d\0A\00"
@errno = global i32 0
@.str.4 = [14 x i8] c"./py-proxy.py\00"
@.str.5 = [3 x i8] c"-f\00"
@.str.6 = [3 x i8] c"-t\00"
@.str.7 = [2 x i8] c"0\00"
@SEEK_SET = global i32 0
@.str.9 = [24 x i8] c"the return value is %d\0A\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@str = [6 x i8] c"error\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x i32]
%4 = alloca i32
%5 = bitcast [3 x i32]* %3 to i8*
%6 = bitcast i32* %4 to i8*
store i32 -1, i32* %4
%7 = tail call i64 @malloc(i32 20)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @random_gen(i8* %8, i32 20)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %8)
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @errno
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %14)
br label %38
16: ; preds = %2
%17 = call i32 @fwrite(i8* %5, i32 4, i32 3, i32* %11)
%18 = tail call i32 @fflush(i32* %11)
%19 = tail call i32 (...) @fork()
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %16
%22 = tail call i64 @execl(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32* null)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%26 = load i32, i32* @errno
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %26)
br label %31
28: ; preds = %16
%29 = tail call i32 @sleep(i32 3)
%30 = tail call i32 @waitpid(i32 %19, i32* null, i32 0)
br label %31
31: ; preds = %21, %24, %28
%32 = load i32, i32* @SEEK_SET
%33 = tail call i32 @fseek(i32* %11, i32 0, i32 %32)
%34 = call i32 @fread(i32* %4, i32 4, i32 1, i32* %11)
%35 = load i32, i32* %4
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i32 %35)
%37 = icmp sgt i32 %35, 0
br i1 %37, label %39, label %38
38: ; preds = %31, %13
br label %39
39: ; preds = %31, %38
%40 = phi i32* [ @EXIT_FAILURE, %38 ], [ @EXIT_SUCCESS, %31 ]
%41 = load i32, i32* %40
ret i32 %41
}