#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__ ssize_t;
typedef int pid_t;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int dup2(int, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ perror(char *);
int pipe(int *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
scalar_t__ write(int /*<<< orphan*/, char *, scalar_t__);
int main(int argc, char *argv[]) {
  char *hostname = "localhost";
  int in[2], out[2], err[2];
  if (argc > 1) {
    hostname = argv[1];
  }
  if (pipe(in) == -1) {
    perror("pipe(in) failed");
  }
  if (pipe(out) == -1) {
    perror("pipe(out) failed");
  }
  if (pipe(err) == -1) {
    perror("pipe(err) failed");
  }
  pid_t child = fork();
  if (child == -1) {
    perror("fork failed");
  }
  if (child == 0) {
    close(in[1]);
    close(out[0]);
    close(err[0]);
    if (dup2(in[0], STDIN_FILENO) == -1) {
      perror("dup failed");
    }
    if (dup2(out[1], STDOUT_FILENO) == -1) {
      perror("dup failed");
    }
    if (dup2(err[1], STDERR_FILENO) == -1) {
      perror("dup failed");
    }
    close(in[0]);
    close(out[1]);
    close(err[1]);
    char *argv[] = {
        "/usr/bin/ssh", "-o", "StrictHostKeyChecking=no", hostname, "sleep",
        "100",          NULL};
    execv(argv[0], argv);
    perror("execv failed");
  } else {
    close(in[0]);
    close(out[1]);
    close(err[1]);
    char buf[4096];
    while (1) {
      ssize_t rt = read(out[0], buf, 4096);
      ssize_t wrt;
      if (rt > 0) {
        wrt = write(STDOUT_FILENO, buf, rt);
        if (wrt == -1 && errno != EINTR) {
          perror("write failed.");
          exit(0);
        }
      }
      rt = read(err[0], buf, 4096);
      if (rt > 0) {
        wrt = write(STDERR_FILENO, buf, rt);
        if (wrt == -1 && errno != EINTR) {
          perror("write failed.");
        }
      }
    }
  }
  wait(NULL);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1080,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe40(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11da <main+0x3a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11f8 <main+0x58>
lea    0xe17(%rip),%rdi
call   1080 <perror@plt>
lea    -0x28(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1216 <main+0x76>
lea    0xe09(%rip),%rdi
call   1080 <perror@plt>
lea    -0x30(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1234 <main+0x94>
lea    0xdfc(%rip),%rdi
call   1080 <perror@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    1254 <main+0xb4>
lea    0xded(%rip),%rdi
call   1080 <perror@plt>
cmpl   $0x0,-0x34(%rbp)
jne    1365 <main+0x1c5>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
mov    -0x30(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%edi
mov    0x2d40(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
cmp    $0xffffffff,%eax
jne    129c <main+0xfc>
lea    0xdb1(%rip),%rdi
call   1080 <perror@plt>
mov    -0x24(%rbp),%edi
mov    0x2d4a(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
cmp    $0xffffffff,%eax
jne    12c2 <main+0x122>
lea    0xd8b(%rip),%rdi
call   1080 <perror@plt>
mov    -0x2c(%rbp),%edi
mov    0x2d04(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
cmp    $0xffffffff,%eax
jne    12e8 <main+0x148>
lea    0xd65(%rip),%rdi
call   1080 <perror@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
lea    0xd4c(%rip),%rax
mov    %rax,-0x70(%rbp)
lea    0xd4e(%rip),%rax
mov    %rax,-0x68(%rbp)
lea    0xd46(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    0xd4c(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xd47(%rip),%rax
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x70(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   10b0 <execv@plt>
lea    0xd2b(%rip),%rdi
call   1080 <perror@plt>
jmp    1493 <main+0x2f3>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%edi
lea    -0x1070(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %rax,-0x1078(%rbp)
cmpq   $0x0,-0x1078(%rbp)
jle    1409 <main+0x269>
mov    0x2c43(%rip),%rax
mov    (%rax),%edi
lea    -0x1070(%rbp),%rsi
mov    -0x1078(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x1080(%rbp)
cmpq   $0xffffffffffffffff,-0x1080(%rbp)
ff
jne    1404 <main+0x264>
mov    0x2bfa(%rip),%rax
mov    (%rax),%rax
mov    0x2be0(%rip),%rcx
cmp    (%rcx),%rax
je     1404 <main+0x264>
lea    0xc9b(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    1409 <main+0x269>
mov    -0x30(%rbp),%edi
lea    -0x1070(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %rax,-0x1078(%rbp)
cmpq   $0x0,-0x1078(%rbp)
jle    148e <main+0x2ee>
mov    0x2b97(%rip),%rax
mov    (%rax),%edi
lea    -0x1070(%rbp),%rsi
mov    -0x1078(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x1080(%rbp)
cmpq   $0xffffffffffffffff,-0x1080(%rbp)
ff
jne    1489 <main+0x2e9>
mov    0x2b6e(%rip),%rax
mov    (%rax),%rax
mov    0x2b54(%rip),%rcx
cmp    (%rcx),%rax
je     1489 <main+0x2e9>
lea    0xc0f(%rip),%rdi
call   1080 <perror@plt>
jmp    148e <main+0x2ee>
jmp    137d <main+0x1dd>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <wait@plt>
xor    %eax,%eax
add    $0x1080,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1028,%rsp
cmp    $0x2,%edi
jl     11bc <main+0x1c>
mov    0x8(%rsi),%rbx
jmp    11c3 <main+0x23>
lea    0xe3d(%rip),%rbx
lea    0x18(%rsp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11de <main+0x3e>
lea    0xe31(%rip),%rdi
call   1080 <perror@plt>
lea    0x10(%rsp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11f9 <main+0x59>
lea    0xe26(%rip),%rdi
call   1080 <perror@plt>
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1214 <main+0x74>
lea    0xe1c(%rip),%rdi
call   1080 <perror@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
je     1305 <main+0x165>
cmp    $0xffffffff,%eax
jne    1234 <main+0x94>
lea    0xe0d(%rip),%rdi
call   1080 <perror@plt>
mov    0x18(%rsp),%edi
call   1050 <close@plt>
mov    0x14(%rsp),%edi
call   1050 <close@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
lea    0x20(%rsp),%rbx
mov    0x2d95(%rip),%r15
mov    0x2d76(%rip),%r12
mov    0x2d5f(%rip),%r13
mov    0x2d60(%rip),%rbp
lea    0xe1c(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
test   %rax,%rax
jle    12b4 <main+0x114>
mov    (%r15),%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
cmp    $0xffffffffffffffff,%rax
jne    12b4 <main+0x114>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
jne    12f2 <main+0x152>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
test   %rax,%rax
jle    1280 <main+0xe0>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
cmp    $0xffffffffffffffff,%rax
jne    1280 <main+0xe0>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1280 <main+0xe0>
mov    %r14,%rdi
call   1080 <perror@plt>
jmp    1280 <main+0xe0>
lea    0xd9a(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x1c(%rsp),%edi
call   1050 <close@plt>
mov    0x10(%rsp),%edi
call   1050 <close@plt>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    0x18(%rsp),%edi
mov    0x2c95(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
cmp    $0xffffffff,%eax
jne    1343 <main+0x1a3>
lea    0xd0a(%rip),%rdi
call   1080 <perror@plt>
mov    0x14(%rsp),%edi
mov    0x2ca2(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
cmp    $0xffffffff,%eax
jne    1366 <main+0x1c6>
lea    0xce7(%rip),%rdi
call   1080 <perror@plt>
mov    0xc(%rsp),%edi
mov    0x2c5f(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
cmp    $0xffffffff,%eax
jne    1389 <main+0x1e9>
lea    0xcc4(%rip),%rdi
call   1080 <perror@plt>
mov    0x18(%rsp),%edi
call   1050 <close@plt>
mov    0x14(%rsp),%edi
call   1050 <close@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
lea    0xca8(%rip),%rdi
mov    %rdi,0x20(%rsp)
lea    0xca9(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xca0(%rip),%rax
mov    %rax,0x30(%rsp)
mov    %rbx,0x38(%rsp)
lea    0xca8(%rip),%rax
mov    %rax,0x40(%rsp)
lea    0xca2(%rip),%rax
mov    %rax,0x48(%rsp)
movq   $0x0,0x50(%rsp)
lea    0x20(%rsp),%rsi
call   10b0 <execv@plt>
lea    0xc87(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   10a0 <wait@plt>
xor    %eax,%eax
add    $0x1028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [16 x i8] c"pipe(in) failed\00"
@.str.2 = [17 x i8] c"pipe(out) failed\00"
@.str.3 = [17 x i8] c"pipe(err) failed\00"
@.str.4 = [12 x i8] c"fork failed\00"
@STDIN_FILENO = global i32 0
@.str.5 = [11 x i8] c"dup failed\00"
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.6 = [13 x i8] c"/usr/bin/ssh\00"
@.str.7 = [3 x i8] c"-o\00"
@.str.8 = [25 x i8] c"StrictHostKeyChecking=no\00"
@.str.9 = [6 x i8] c"sleep\00"
@.str.10 = [4 x i8] c"100\00"
@.str.11 = [13 x i8] c"execv failed\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.12 = [14 x i8] c"write failed.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [2 x i32]
%8 = alloca [2 x i32]
%9 = alloca [2 x i32]
%10 = alloca i32
%11 = alloca [7 x i8*]
%12 = alloca [4096 x i8]
%13 = alloca i64
%14 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %6
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %6
br label %21
21: ; preds = %17, %2
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%23 = call i32 @pipe(i32* %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%29 = call i32 @pipe(i32* %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%35 = call i32 @pipe(i32* %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %33
%40 = call i32 (...) @fork()
store i32 %40, i32* %10
%41 = load i32, i32* %10
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %45
45: ; preds = %43, %39
%46 = load i32, i32* %10
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %104
48: ; preds = %45
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%50 = load i32, i32* %49
%51 = call i32 @close(i32 %50)
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%53 = load i32, i32* %52
%54 = call i32 @close(i32 %53)
%55 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%56 = load i32, i32* %55
%57 = call i32 @close(i32 %56)
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%59 = load i32, i32* %58
%60 = load i32, i32* @STDIN_FILENO
%61 = call i32 @dup2(i32 %59, i32 %60)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %65
63: ; preds = %48
%64 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %65
65: ; preds = %63, %48
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%67 = load i32, i32* %66
%68 = load i32, i32* @STDOUT_FILENO
%69 = call i32 @dup2(i32 %67, i32 %68)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %73
71: ; preds = %65
%72 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %73
73: ; preds = %71, %65
%74 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%75 = load i32, i32* %74
%76 = load i32, i32* @STDERR_FILENO
%77 = call i32 @dup2(i32 %75, i32 %76)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %81
79: ; preds = %73
%80 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %81
81: ; preds = %79, %73
%82 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%83 = load i32, i32* %82
%84 = call i32 @close(i32 %83)
%85 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%86 = load i32, i32* %85
%87 = call i32 @close(i32 %86)
%88 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%89 = load i32, i32* %88
%90 = call i32 @close(i32 %89)
%91 = getelementptr inbounds [7 x i8*], [7 x i8*]* %11, i64 0, i64 0
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8** %91
%92 = getelementptr inbounds i8*, i8** %91, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8** %92
%93 = getelementptr inbounds i8*, i8** %92, i64 1
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8** %93
%94 = getelementptr inbounds i8*, i8** %93, i64 1
%95 = load i8*, i8** %6
store i8* %95, i8** %94
%96 = getelementptr inbounds i8*, i8** %94, i64 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i8** %96
%97 = getelementptr inbounds i8*, i8** %96, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8** %97
%98 = getelementptr inbounds i8*, i8** %97, i64 1
store i8* null, i8** %98
%99 = getelementptr inbounds [7 x i8*], [7 x i8*]* %11, i64 0, i64 0
%100 = load i8*, i8** %99
%101 = getelementptr inbounds [7 x i8*], [7 x i8*]* %11, i64 0, i64 0
%102 = call i32 @execv(i8* %100, i8** %101)
%103 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0))
br label %158
104: ; preds = %45
%105 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%106 = load i32, i32* %105
%107 = call i32 @close(i32 %106)
%108 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%109 = load i32, i32* %108
%110 = call i32 @close(i32 %109)
%111 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%112 = load i32, i32* %111
%113 = call i32 @close(i32 %112)
br label %114
114: ; preds = %104, %157
%115 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%116 = load i32, i32* %115
%117 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%118 = call i64 @read(i32 %116, i8* %117, i32 4096)
store i64 %118, i64* %13
%119 = load i64, i64* %13
%120 = icmp sgt i64 %119, 0
br i1 %120, label %121, label %136
121: ; preds = %114
%122 = load i32, i32* @STDOUT_FILENO
%123 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%124 = load i64, i64* %13
%125 = call i64 @write(i32 %122, i8* %123, i64 %124)
store i64 %125, i64* %14
%126 = load i64, i64* %14
%127 = icmp eq i64 %126, -1
br i1 %127, label %128, label %135
128: ; preds = %121
%129 = load i64, i64* @errno
%130 = load i64, i64* @EINTR
%131 = icmp ne i64 %129, %130
br i1 %131, label %132, label %135
132: ; preds = %128
%133 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
%134 = call i32 @exit(i32 0)
unreachable
135: ; preds = %128, %121
br label %136
136: ; preds = %135, %114
%137 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%138 = load i32, i32* %137
%139 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%140 = call i64 @read(i32 %138, i8* %139, i32 4096)
store i64 %140, i64* %13
%141 = load i64, i64* %13
%142 = icmp sgt i64 %141, 0
br i1 %142, label %143, label %157
143: ; preds = %136
%144 = load i32, i32* @STDERR_FILENO
%145 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%146 = load i64, i64* %13
%147 = call i64 @write(i32 %144, i8* %145, i64 %146)
store i64 %147, i64* %14
%148 = load i64, i64* %14
%149 = icmp eq i64 %148, -1
br i1 %149, label %150, label %156
150: ; preds = %143
%151 = load i64, i64* @errno
%152 = load i64, i64* @EINTR
%153 = icmp ne i64 %151, %152
br i1 %153, label %154, label %156
154: ; preds = %150
%155 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
br label %156
156: ; preds = %154, %150, %143
br label %157
157: ; preds = %156, %136
br label %114
158: ; preds = %81
%159 = call i32 @wait(i32* null)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [16 x i8] c"pipe(in) failed\00"
@.str.2 = [17 x i8] c"pipe(out) failed\00"
@.str.3 = [17 x i8] c"pipe(err) failed\00"
@.str.4 = [12 x i8] c"fork failed\00"
@STDIN_FILENO = global i32 0
@.str.5 = [11 x i8] c"dup failed\00"
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.6 = [13 x i8] c"/usr/bin/ssh\00"
@.str.7 = [3 x i8] c"-o\00"
@.str.8 = [25 x i8] c"StrictHostKeyChecking=no\00"
@.str.9 = [6 x i8] c"sleep\00"
@.str.10 = [4 x i8] c"100\00"
@.str.11 = [13 x i8] c"execv failed\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.12 = [14 x i8] c"write failed.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = alloca [2 x i32]
%5 = alloca [2 x i32]
%6 = alloca [7 x i8*]
%7 = alloca [4096 x i8]
%8 = bitcast [2 x i32]* %3 to i8*
%9 = bitcast [2 x i32]* %4 to i8*
%10 = bitcast [2 x i32]* %5 to i8*
%11 = icmp sgt i32 %0, 1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
br label %15
15: ; preds = %12, %2
%16 = phi i8* [ %14, %12 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %2 ]
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%18 = call i32 @pipe(i32* %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%24 = call i32 @pipe(i32* %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%30 = call i32 @pipe(i32* %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %32, %28
%35 = call i32 (...) @fork()
switch i32 %35, label %86 [
i32 -1, label %36
i32 0, label %38
]
36: ; preds = %34
%37 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %86
38: ; preds = %34
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%40 = load i32, i32* %39
%41 = call i32 @close(i32 %40)
%42 = load i32, i32* %23
%43 = call i32 @close(i32 %42)
%44 = load i32, i32* %29
%45 = call i32 @close(i32 %44)
%46 = load i32, i32* %17
%47 = load i32, i32* @STDIN_FILENO
%48 = call i32 @dup2(i32 %46, i32 %47)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %38
%51 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %52
52: ; preds = %50, %38
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%54 = load i32, i32* %53
%55 = load i32, i32* @STDOUT_FILENO
%56 = call i32 @dup2(i32 %54, i32 %55)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %60
58: ; preds = %52
%59 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %60
60: ; preds = %58, %52
%61 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%62 = load i32, i32* %61
%63 = load i32, i32* @STDERR_FILENO
%64 = call i32 @dup2(i32 %62, i32 %63)
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %68
66: ; preds = %60
%67 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %68
68: ; preds = %66, %60
%69 = load i32, i32* %17
%70 = call i32 @close(i32 %69)
%71 = load i32, i32* %53
%72 = call i32 @close(i32 %71)
%73 = load i32, i32* %61
%74 = call i32 @close(i32 %73)
%75 = bitcast [7 x i8*]* %6 to i8*
%76 = getelementptr inbounds [7 x i8*], [7 x i8*]* %6, i64 0, i64 0
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8** %76
%77 = getelementptr inbounds [7 x i8*], [7 x i8*]* %6, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8** %77
%78 = getelementptr inbounds [7 x i8*], [7 x i8*]* %6, i64 0, i64 2
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8** %78
%79 = getelementptr inbounds [7 x i8*], [7 x i8*]* %6, i64 0, i64 3
store i8* %16, i8** %79
%80 = getelementptr inbounds [7 x i8*], [7 x i8*]* %6, i64 0, i64 4
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i8** %80
%81 = getelementptr inbounds [7 x i8*], [7 x i8*]* %6, i64 0, i64 5
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8** %81
%82 = getelementptr inbounds [7 x i8*], [7 x i8*]* %6, i64 0, i64 6
store i8* null, i8** %82
%83 = call i32 @execv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8** %76)
%84 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0))
%85 = call i32 @wait(i32* null)
ret i32 0
86: ; preds = %36, %34
%87 = load i32, i32* %17
%88 = call i32 @close(i32 %87)
%89 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%90 = load i32, i32* %89
%91 = call i32 @close(i32 %90)
%92 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%93 = load i32, i32* %92
%94 = call i32 @close(i32 %93)
%95 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
br label %96
96: ; preds = %119, %86
%97 = load i32, i32* %23
%98 = call i64 @read(i32 %97, i8* %95, i32 4096)
%99 = icmp sgt i64 %98, 0
br i1 %99, label %100, label %111
100: ; preds = %96
%101 = load i32, i32* @STDOUT_FILENO
%102 = call i64 @write(i32 %101, i8* %95, i64 %98)
%103 = icmp eq i64 %102, -1
br i1 %103, label %104, label %111
104: ; preds = %100
%105 = load i64, i64* @errno
%106 = load i64, i64* @EINTR
%107 = icmp eq i64 %105, %106
br i1 %107, label %111, label %108
108: ; preds = %104
%109 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
%110 = call i32 @exit(i32 0)
unreachable
111: ; preds = %100, %104, %96
%112 = load i32, i32* %29
%113 = call i64 @read(i32 %112, i8* %95, i32 4096)
%114 = icmp sgt i64 %113, 0
br i1 %114, label %115, label %119
115: ; preds = %111
%116 = load i32, i32* @STDERR_FILENO
%117 = call i64 @write(i32 %116, i8* %95, i64 %113)
%118 = icmp eq i64 %117, -1
br i1 %118, label %120, label %119
119: ; preds = %115, %120, %124, %111
br label %96
120: ; preds = %115
%121 = load i64, i64* @errno
%122 = load i64, i64* @EINTR
%123 = icmp eq i64 %121, %122
br i1 %123, label %119, label %124
124: ; preds = %120
%125 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
br label %119
}