#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execlp(char *, char *, char *, int /*<<< orphan*/ *);
int fork();
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ scanf(char *, int *, int *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int a, b, blen, pid;
  char buf[1024];
  int fd1[2], fd2[2];
  scanf("%d%d", &a, &b);
  snprintf(buf, sizeof(buf), "%d + %d\n", a, b);
  blen = strlen(buf);
  if (pipe(fd1) < 0)
    die("pipe failed");
  if (pipe(fd2) < 0)
    die("pipe failed");
  if (!(pid = fork())) {
    dup2(fd1[0], 0);
    close(fd1[0]);
    close(fd1[1]);
    dup2(fd2[1], 1);
    close(fd2[0]);
    close(fd2[1]);
    execlp("/usr/bin/bc", "/usr/bin/bc", "--quiet", NULL);
    die("execlp failed");
  } else if (pid < 0) {
    die("fork failed");
  }
  write(fd1[1], buf, blen);
  close(fd1[0]);
  close(fd1[1]);
  close(fd2[1]);
  blen = read(fd2[0], buf, sizeof(buf));
  buf[blen] = 0;
  printf("%s", buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe27(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   10b0 <scanf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    $0x400,%esi
lea    0xe05(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10(%rbp)
lea    -0x428(%rbp),%rdi
call   1090 <pipe@plt>
cmp    $0x0,%rax
jge    1236 <main+0x76>
lea    0xddd(%rip),%rdi
call   10c0 <die@plt>
lea    -0x430(%rbp),%rdi
call   1090 <pipe@plt>
cmp    $0x0,%rax
jge    1258 <main+0x98>
lea    0xdbb(%rip),%rdi
call   10c0 <die@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    12df <main+0x11f>
mov    -0x428(%rbp),%edi
xor    %esi,%esi
call   1050 <dup2@plt>
mov    -0x428(%rbp),%edi
call   1080 <close@plt>
mov    -0x424(%rbp),%edi
call   1080 <close@plt>
mov    -0x42c(%rbp),%edi
mov    $0x1,%esi
call   1050 <dup2@plt>
mov    -0x430(%rbp),%edi
call   1080 <close@plt>
mov    -0x42c(%rbp),%edi
call   1080 <close@plt>
lea    0xd5f(%rip),%rsi
lea    0xd64(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   10d0 <execlp@plt>
lea    0xd59(%rip),%rdi
call   10c0 <die@plt>
jmp    12fa <main+0x13a>
cmpl   $0x0,-0x14(%rbp)
jge    12f5 <main+0x135>
lea    0xd4c(%rip),%rdi
call   10c0 <die@plt>
jmp    12fa <main+0x13a>
mov    -0x424(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <write@plt>
mov    -0x428(%rbp),%edi
call   1080 <close@plt>
mov    -0x424(%rbp),%edi
call   1080 <close@plt>
mov    -0x42c(%rbp),%edi
call   1080 <close@plt>
mov    -0x430(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
mov    %eax,-0x10(%rbp)
movslq -0x10(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rsi
lea    0xce4(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x428,%rsp
lea    0xe30(%rip),%rdi
lea    0x1c(%rsp),%rsi
lea    0x18(%rsp),%rdx
call   10b0 <scanf@plt>
mov    0x1c(%rsp),%ecx
mov    0x18(%rsp),%r8d
lea    0xe16(%rip),%rdx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1070 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%rdi
call   1090 <pipe@plt>
test   %rax,%rax
jns    1226 <main+0x66>
lea    0xded(%rip),%rdi
call   10c0 <die@plt>
lea    0x10(%rsp),%rdi
call   1090 <pipe@plt>
test   %rax,%rax
jns    1241 <main+0x81>
lea    0xdd2(%rip),%rdi
call   10c0 <die@plt>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     1257 <main+0x97>
jns    12b8 <main+0xf8>
lea    0xde7(%rip),%rdi
jmp    12b3 <main+0xf3>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1050 <dup2@plt>
mov    0x8(%rsp),%edi
call   1080 <close@plt>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
mov    0x14(%rsp),%edi
mov    $0x1,%esi
call   1050 <dup2@plt>
mov    0x10(%rsp),%edi
call   1080 <close@plt>
mov    0x14(%rsp),%edi
call   1080 <close@plt>
lea    0xd7f(%rip),%rdi
lea    0xd84(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   10d0 <execlp@plt>
lea    0xd7b(%rip),%rdi
call   10c0 <die@plt>
mov    0xc(%rsp),%edi
lea    0x20(%rsp),%rbx
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
mov    0x8(%rsp),%edi
call   1080 <close@plt>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
mov    0x14(%rsp),%edi
call   1080 <close@plt>
mov    0x10(%rsp),%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
lea    0xd43(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x428,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d%d\00"
@.str.1 = [9 x i8] c"%d + %d\0A\00"
@.str.2 = [12 x i8] c"pipe failed\00"
@.str.3 = [12 x i8] c"/usr/bin/bc\00"
@.str.4 = [8 x i8] c"--quiet\00"
@.str.5 = [14 x i8] c"execlp failed\00"
@.str.6 = [12 x i8] c"fork failed\00"
@.str.7 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca [2 x i32]
%8 = alloca [2 x i32]
store i32 0, i32* %1
%9 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = load i32, i32* %2
%12 = load i32, i32* %3
%13 = call i32 @snprintf(i8* %10, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %4
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%17 = call i64 @pipe(i32* %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %0
%20 = call i32 @die(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %0
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%23 = call i64 @pipe(i32* %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @die(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = call i32 (...) @fork()
store i32 %28, i32* %5
%29 = icmp ne i32 %28, 0
br i1 %29, label %51, label %30
30: ; preds = %27
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%32 = load i32, i32* %31
%33 = call i32 @dup2(i32 %32, i32 0)
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%35 = load i32, i32* %34
%36 = call i32 @close(i32 %35)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%38 = load i32, i32* %37
%39 = call i32 @close(i32 %38)
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%41 = load i32, i32* %40
%42 = call i32 @dup2(i32 %41, i32 1)
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%44 = load i32, i32* %43
%45 = call i32 @close(i32 %44)
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%47 = load i32, i32* %46
%48 = call i32 @close(i32 %47)
%49 = call i32 @execlp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32* null)
%50 = call i32 @die(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %57
51: ; preds = %27
%52 = load i32, i32* %5
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 @die(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br label %56
56: ; preds = %54, %51
br label %57
57: ; preds = %56, %30
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%59 = load i32, i32* %58
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%61 = load i32, i32* %4
%62 = call i32 @write(i32 %59, i8* %60, i32 %61)
%63 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%64 = load i32, i32* %63
%65 = call i32 @close(i32 %64)
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%67 = load i32, i32* %66
%68 = call i32 @close(i32 %67)
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%70 = load i32, i32* %69
%71 = call i32 @close(i32 %70)
%72 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%73 = load i32, i32* %72
%74 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%75 = call i32 @read(i32 %73, i8* %74, i32 1024)
store i32 %75, i32* %4
%76 = load i32, i32* %4
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %77
store i8 0, i8* %78
%79 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%80 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %79)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d%d\00"
@.str.1 = [9 x i8] c"%d + %d\0A\00"
@.str.2 = [12 x i8] c"pipe failed\00"
@.str.3 = [12 x i8] c"/usr/bin/bc\00"
@.str.4 = [8 x i8] c"--quiet\00"
@.str.5 = [14 x i8] c"execlp failed\00"
@.str.6 = [12 x i8] c"fork failed\00"
@.str.7 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca [2 x i32]
%5 = alloca [2 x i32]
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = bitcast [2 x i32]* %4 to i8*
%10 = bitcast [2 x i32]* %5 to i8*
%11 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%12 = load i32, i32* %1
%13 = load i32, i32* %2
%14 = call i32 @snprintf(i8* %8, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %13)
%15 = call i32 @strlen(i8* %8)
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%17 = call i64 @pipe(i32* %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %0
%20 = call i32 @die(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %0
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%23 = call i64 @pipe(i32* %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @die(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = call i32 (...) @fork()
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %46
30: ; preds = %27
%31 = load i32, i32* %16
%32 = call i32 @dup2(i32 %31, i32 0)
%33 = load i32, i32* %16
%34 = call i32 @close(i32 %33)
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 @close(i32 %36)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%39 = load i32, i32* %38
%40 = call i32 @dup2(i32 %39, i32 1)
%41 = load i32, i32* %22
%42 = call i32 @close(i32 %41)
%43 = load i32, i32* %38
%44 = call i32 @close(i32 %43)
%45 = call i32 @execlp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32* null)
br label %48
46: ; preds = %27
%47 = icmp slt i32 %28, 0
br i1 %47, label %48, label %51
48: ; preds = %46, %30
%49 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), %30 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), %46 ]
%50 = call i32 @die(i8* %49)
br label %51
51: ; preds = %48, %46
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%53 = load i32, i32* %52
%54 = call i32 @write(i32 %53, i8* %8, i32 %15)
%55 = load i32, i32* %16
%56 = call i32 @close(i32 %55)
%57 = load i32, i32* %52
%58 = call i32 @close(i32 %57)
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%60 = load i32, i32* %59
%61 = call i32 @close(i32 %60)
%62 = load i32, i32* %22
%63 = call i32 @read(i32 %62, i8* %8, i32 1024)
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %64
store i8 0, i8* %65
%66 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %8)
ret i32 0
}