#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) {
  }
  if (pipe(fd2) < 0) {
  }
  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    122f <main+0x6f>
jmp    122f <main+0x6f>
lea    -0x430(%rbp),%rdi
call   1090 <pipe@plt>
cmp    $0x0,%rax
jge    124a <main+0x8a>
jmp    124a <main+0x8a>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    12d1 <main+0x111>
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    0xd61(%rip),%rsi
lea    0xd66(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   10d0 <execlp@plt>
lea    0xd5b(%rip),%rdi
call   10c0 <die@plt>
jmp    12ec <main+0x12c>
cmpl   $0x0,-0x14(%rbp)
jge    12e7 <main+0x127>
lea    0xd4e(%rip),%rdi
call   10c0 <die@plt>
jmp    12ec <main+0x12c>
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    0xce6(%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>
lea    0x10(%rsp),%rdi
call   1090 <pipe@plt>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     1235 <main+0x75>
jns    1296 <main+0xd6>
lea    0xdfd(%rip),%rdi
jmp    1291 <main+0xd1>
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    0xd95(%rip),%rdi
lea    0xd9a(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   10d0 <execlp@plt>
lea    0xd91(%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    0xd59(%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"/usr/bin/bc\00"
@.str.3 = [8 x i8] c"--quiet\00"
@.str.4 = [14 x i8] c"execlp failed\00"
@.str.5 = [12 x i8] c"fork failed\00"
@.str.6 = [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 %20
19: ; preds = %0
br label %20
20: ; preds = %19, %0
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%22 = call i64 @pipe(i32* %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
br label %25
25: ; preds = %24, %20
%26 = call i32 (...) @fork()
store i32 %26, i32* %5
%27 = icmp ne i32 %26, 0
br i1 %27, label %49, label %28
28: ; preds = %25
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%30 = load i32, i32* %29
%31 = call i32 @dup2(i32 %30, i32 0)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%33 = load i32, i32* %32
%34 = call i32 @close(i32 %33)
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 @close(i32 %36)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%39 = load i32, i32* %38
%40 = call i32 @dup2(i32 %39, i32 1)
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%42 = load i32, i32* %41
%43 = call i32 @close(i32 %42)
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%45 = load i32, i32* %44
%46 = call i32 @close(i32 %45)
%47 = call i32 @execlp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32* null)
%48 = call i32 @die(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %55
49: ; preds = %25
%50 = load i32, i32* %5
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = call i32 @die(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %54
54: ; preds = %52, %49
br label %55
55: ; preds = %54, %28
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%57 = load i32, i32* %56
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%59 = load i32, i32* %4
%60 = call i32 @write(i32 %57, i8* %58, i32 %59)
%61 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%62 = load i32, i32* %61
%63 = call i32 @close(i32 %62)
%64 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%65 = load i32, i32* %64
%66 = call i32 @close(i32 %65)
%67 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%68 = load i32, i32* %67
%69 = call i32 @close(i32 %68)
%70 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%71 = load i32, i32* %70
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%73 = call i32 @read(i32 %71, i8* %72, i32 1024)
store i32 %73, i32* %4
%74 = load i32, i32* %4
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %75
store i8 0, i8* %76
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%78 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %77)
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"/usr/bin/bc\00"
@.str.3 = [8 x i8] c"--quiet\00"
@.str.4 = [14 x i8] c"execlp failed\00"
@.str.5 = [12 x i8] c"fork failed\00"
@.str.6 = [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 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%19 = call i64 @pipe(i32* %18)
%20 = call i32 (...) @fork()
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %38
22: ; preds = %0
%23 = load i32, i32* %16
%24 = call i32 @dup2(i32 %23, i32 0)
%25 = load i32, i32* %16
%26 = call i32 @close(i32 %25)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%28 = load i32, i32* %27
%29 = call i32 @close(i32 %28)
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%31 = load i32, i32* %30
%32 = call i32 @dup2(i32 %31, i32 1)
%33 = load i32, i32* %18
%34 = call i32 @close(i32 %33)
%35 = load i32, i32* %30
%36 = call i32 @close(i32 %35)
%37 = call i32 @execlp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %40
38: ; preds = %0
%39 = icmp slt i32 %20, 0
br i1 %39, label %40, label %43
40: ; preds = %38, %22
%41 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), %22 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), %38 ]
%42 = call i32 @die(i8* %41)
br label %43
43: ; preds = %40, %38
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%45 = load i32, i32* %44
%46 = call i32 @write(i32 %45, i8* %8, i32 %15)
%47 = load i32, i32* %16
%48 = call i32 @close(i32 %47)
%49 = load i32, i32* %44
%50 = call i32 @close(i32 %49)
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%52 = load i32, i32* %51
%53 = call i32 @close(i32 %52)
%54 = load i32, i32* %18
%55 = call i32 @read(i32 %54, i8* %8, i32 1024)
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %56
store i8 0, i8* %57
%58 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %8)
ret i32 0
}