#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
scalar_t__ dup2(int, int);
int /*<<< orphan*/ execl(char *, char *, char const *, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
scalar_t__ malloc(unsigned int);
scalar_t__ pipe(int *);
int /*<<< orphan*/ read(int, char *, unsigned int);
const char *call_python(const char *filename) {
  int pipes[2];
  assert(pipe(pipes) >= 0);
  pid_t childpid = fork();
  assert(childpid >= 0);
  if (childpid == 0) {
    assert(dup2(pipes[1], 1) >= 0);
    assert(dup2(pipes[1], 2) >= 0);
    close(pipes[0]);
    close(pipes[1]);
    execl("/usr/bin/python", "/usr/bin/python", filename, "--no-alarm",
          (char *)0);
    exit(0);
  }
  close(pipes[1]);
  unsigned size = 20;
  char *buffer = (char *)malloc(size * sizeof(char));
  read(pipes[0], buffer, size);
  close(pipes[0]);
  return buffer;
}


x86 assembly (clang, -O0):
<call_python>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0x0,%rax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1250 <call_python+0xc0>
mov    -0xc(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
cmp    $0x0,%rax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0xc(%rbp),%edi
mov    $0x2,%esi
call   1030 <dup2@plt>
cmp    $0x0,%rax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%rdx
lea    0xdcb(%rip),%rsi
lea    0xdd4(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   10a0 <execl@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
movl   $0x14,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <read@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<call_python>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rsp,%rdi
call   1050 <pipe@plt>
shr    $0x3f,%rax
xor    $0x1,%eax
mov    %eax,%edi
call   1070 <assert@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
mov    %rax,%rbx
mov    %rax,%rdi
shr    $0x3f,%rdi
xor    $0x1,%edi
call   1070 <assert@plt>
mov    0x4(%rsp),%edi
test   %rbx,%rbx
je     1204 <call_python+0x74>
call   1040 <close@plt>
mov    $0x14,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    (%rsp),%edi
mov    %rax,%rsi
mov    $0x14,%edx
call   1060 <read@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x1,%esi
call   1030 <dup2@plt>
shr    $0x3f,%rax
xor    $0x1,%eax
mov    %eax,%edi
call   1070 <assert@plt>
mov    0x4(%rsp),%edi
mov    $0x2,%esi
call   1030 <dup2@plt>
shr    $0x3f,%rax
xor    $0x1,%eax
mov    %eax,%edi
call   1070 <assert@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
lea    0xdb0(%rip),%rdi
lea    0xdb9(%rip),%rcx
mov    %rdi,%rsi
mov    %r14,%rdx
xor    %r8d,%r8d
call   10a0 <execl@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"/usr/bin/python\00"
@.str.1 = [11 x i8] c"--no-alarm\00"
define i8* @call_python(i8* %0) {
%2 = alloca i8*
%3 = alloca [2 x i32]
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %2
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%8 = call i64 @pipe(i32* %7)
%9 = icmp sge i64 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = call i64 (...) @fork()
store i64 %12, i64* %4
%13 = load i64, i64* %4
%14 = icmp sge i64 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i64, i64* %4
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %41
19: ; preds = %1
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%21 = load i32, i32* %20
%22 = call i64 @dup2(i32 %21, i32 1)
%23 = icmp sge i64 %22, 0
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%27 = load i32, i32* %26
%28 = call i64 @dup2(i32 %27, i32 2)
%29 = icmp sge i64 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%33 = load i32, i32* %32
%34 = call i32 @close(i32 %33)
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 @close(i32 %36)
%38 = load i8*, i8** %2
%39 = call i32 @execl(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %38, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* null)
%40 = call i32 @exit(i32 0)
unreachable
41: ; preds = %1
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%43 = load i32, i32* %42
%44 = call i32 @close(i32 %43)
store i32 20, i32* %5
%45 = load i32, i32* %5
%46 = zext i32 %45 to i64
%47 = mul i64 %46, 1
%48 = trunc i64 %47 to i32
%49 = call i64 @malloc(i32 %48)
%50 = inttoptr i64 %49 to i8*
store i8* %50, i8** %6
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%52 = load i32, i32* %51
%53 = load i8*, i8** %6
%54 = load i32, i32* %5
%55 = call i32 @read(i32 %52, i8* %53, i32 %54)
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%57 = load i32, i32* %56
%58 = call i32 @close(i32 %57)
%59 = load i8*, i8** %6
ret i8* %59
}

LLVM IR (-O2):
@.str = [16 x i8] c"/usr/bin/python\00"
@.str.1 = [11 x i8] c"--no-alarm\00"
define i8* @call_python(i8* %0) {
%2 = alloca [2 x i32]
%3 = bitcast [2 x i32]* %2 to i8*
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%5 = call i64 @pipe(i32* %4)
%6 = lshr i64 %5, 63
%7 = trunc i64 %6 to i32
%8 = xor i32 %7, 1
%9 = call i32 @assert(i32 %8)
%10 = call i64 (...) @fork()
%11 = lshr i64 %10, 63
%12 = trunc i64 %11 to i32
%13 = xor i32 %12, 1
%14 = call i32 @assert(i32 %13)
%15 = icmp eq i64 %10, 0
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%17 = load i32, i32* %16
br i1 %15, label %18, label %36
18: ; preds = %1
%19 = call i64 @dup2(i32 %17, i32 1)
%20 = lshr i64 %19, 63
%21 = trunc i64 %20 to i32
%22 = xor i32 %21, 1
%23 = call i32 @assert(i32 %22)
%24 = load i32, i32* %16
%25 = call i64 @dup2(i32 %24, i32 2)
%26 = lshr i64 %25, 63
%27 = trunc i64 %26 to i32
%28 = xor i32 %27, 1
%29 = call i32 @assert(i32 %28)
%30 = load i32, i32* %4
%31 = call i32 @close(i32 %30)
%32 = load i32, i32* %16
%33 = call i32 @close(i32 %32)
%34 = call i32 @execl(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* null)
%35 = call i32 @exit(i32 0)
unreachable
36: ; preds = %1
%37 = call i32 @close(i32 %17)
%38 = call i64 @malloc(i32 20)
%39 = inttoptr i64 %38 to i8*
%40 = load i32, i32* %4
%41 = call i32 @read(i32 %40, i8* %39, i32 20)
%42 = load i32, i32* %4
%43 = call i32 @close(i32 %42)
ret i8* %39
}