#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 STDIN_FILENO;
int cli_conn(char *);
int /*<<< orphan*/ close(int);
scalar_t__ ferror(int /*<<< orphan*/);
scalar_t__ fputs(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 = cli_conn("./pipe");
  if (fdin < 0)
    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    13f3 <main+0x253>
lea    0xe2e(%rip),%rdi
call   10a0 <cli_conn@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    120c <main+0x6c>
movl   $0x0,-0x4(%rbp)
jmp    13f3 <main+0x253>
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    1272 <main+0xd2>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
call   1090 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    126d <main+0xcd>
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f3 <main+0x253>
jmp    1295 <main+0xf5>
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     12d9 <main+0x139>
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f3 <main+0x253>
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    133f <main+0x19f>
lea    0xd49(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f3 <main+0x253>
cmpl   $0x0,-0x1c(%rbp)
jne    1363 <main+0x1c3>
lea    0xd3b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f3 <main+0x253>
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
cltq
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rdi
mov    0x2c4f(%rip),%rax
mov    (%rax),%esi
call   1070 <fputs@plt>
mov    0x2c51(%rip),%rcx
cmp    (%rcx),%rax
jne    13b2 <main+0x212>
lea    0xcff(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f3 <main+0x253>
mov    0x2c2f(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     13e4 <main+0x244>
lea    0xccd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f3 <main+0x253>
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    1221 <main+0x71>
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe2f(%rip),%rdi
call   10b0 <cli_conn@plt>
test   %eax,%eax
js     1316 <main+0x166>
mov    %eax,%r14d
lea    0xe1f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    $0x1,%ebp
jne    1232 <main+0x82>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0x80,%edx
call   10a0 <read@plt>
test   %eax,%eax
jns    1249 <main+0x99>
lea    0xe5d(%rip),%rdi
call   1030 <puts@plt>
jmp    1316 <main+0x166>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
jmp    1316 <main+0x166>
mov    0x8(%rbx),%rdx
mov    0x10(%rbx),%rcx
lea    0xde2(%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    12e4 <main+0x134>
lea    0xdbb(%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     12f2 <main+0x142>
je     1300 <main+0x150>
add    %ebx,%eax
cltq
movb   $0x0,(%rsp,%rax,1)
mov    0x2d23(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1080 <fputs@plt>
mov    0x2d22(%rip),%rcx
cmp    (%rcx),%rax
je     12d6 <main+0x126>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
call   1040 <ferror@plt>
test   %rax,%rax
je     130e <main+0x15e>
lea    0xd50(%rip),%rdi
call   1030 <puts@plt>
jmp    1316 <main+0x166>
lea    0xd75(%rip),%rdi
call   1030 <puts@plt>
jmp    1316 <main+0x166>
lea    0xd52(%rip),%rdi
call   1030 <puts@plt>
jmp    1316 <main+0x166>
lea    0xd32(%rip),%rdi
call   1030 <puts@plt>
jmp    1316 <main+0x166>
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"
@.str.2 = [28 x i8] c"open file pipe ok, fd = %d\0A\00"
@STDIN_FILENO = global i32 0
@.str.3 = [23 x i8] c"read error from stdin\0A\00"
@.str.4 = [6 x i8] c"%s %s\00"
@.str.5 = [21 x i8] c"write error to pipe\0A\00"
@.str.6 = [4 x i8] c" = \00"
@.str.7 = [22 x i8] c"read error from pipe\0A\00"
@.str.8 = [19 x i8] c"child closed pipe\0A\00"
@stdout = global i32 0
@EOF = global i64 0
@.str.9 = [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 %100
18: ; preds = %13, %2
%19 = call i32 @cli_conn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 0, i32* %3
br label %100
23: ; preds = %18
%24 = load i32, i32* %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %6
store i32 %26, i32* %7
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %37
29: ; preds = %23
%30 = load i32, i32* @STDIN_FILENO
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%32 = call i32 @read(i32 %30, i8* %31, i32 128)
store i32 %32, i32* %8
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %100
36: ; preds = %29
br label %46
37: ; preds = %23
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %41, i8* %44)
br label %46
46: ; preds = %37, %36
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%48 = call i32 @strlen(i8* %47)
store i32 %48, i32* %8
%49 = load i32, i32* %7
%50 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%51 = load i32, i32* %8
%52 = call i32 @write(i32 %49, i8* %50, i32 %51)
%53 = load i32, i32* %8
%54 = icmp ne i32 %52, %53
br i1 %54, label %55, label %57
55: ; preds = %46
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %100
57: ; preds = %46
%58 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%59 = call i32 @strcat(i8* %58, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%60 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%61 = call i32 @strlen(i8* %60)
store i32 %61, i32* %9
%62 = load i32, i32* %6
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%64 = load i32, i32* %9
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
%67 = load i32, i32* %9
%68 = sub nsw i32 128, %67
%69 = call i32 @read(i32 %62, i8* %66, i32 %68)
store i32 %69, i32* %8
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %57
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %3
br label %100
73: ; preds = %57
%74 = load i32, i32* %8
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %73
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %3
br label %100
78: ; preds = %73
%79 = load i32, i32* %9
%80 = load i32, i32* %8
%81 = add nsw i32 %79, %80
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 %82
store i8 0, i8* %83
%84 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%85 = load i32, i32* @stdout
%86 = call i64 @fputs(i8* %84, i32 %85)
%87 = load i64, i64* @EOF
%88 = icmp eq i64 %86, %87
br i1 %88, label %89, label %91
89: ; preds = %78
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %3
br label %100
91: ; preds = %78
%92 = load i32, i32* @stdin
%93 = call i64 @ferror(i32 %92)
%94 = icmp ne i64 %93, 0
br i1 %94, label %95, label %97
95: ; preds = %91
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %3
br label %100
97: ; preds = %91
%98 = load i32, i32* %6
%99 = call i32 @close(i32 %98)
store i32 0, i32* %3
br label %100
100: ; preds = %97, %95, %89, %76, %71, %55, %34, %22, %16
%101 = load i32, i32* %3
ret i32 %101
}

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