#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 */
float NAN;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char **, int);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ write(int, char **, int);
int main(int argc, char const *argv[]) {
  int fd[2];
  if (pipe(fd) < 0) {
    perror("pipe");
    exit(1);
  }
  pid_t pid = fork();
  if (pid < 0) {
    perror("fork");
    exit(1);
  } else if (pid > 0) {
    char num1[10], num2[10];
    printf("First number: ");
    scanf("%10s", num1);
    printf("Second number: ");
    scanf("%10s", num2);
    close(fd[0]);
    write(fd[1], &num1, 10);
    write(fd[1], &num2, 10);
  } else {
    char num1s[10], num2s[10];
    close(fd[1]);
    read(fd[0], &num1s, 10);
    read(fd[0], &num2s, 10);
    int num1 = atoi(num1s);
    int num2 = atoi(num2s);
    int sum = num1 + num2;
    int diff = num1 - num2;
    int mul = num1 * num2;
    float div;
    if (num2 != 0)
      div = (float)num1 / (float)num2;
    else
      div = NAN;
    printf("Sum: %d, Diff: %d, Mul: %d, Div: %f\n", sum, diff, mul, div);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
jge    11df <main+0x3f>
lea    0xe30(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    120b <main+0x6b>
lea    0xe09(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jle    1281 <main+0xe1>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x2a(%rbp),%rsi
lea    0xdea(%rip),%rdi
call   1080 <scanf@plt>
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x34(%rbp),%rsi
lea    0xdcc(%rip),%rdi
call   1080 <scanf@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%edi
lea    -0x2a(%rbp),%rsi
mov    $0xa,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
lea    -0x34(%rbp),%rsi
mov    $0xa,%edx
call   1030 <write@plt>
jmp    1331 <main+0x191>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
lea    -0x3e(%rbp),%rsi
mov    $0xa,%edx
call   1070 <read@plt>
mov    -0x18(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    $0xa,%edx
call   1070 <read@plt>
lea    -0x3e(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x4c(%rbp)
lea    -0x48(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x50(%rbp)
mov    -0x4c(%rbp),%eax
add    -0x50(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x4c(%rbp),%eax
sub    -0x50(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x4c(%rbp),%eax
imul   -0x50(%rbp),%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x50(%rbp)
je     1301 <main+0x161>
cvtsi2ssl -0x4c(%rbp),%xmm0
cvtsi2ssl -0x50(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x60(%rbp)
jmp    1311 <main+0x171>
mov    0x2cf0(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x60(%rbp)
mov    -0x54(%rbp),%esi
mov    -0x58(%rbp),%edx
mov    -0x5c(%rbp),%ecx
movss  -0x60(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd04(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1336 <main+0x196>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0x4(%rsp),%rdi
call   1060 <pipe@plt>
test   %rax,%rax
js     12cf <main+0x12f>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
js     12d8 <main+0x138>
je     1241 <main+0xa1>
lea    0xe35(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe36(%rip),%rbx
lea    0x16(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <scanf@plt>
lea    0xe24(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
mov    0x8(%rsp),%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <write@plt>
mov    0x8(%rsp),%edi
mov    %r15,%rsi
mov    $0xa,%edx
call   1030 <write@plt>
jmp    12c3 <main+0x123>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    0x4(%rsp),%edi
lea    0x16(%rsp),%rbx
mov    %rbx,%rsi
mov    $0xa,%edx
call   1070 <read@plt>
mov    0x4(%rsp),%edi
lea    0xc(%rsp),%r14
mov    %r14,%rsi
mov    $0xa,%edx
call   1070 <read@plt>
mov    %rbx,%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   10a0 <atoi@plt>
lea    (%rax,%rbx,1),%esi
mov    %ebx,%edx
sub    %eax,%edx
mov    %eax,%ecx
imul   %ebx,%ecx
test   %eax,%eax
je     12a6 <main+0x106>
cvtsi2ss %ebx,%xmm0
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
jmp    12b1 <main+0x111>
mov    0x2d4b(%rip),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd72(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd2a(%rip),%rdi
jmp    12df <main+0x13f>
lea    0xd26(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [15 x i8] c"First number: \00"
@.str.3 = [5 x i8] c"%10s\00"
@.str.4 = [16 x i8] c"Second number: \00"
@NAN = global float 0.000000e+00
@.str.5 = [37 x i8] c"Sum: %d, Diff: %d, Mul: %d, Div: %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i64
%8 = alloca [10 x i8]
%9 = alloca [10 x i8]
%10 = alloca [10 x i8]
%11 = alloca [10 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%19 = call i64 @pipe(i32* %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
%25 = call i64 (...) @fork()
store i64 %25, i64* %7
%26 = load i64, i64* %7
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %24
%32 = load i64, i64* %7
%33 = icmp sgt i64 %32, 0
br i1 %33, label %34, label %52
34: ; preds = %31
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%36 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%37 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%39 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%40 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%42 = load i32, i32* %41
%43 = call i32 @close(i32 %42)
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%45 = load i32, i32* %44
%46 = bitcast [10 x i8]* %8 to i8**
%47 = call i32 @write(i32 %45, i8** %46, i32 10)
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%49 = load i32, i32* %48
%50 = bitcast [10 x i8]* %9 to i8**
%51 = call i32 @write(i32 %49, i8** %50, i32 10)
br label %94
52: ; preds = %31
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%54 = load i32, i32* %53
%55 = call i32 @close(i32 %54)
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%57 = load i32, i32* %56
%58 = bitcast [10 x i8]* %10 to i8**
%59 = call i32 @read(i32 %57, i8** %58, i32 10)
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%61 = load i32, i32* %60
%62 = bitcast [10 x i8]* %11 to i8**
%63 = call i32 @read(i32 %61, i8** %62, i32 10)
%64 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%65 = call i32 @atoi(i8* %64)
store i32 %65, i32* %12
%66 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%67 = call i32 @atoi(i8* %66)
store i32 %67, i32* %13
%68 = load i32, i32* %12
%69 = load i32, i32* %13
%70 = add nsw i32 %68, %69
store i32 %70, i32* %14
%71 = load i32, i32* %12
%72 = load i32, i32* %13
%73 = sub nsw i32 %71, %72
store i32 %73, i32* %15
%74 = load i32, i32* %12
%75 = load i32, i32* %13
%76 = mul nsw i32 %74, %75
store i32 %76, i32* %16
%77 = load i32, i32* %13
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %85
79: ; preds = %52
%80 = load i32, i32* %12
%81 = sitofp i32 %80 to float
%82 = load i32, i32* %13
%83 = sitofp i32 %82 to float
%84 = fdiv float %81, %83
store float %84, float* %17
br label %87
85: ; preds = %52
%86 = load float, float* @NAN
store float %86, float* %17
br label %87
87: ; preds = %85, %79
%88 = load i32, i32* %14
%89 = load i32, i32* %15
%90 = load i32, i32* %16
%91 = load float, float* %17
%92 = fpext float %91 to double
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %88, i32 %89, i32 %90, double %92)
br label %94
94: ; preds = %87, %34
br label %95
95: ; preds = %94
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [15 x i8] c"First number: \00"
@.str.3 = [5 x i8] c"%10s\00"
@.str.4 = [16 x i8] c"Second number: \00"
@NAN = global float 0.000000e+00
@.str.5 = [37 x i8] c"Sum: %d, Diff: %d, Mul: %d, Div: %f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca [10 x i8]
%5 = alloca [10 x i8]
%6 = alloca [10 x i8]
%7 = alloca [10 x i8]
%8 = bitcast [2 x i32]* %3 to i8*
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%10 = call i64 @pipe(i32* %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = call i64 (...) @fork()
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = icmp eq i64 %16, 0
br i1 %22, label %39, label %23
23: ; preds = %21
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%30 = load i32, i32* %9
%31 = call i32 @close(i32 %30)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%33 = load i32, i32* %32
%34 = bitcast [10 x i8]* %4 to i8**
%35 = call i32 @write(i32 %33, i8** %34, i32 10)
%36 = load i32, i32* %32
%37 = bitcast [10 x i8]* %5 to i8**
%38 = call i32 @write(i32 %36, i8** %37, i32 10)
br label %67
39: ; preds = %21
%40 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%41 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%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)
%45 = load i32, i32* %9
%46 = bitcast [10 x i8]* %6 to i8**
%47 = call i32 @read(i32 %45, i8** %46, i32 10)
%48 = load i32, i32* %9
%49 = bitcast [10 x i8]* %7 to i8**
%50 = call i32 @read(i32 %48, i8** %49, i32 10)
%51 = call i32 @atoi(i8* %40)
%52 = call i32 @atoi(i8* %41)
%53 = add nsw i32 %52, %51
%54 = sub nsw i32 %51, %52
%55 = mul nsw i32 %52, %51
%56 = icmp eq i32 %52, 0
br i1 %56, label %61, label %57
57: ; preds = %39
%58 = sitofp i32 %51 to float
%59 = sitofp i32 %52 to float
%60 = fdiv float %58, %59
br label %63
61: ; preds = %39
%62 = load float, float* @NAN
br label %63
63: ; preds = %61, %57
%64 = phi float [ %60, %57 ], [ %62, %61 ]
%65 = fpext float %64 to double
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %53, i32 %54, i32 %55, double %65)
br label %67
67: ; preds = %23, %63
ret i32 0
}