#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*/ values;
typedef scalar_t__ pid_t;

/* Variables and functions */
double NAN;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, int **, int);
int /*<<< orphan*/ scanf(char *, int *, int *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, int *, int);
int main(int argc, char const *argv[]) {
  int fd[2];
  if (pipe(fd) == -1) {
    perror("pipe");
    exit(1);
  }
  pid_t pid;
  pid = fork();
  if (pid < 0) {
    perror("fork");
    exit(1);
  } else if (pid == 0) {
    close(fd[1]);
    int values[2];
    read(fd[0], &values, sizeof(values));
    printf("%d + %d = %d\n", values[0], values[1], values[0] + values[1]);
    printf("%d - %d = %d\n", values[0], values[1], values[0] - values[1]);
    printf("%d * %d = %d\n", values[0], values[1], values[0] * values[1]);
    printf("%d / %d = ", values[0], values[1]);
    if (values[1] != 0)
      printf("%f\n", (float)values[0] / (float)values[1]);
    else
      printf("%f\n", NAN);
    close(fd[0]);
    _exit(0);
  } else if (pid > 0) {
    close(fd[0]);
    int values[2];
    printf("Insert two comma separated integers (example: 1, 2): ");
    fflush(stdout);
    scanf("%10d, %10d", &values[0], &values[1]);
    write(fd[1], values, sizeof(values));
    wait(NULL);
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11f7 <main+0x37>
lea    0xe18(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1223 <main+0x63>
lea    0xdf1(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1301 <main+0x141>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1080 <read@plt>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
add    -0x24(%rbp),%ecx
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
sub    -0x24(%rbp),%ecx
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
imul   -0x24(%rbp),%ecx
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x24(%rbp)
je     12d9 <main+0x119>
cvtsi2ssl -0x28(%rbp),%xmm0
cvtsi2ssl -0x24(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd72(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    12f2 <main+0x132>
mov    0x2d18(%rip),%rax
movsd  (%rax),%xmm0
lea    0xd54(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
cmpq   $0x0,-0x20(%rbp)
jle    1369 <main+0x1a9>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
lea    0xd28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
lea    -0x30(%rbp),%rsi
lea    -0x30(%rbp),%rdx
add    $0x4,%rdx
lea    0xd36(%rip),%rdi
call   10a0 <scanf@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x8,%edx
call   1040 <write@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <wait@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
jmp    136e <main+0x1ae>
jmp    1373 <main+0x1b3>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11df <main+0x1f>
lea    0xe23(%rip),%rdi
jmp    11f2 <main+0x32>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %rax,%rax
jns    1201 <main+0x41>
lea    0xe13(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jne    1298 <main+0xd8>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x8,%edx
call   1080 <read@plt>
mov    0x10(%rsp),%r14d
mov    0x14(%rsp),%ebx
lea    (%rbx,%r14,1),%ecx
lea    0xdd3(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%ecx
sub    %ebx,%ecx
lea    0xdc9(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%ecx
imul   %r14d,%ecx
lea    0xdbe(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdb9(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
jne    12f5 <main+0x135>
mov    0x2d66(%rip),%rax
movsd  (%rax),%xmm0
jmp    1306 <main+0x146>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
lea    0xd9b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
lea    0x14(%rsp),%rdx
lea    0xdb0(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   10a0 <scanf@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1040 <write@plt>
xor    %edi,%edi
call   10d0 <wait@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
cvtsi2ss %r14d,%xmm0
cvtsi2ss %ebx,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd32(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [14 x i8] c"%d + %d = %d\0A\00"
@.str.3 = [14 x i8] c"%d - %d = %d\0A\00"
@.str.4 = [14 x i8] c"%d * %d = %d\0A\00"
@.str.5 = [11 x i8] c"%d / %d = \00"
@.str.6 = [4 x i8] c"%f\0A\00"
@NAN = global double 0.000000e+00
@.str.7 = [54 x i8] c"Insert two comma separated integers (example: 1, 2): \00"
@stdout = global i32 0
@.str.8 = [11 x i8] c"%10d, %10d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [2 x i32]
%6 = alloca i64
%7 = alloca [2 x i32]
%8 = alloca [2 x i32]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = icmp eq i32 %10, -1
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()
store i64 %16, i64* %6
%17 = load i64, i64* %6
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %15
%23 = load i64, i64* %6
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %89
25: ; preds = %22
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%27 = load i32, i32* %26
%28 = call i32 @close(i32 %27)
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%30 = load i32, i32* %29
%31 = bitcast [2 x i32]* %7 to i32**
%32 = call i32 @read(i32 %30, i32** %31, i32 8)
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%34 = load i32, i32* %33
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%36 = load i32, i32* %35
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%38 = load i32, i32* %37
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%40 = load i32, i32* %39
%41 = add nsw i32 %38, %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %34, i32 %36, i32 %41)
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%44 = load i32, i32* %43
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%46 = load i32, i32* %45
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%48 = load i32, i32* %47
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%50 = load i32, i32* %49
%51 = sub nsw i32 %48, %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %44, i32 %46, i32 %51)
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%54 = load i32, i32* %53
%55 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%56 = load i32, i32* %55
%57 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%58 = load i32, i32* %57
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%60 = load i32, i32* %59
%61 = mul nsw i32 %58, %60
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %54, i32 %56, i32 %61)
%63 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%64 = load i32, i32* %63
%65 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%66 = load i32, i32* %65
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %64, i32 %66)
%68 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%69 = load i32, i32* %68
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %81
71: ; preds = %25
%72 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%73 = load i32, i32* %72
%74 = sitofp i32 %73 to float
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%76 = load i32, i32* %75
%77 = sitofp i32 %76 to float
%78 = fdiv float %74, %77
%79 = fpext float %78 to double
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), double %79)
br label %84
81: ; preds = %25
%82 = load double, double* @NAN
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), double %82)
br label %84
84: ; preds = %81, %71
%85 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%86 = load i32, i32* %85
%87 = call i32 @close(i32 %86)
%88 = call i32 @_exit(i32 0)
unreachable
89: ; preds = %22
%90 = load i64, i64* %6
%91 = icmp sgt i64 %90, 0
br i1 %91, label %92, label %108
92: ; preds = %89
%93 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%94 = load i32, i32* %93
%95 = call i32 @close(i32 %94)
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.7, i64 0, i64 0))
%97 = load i32, i32* @stdout
%98 = call i32 @fflush(i32 %97)
%99 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%100 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%101 = call i32 @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32* %99, i32* %100)
%102 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%103 = load i32, i32* %102
%104 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%105 = call i32 @write(i32 %103, i32* %104, i32 8)
%106 = call i32 @wait(i32* null)
%107 = call i32 @exit(i32 0)
unreachable
108: ; preds = %89
br label %109
109: ; preds = %108
br label %110
110: ; preds = %109
ret i32 0
}

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