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

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ O_RDWR;
int STDIN_FILENO;
int /*<<< orphan*/ close(int);
scalar_t__ ferror(int /*<<< orphan*/);
scalar_t__ fputs(char *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  if (argc != 1 && argc != 3) {
    printf("usage: padd3 <int1> <int2>\n");
    return 0;
  }
  int fdin, fdout, n, m;
  char line[128];
  fdin = open("./pipe", O_RDWR);
  if (fdin < 0) {
    printf("open file pipe failed\n");
    return 0;
  }
  printf("open file pipe ok, fd = %d\n", fdin);
  fdout = fdin;
  if (argc == 1) {
    if ((n = read(STDIN_FILENO, line, 128)) < 0) {
      printf("read error from stdin\n");
      return 0;
    }
  } else {
    sprintf(line, "%s %s", argv[1], argv[2]);
  }
  n = strlen(line);
  if (write(fdout, line, n) != n) {
    printf("write error to pipe\n");
    return 0;
  }
  strcat(line, " = ");
  m = strlen(line);
  if ((n = read(fdin, line + m, 128 - m)) < 0) {
    printf("read error from pipe\n");
    return 0;
  }
  if (n == 0) {
    printf("child closed pipe\n");
    return 0;
  }
  line[m + n] = 0;
  if (fputs(line, stdout) == EOF) {
    printf("fputs error\n");
    return 0;
  }
  if (ferror(stdin)) {
    printf("fputs error\n");
    return 0;
  }
  close(fdin);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     11e7 <main+0x47>
cmpl   $0x3,-0x8(%rbp)
je     11e7 <main+0x47>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    140a <main+0x26a>
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
lea    0xe25(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1223 <main+0x83>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    140a <main+0x26a>
mov    -0x14(%rbp),%esi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1289 <main+0xe9>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
call   1090 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1284 <main+0xe4>
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    140a <main+0x26a>
jmp    12ac <main+0x10c>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xdc6(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <write@plt>
cmp    -0x1c(%rbp),%eax
je     12f0 <main+0x150>
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    140a <main+0x26a>
lea    -0xa0(%rbp),%rdi
lea    0xd8a(%rip),%rsi
call   10b0 <strcat@plt>
lea    -0xa0(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0xa0(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
mov    $0x80,%edx
sub    -0x20(%rbp),%edx
call   1090 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1356 <main+0x1b6>
lea    0xd49(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    140a <main+0x26a>
cmpl   $0x0,-0x1c(%rbp)
jne    137a <main+0x1da>
lea    0xd3b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    140a <main+0x26a>
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
cltq
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rdi
mov    0x2c30(%rip),%rax
mov    (%rax),%esi
call   1070 <fputs@plt>
mov    0x2c32(%rip),%rcx
cmp    (%rcx),%rax
jne    13c9 <main+0x229>
lea    0xcff(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    140a <main+0x26a>
mov    0x2c10(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     13fb <main+0x25b>
lea    0xccd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    140a <main+0x26a>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %edi,%eax
and    $0xfffffffd,%eax
cmp    $0x1,%eax
jne    1226 <main+0x76>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
lea    0xe26(%rip),%rdi
call   10b0 <open@plt>
test   %eax,%eax
js     1237 <main+0x87>
mov    %eax,%r14d
lea    0xe1a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    $0x1,%ebp
jne    1248 <main+0x98>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0x80,%edx
call   10a0 <read@plt>
test   %eax,%eax
jns    125f <main+0xaf>
lea    0xe58(%rip),%rdi
call   1030 <puts@plt>
jmp    132c <main+0x17c>
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
jmp    132c <main+0x17c>
lea    0xe4c(%rip),%rdi
call   1030 <puts@plt>
jmp    132c <main+0x17c>
mov    0x8(%rbx),%rdx
mov    0x10(%rbx),%rcx
lea    0xdcc(%rip),%rsi
mov    %rsp,%rdi
call   10d0 <sprintf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    %ebp,%eax
jne    12fa <main+0x14a>
lea    0xda5(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   10c0 <strcat@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
cltq
lea    (%rsp,%rax,1),%rsi
mov    $0x80,%edx
sub    %eax,%edx
mov    %r14d,%edi
call   10a0 <read@plt>
test   %eax,%eax
js     1308 <main+0x158>
je     1316 <main+0x166>
add    %ebx,%eax
cltq
movb   $0x0,(%rsp,%rax,1)
mov    0x2d05(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1080 <fputs@plt>
mov    0x2d04(%rip),%rcx
cmp    (%rcx),%rax
je     12ec <main+0x13c>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
call   1040 <ferror@plt>
test   %rax,%rax
je     1324 <main+0x174>
lea    0xd3a(%rip),%rdi
call   1030 <puts@plt>
jmp    132c <main+0x17c>
lea    0xd5f(%rip),%rdi
call   1030 <puts@plt>
jmp    132c <main+0x17c>
lea    0xd3c(%rip),%rdi
call   1030 <puts@plt>
jmp    132c <main+0x17c>
lea    0xd1c(%rip),%rdi
call   1030 <puts@plt>
jmp    132c <main+0x17c>
mov    %r14d,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"usage: padd3 <int1> <int2>\0A\00"
@.str.1 = [7 x i8] c"./pipe\00"
@O_RDWR = global i32 0
@.str.2 = [23 x i8] c"open file pipe failed\0A\00"
@.str.3 = [28 x i8] c"open file pipe ok, fd = %d\0A\00"
@STDIN_FILENO = global i32 0
@.str.4 = [23 x i8] c"read error from stdin\0A\00"
@.str.5 = [6 x i8] c"%s %s\00"
@.str.6 = [21 x i8] c"write error to pipe\0A\00"
@.str.7 = [4 x i8] c" = \00"
@.str.8 = [22 x i8] c"read error from pipe\0A\00"
@.str.9 = [19 x i8] c"child closed pipe\0A\00"
@stdout = global i32 0
@EOF = global i64 0
@.str.10 = [13 x i8] c"fputs error\0A\00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %102
18: ; preds = %13, %2
%19 = load i32, i32* @O_RDWR
%20 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %102
25: ; preds = %18
%26 = load i32, i32* %6
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %6
store i32 %28, i32* %7
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %39
31: ; preds = %25
%32 = load i32, i32* @STDIN_FILENO
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%34 = call i32 @read(i32 %32, i8* %33, i32 128)
store i32 %34, i32* %8
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %102
38: ; preds = %31
br label %48
39: ; preds = %25
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32 @sprintf(i8* %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %43, i8* %46)
br label %48
48: ; preds = %39, %38
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
store i32 %50, i32* %8
%51 = load i32, i32* %7
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%53 = load i32, i32* %8
%54 = call i32 @write(i32 %51, i8* %52, i32 %53)
%55 = load i32, i32* %8
%56 = icmp ne i32 %54, %55
br i1 %56, label %57, label %59
57: ; preds = %48
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %3
br label %102
59: ; preds = %48
%60 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%61 = call i32 @strcat(i8* %60, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%62 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%63 = call i32 @strlen(i8* %62)
store i32 %63, i32* %9
%64 = load i32, i32* %6
%65 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%66 = load i32, i32* %9
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
%69 = load i32, i32* %9
%70 = sub nsw i32 128, %69
%71 = call i32 @read(i32 %64, i8* %68, i32 %70)
store i32 %71, i32* %8
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %59
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %3
br label %102
75: ; preds = %59
%76 = load i32, i32* %8
%77 = icmp eq i32 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %75
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %3
br label %102
80: ; preds = %75
%81 = load i32, i32* %9
%82 = load i32, i32* %8
%83 = add nsw i32 %81, %82
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 %84
store i8 0, i8* %85
%86 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%87 = load i32, i32* @stdout
%88 = call i64 @fputs(i8* %86, i32 %87)
%89 = load i64, i64* @EOF
%90 = icmp eq i64 %88, %89
br i1 %90, label %91, label %93
91: ; preds = %80
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %3
br label %102
93: ; preds = %80
%94 = load i32, i32* @stdin
%95 = call i64 @ferror(i32 %94)
%96 = icmp ne i64 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %93
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %3
br label %102
99: ; preds = %93
%100 = load i32, i32* %6
%101 = call i32 @close(i32 %100)
store i32 0, i32* %3
br label %102
102: ; preds = %99, %97, %91, %78, %73, %57, %36, %23, %16
%103 = load i32, i32* %3
ret i32 %103
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"./pipe\00"
@O_RDWR = global i32 0
@.str.3 = [28 x i8] c"open file pipe ok, fd = %d\0A\00"
@STDIN_FILENO = global i32 0
@.str.5 = [6 x i8] c"%s %s\00"
@.str.7 = [4 x i8] c" = \00"
@stdout = global i32 0
@EOF = global i64 0
@stdin = global i32 0
@str.11 = [12 x i8] c"fputs error\00"
@str.12 = [18 x i8] c"child closed pipe\00"
@str.13 = [21 x i8] c"read error from pipe\00"
@str.14 = [20 x i8] c"write error to pipe\00"
@str.15 = [22 x i8] c"read error from stdin\00"
@str.16 = [22 x i8] c"open file pipe failed\00"
@str.17 = [27 x i8] c"usage: padd3 <int1> <int2>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = and i32 %0, -3
%5 = icmp eq i32 %4, 1
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.17, i64 0, i64 0))
br label %69
8: ; preds = %2
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%10 = load i32, i32* @O_RDWR
%11 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.16, i64 0, i64 0))
br label %68
15: ; preds = %8
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%17 = icmp eq i32 %0, 1
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i32, i32* @STDIN_FILENO
%20 = call i32 @read(i32 %19, i8* %9, i32 128)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.15, i64 0, i64 0))
br label %68
24: ; preds = %15
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %26, i8* %28)
br label %30
30: ; preds = %18, %24
%31 = call i32 @strlen(i8* %9)
%32 = call i32 @write(i32 %11, i8* %9, i32 %31)
%33 = icmp eq i32 %32, %31
br i1 %33, label %36, label %34
34: ; preds = %30
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.14, i64 0, i64 0))
br label %68
36: ; preds = %30
%37 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%38 = call i32 @strlen(i8* %9)
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %39
%41 = sub nsw i32 128, %38
%42 = call i32 @read(i32 %11, i8* %40, i32 %41)
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %36
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.13, i64 0, i64 0))
br label %68
46: ; preds = %36
%47 = icmp eq i32 %42, 0
br i1 %47, label %48, label %50
48: ; preds = %46
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.12, i64 0, i64 0))
br label %68
50: ; preds = %46
%51 = add nsw i32 %42, %38
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %52
store i8 0, i8* %53
%54 = load i32, i32* @stdout
%55 = call i64 @fputs(i8* %9, i32 %54)
%56 = load i64, i64* @EOF
%57 = icmp eq i64 %55, %56
br i1 %57, label %58, label %60
58: ; preds = %50
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.11, i64 0, i64 0))
br label %68
60: ; preds = %50
%61 = load i32, i32* @stdin
%62 = call i64 @ferror(i32 %61)
%63 = icmp eq i64 %62, 0
br i1 %63, label %66, label %64
64: ; preds = %60
%65 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.11, i64 0, i64 0))
br label %68
66: ; preds = %60
%67 = call i32 @close(i32 %11)
br label %68
68: ; preds = %66, %64, %58, %48, %44, %34, %22, %13
br label %69
69: ; preds = %68, %6
ret i32 0
}