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

/* Variables and functions */
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int read(int, char *, size_t);
int vfork();
size_t quick_run(char **argv, char *buf, size_t max_len) {
  int pfildes[2];
  if ((pipe(pfildes)) == -1) {
    perror("ERROR [line "
           "29"
           "]");
    exit(1);
  };
  int pid = vfork();
  if (!pid) {
    close(pfildes[0]);
    dup2(pfildes[1], 1);
    close(pfildes[1]);
    execvp(argv[0], argv);
    perror("ERROR [line "
           "36"
           "]");
    _exit(1);
  } else if ((pid) == -1) {
    perror("ERROR [line "
           "38"
           "]");
    exit(1);
  };
  close(pfildes[1]);
  ssize_t size = read(pfildes[0], buf, max_len - 1);
  if ((size) == -1) {
    perror("ERROR [line "
           "41"
           "]");
    exit(1);
  };
  buf[size] = '\0';
  close(pfildes[0]);
  return (size_t)size;
}


x86 assembly (clang, -O0):
<quick_run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11cc <quick_run+0x3c>
lea    0xe43(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
call   1090 <vfork@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1221 <quick_run+0x91>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   10a0 <execvp@plt>
lea    0xdfe(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
cmpl   $0xffffffff,-0x24(%rbp)
jne    1241 <quick_run+0xb1>
lea    0xdee(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1246 <quick_run+0xb6>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    $0x1,%rdx
call   1070 <read@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1285 <quick_run+0xf5>
lea    0xdba(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
movslq -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quick_run>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rsp,%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
je     11fb <quick_run+0x6b>
call   1090 <vfork@plt>
cmp    $0xffffffff,%eax
je     1204 <quick_run+0x74>
test   %eax,%eax
je     120d <quick_run+0x7d>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
mov    (%rsp),%edi
add    $0xffffffffffffffff,%r15
mov    %r12,%rsi
mov    %r15,%rdx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     124c <quick_run+0xbc>
movslq %eax,%rbx
movb   $0x0,(%r12,%rbx,1)
mov    (%rsp),%edi
call   1050 <close@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdfe(%rip),%rdi
jmp    1253 <quick_run+0xc3>
lea    0xe15(%rip),%rdi
jmp    1253 <quick_run+0xc3>
mov    (%rsp),%edi
call   1050 <close@plt>
mov    0x4(%rsp),%edi
mov    $0x1,%ebx
mov    %ebx,%esi
call   1040 <dup2@plt>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
mov    (%r14),%rdi
mov    %r14,%rsi
call   10a0 <execvp@plt>
lea    0xdd0(%rip),%rdi
call   1080 <perror@plt>
mov    %ebx,%edi
call   1030 <_exit@plt>
lea    0xddd(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"ERROR [line 29]\00"
@.str.1 = [16 x i8] c"ERROR [line 36]\00"
@.str.2 = [16 x i8] c"ERROR [line 38]\00"
@.str.3 = [16 x i8] c"ERROR [line 41]\00"
define i64 @quick_run(i8** %0, i8* %1, i64 %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [2 x i32]
%8 = alloca i32
%9 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%11 = call i32 @pipe(i32* %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %3
%17 = call i32 @vfork()
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp ne i32 %18, 0
br i1 %19, label %37, label %20
20: ; preds = %16
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%22 = load i32, i32* %21
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @dup2(i32 %25, i32 1)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%28 = load i32, i32* %27
%29 = call i32 @close(i32 %28)
%30 = load i8**, i8*** %4
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %4
%34 = call i32 @execvp(i8* %32, i8** %33)
%35 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @_exit(i32 1)
unreachable
37: ; preds = %16
%38 = load i32, i32* %8
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %37
br label %44
44: ; preds = %43
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%46 = load i32, i32* %45
%47 = call i32 @close(i32 %46)
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%49 = load i32, i32* %48
%50 = load i8*, i8** %5
%51 = load i64, i64* %6
%52 = sub i64 %51, 1
%53 = call i32 @read(i32 %49, i8* %50, i64 %52)
store i32 %53, i32* %9
%54 = load i32, i32* %9
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %59
56: ; preds = %44
%57 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %44
%60 = load i8*, i8** %5
%61 = load i32, i32* %9
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
store i8 0, i8* %63
%64 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%65 = load i32, i32* %64
%66 = call i32 @close(i32 %65)
%67 = load i32, i32* %9
%68 = sext i32 %67 to i64
ret i64 %68
}

LLVM IR (-O2):
@.str = [16 x i8] c"ERROR [line 29]\00"
@.str.1 = [16 x i8] c"ERROR [line 36]\00"
@.str.2 = [16 x i8] c"ERROR [line 38]\00"
@.str.3 = [16 x i8] c"ERROR [line 41]\00"
define i64 @quick_run(i8** %0, i8* nocapture %1, i64 %2) {
%4 = alloca [2 x i32]
%5 = bitcast [2 x i32]* %4 to i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%7 = call i32 @pipe(i32* %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %3
%13 = call i32 @vfork()
switch i32 %13, label %29 [
i32 0, label %14
i32 -1, label %26
]
14: ; preds = %12
%15 = load i32, i32* %6
%16 = call i32 @close(i32 %15)
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%18 = load i32, i32* %17
%19 = call i32 @dup2(i32 %18, i32 1)
%20 = load i32, i32* %17
%21 = call i32 @close(i32 %20)
%22 = load i8*, i8** %0
%23 = call i32 @execvp(i8* %22, i8** %0)
%24 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @_exit(i32 1)
unreachable
26: ; preds = %12
%27 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %12
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%31 = load i32, i32* %30
%32 = call i32 @close(i32 %31)
%33 = load i32, i32* %6
%34 = add i64 %2, -1
%35 = call i32 @read(i32 %33, i8* %1, i64 %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %29
%38 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %29
%41 = sext i32 %35 to i64
%42 = getelementptr inbounds i8, i8* %1, i64 %41
store i8 0, i8* %42
%43 = load i32, i32* %6
%44 = call i32 @close(i32 %43)
ret i64 %41
}