#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 */
struct stat {
  int dummy;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
scalar_t__ fork();
int pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, ...);
int /*<<< orphan*/ usleep(int);
int write(int, ...);
int main(void) {
  char buffer[32768], buffer2[32768];
  int desc[2];
  int buggy, error, i, successes, total;
  struct stat status;
  pid_t new_pid;
  buggy = 0;
  total = 0;
  error = pipe(desc);
  if (error)
    err(0, "Couldn't allocate fds\n");
  buffer[0] = 'A';
  for (i = 1; i < 32768; i++) {
    buffer[i] = buffer[i - 1] + 1;
    if (buffer[i] > 'Z')
      buffer[i] = 'A';
  }
  new_pid = fork();
  if (new_pid == 0) {
    error = write(desc[1], &buffer, 4096);
    total += error;
    error = write(desc[1], &buffer[total], 4096);
    total += error;
    error = write(desc[1], &buffer[total], 4000);
    total += error;
    printf("Wrote %d bytes, sleeping\n", total);
    usleep(1000000);
    error = write(desc[1], &buffer[total], 3000);
    total += error;
    error = write(desc[1], &buffer[total], 3000);
    total += error;
    printf("Wrote another 6000 bytes, %d total, done\n", total);
  } else {
    usleep(500000);
    error = read(desc[0], &buffer2, 8192);
    total += error;
    printf("Read %d bytes, going back to sleep\n", error);
    usleep(1000000);
    error = read(desc[0], &buffer2[total], 16384);
    total += error;
    printf("Read %d bytes, done\n", error);
    for (i = 0; i < total; i++) {
      if (buffer[i] != buffer2[i]) {
        buggy = 1;
        printf("Location %d input: %hhx output: %hhx\n", i, buffer[i],
               buffer2[i]);
      }
    }
    if (buggy)
      printf("FAILURE\n");
    else
      printf("SUCCESS\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10040,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1001c(%rbp)
movl   $0x0,-0x1002c(%rbp)
lea    -0x10018(%rbp),%rdi
call   1050 <pipe@plt>
mov    %eax,-0x10020(%rbp)
cmpl   $0x0,-0x10020(%rbp)
je     11c3 <main+0x53>
xor    %edi,%edi
lea    0xe42(%rip),%rsi
call   1070 <err@plt>
movb   $0x41,-0x8010(%rbp)
movl   $0x1,-0x10024(%rbp)
cmpl   $0x8000,-0x10024(%rbp)
jge    124a <main+0xda>
mov    -0x10024(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x8010(%rbp,%rax,1),%eax
ff
add    $0x1,%eax
mov    %al,%cl
movslq -0x10024(%rbp),%rax
mov    %cl,-0x8010(%rbp,%rax,1)
movslq -0x10024(%rbp),%rax
movsbl -0x8010(%rbp,%rax,1),%eax
ff
cmp    $0x5a,%eax
jle    1231 <main+0xc1>
movslq -0x10024(%rbp),%rax
movb   $0x41,-0x8010(%rbp,%rax,1)
41
jmp    1236 <main+0xc6>
mov    -0x10024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10024(%rbp)
jmp    11d4 <main+0x64>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10038(%rbp)
cmpq   $0x0,-0x10038(%rbp)
jne    13ba <main+0x24a>
mov    -0x10014(%rbp),%edi
lea    -0x8010(%rbp),%rsi
mov    $0x1000,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x10020(%rbp)
mov    -0x10020(%rbp),%eax
add    -0x1002c(%rbp),%eax
mov    %eax,-0x1002c(%rbp)
mov    -0x10014(%rbp),%edi
movslq -0x1002c(%rbp),%rax
lea    -0x8010(%rbp),%rsi
add    %rax,%rsi
mov    $0x1000,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x10020(%rbp)
mov    -0x10020(%rbp),%eax
add    -0x1002c(%rbp),%eax
mov    %eax,-0x1002c(%rbp)
mov    -0x10014(%rbp),%edi
movslq -0x1002c(%rbp),%rax
lea    -0x8010(%rbp),%rsi
add    %rax,%rsi
mov    $0xfa0,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x10020(%rbp)
mov    -0x10020(%rbp),%eax
add    -0x1002c(%rbp),%eax
mov    %eax,-0x1002c(%rbp)
mov    -0x1002c(%rbp),%esi
lea    0xcfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xf4240,%edi
call   1090 <usleep@plt>
mov    -0x10014(%rbp),%edi
movslq -0x1002c(%rbp),%rax
lea    -0x8010(%rbp),%rsi
add    %rax,%rsi
mov    $0xbb8,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x10020(%rbp)
mov    -0x10020(%rbp),%eax
add    -0x1002c(%rbp),%eax
mov    %eax,-0x1002c(%rbp)
mov    -0x10014(%rbp),%edi
movslq -0x1002c(%rbp),%rax
lea    -0x8010(%rbp),%rsi
add    %rax,%rsi
mov    $0xbb8,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x10020(%rbp)
mov    -0x10020(%rbp),%eax
add    -0x1002c(%rbp),%eax
mov    %eax,-0x1002c(%rbp)
mov    -0x1002c(%rbp),%esi
lea    0xc83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    152c <main+0x3bc>
mov    $0x7a120,%edi
call   1090 <usleep@plt>
mov    -0x10018(%rbp),%edi
lea    -0x10010(%rbp),%rsi
mov    $0x2000,%edx
mov    $0x0,%al
call   1060 <read@plt>
mov    %eax,-0x10020(%rbp)
mov    -0x10020(%rbp),%eax
add    -0x1002c(%rbp),%eax
mov    %eax,-0x1002c(%rbp)
mov    -0x10020(%rbp),%esi
lea    0xc59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xf4240,%edi
call   1090 <usleep@plt>
mov    -0x10018(%rbp),%edi
movslq -0x1002c(%rbp),%rax
lea    -0x10010(%rbp),%rsi
add    %rax,%rsi
mov    $0x4000,%edx
mov    $0x0,%al
call   1060 <read@plt>
mov    %eax,-0x10020(%rbp)
mov    -0x10020(%rbp),%eax
add    -0x1002c(%rbp),%eax
mov    %eax,-0x1002c(%rbp)
mov    -0x10020(%rbp),%esi
lea    0xc24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x10024(%rbp)
mov    -0x10024(%rbp),%eax
cmp    -0x1002c(%rbp),%eax
jge    14f9 <main+0x389>
movslq -0x10024(%rbp),%rax
movsbl -0x8010(%rbp,%rax,1),%eax
ff
movslq -0x10024(%rbp),%rcx
movsbl -0x10010(%rbp,%rcx,1),%ecx
ff
cmp    %ecx,%eax
je     14e0 <main+0x370>
movl   $0x1,-0x1001c(%rbp)
mov    -0x10024(%rbp),%esi
movslq -0x10024(%rbp),%rax
movsbl -0x8010(%rbp,%rax,1),%edx
ff
movslq -0x10024(%rbp),%rax
movsbl -0x10010(%rbp,%rax,1),%ecx
ff
lea    0xbbb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    14e5 <main+0x375>
mov    -0x10024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10024(%rbp)
jmp    146c <main+0x2fc>
cmpl   $0x0,-0x1001c(%rbp)
je     1519 <main+0x3a9>
lea    0xbad(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1527 <main+0x3b7>
lea    0xba3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    152c <main+0x3bc>
mov    -0x4(%rbp),%eax
add    $0x10040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10010,%rsp
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
test   %eax,%eax
je     11a8 <main+0x28>
lea    0xe5f(%rip),%rsi
xor    %edi,%edi
call   1080 <err@plt>
movb   $0x41,0x10(%rsp)
mov    $0x41,%dl
mov    $0x4,%eax
jmp    11c8 <main+0x48>
cs nopw 0x0(%rax,%rax,1)
mov    %dl,0x10(%rsp,%rax,1)
add    $0x4,%rax
add    $0x1,%dl
mov    $0x41,%ecx
mov    $0x41,%esi
cmp    $0x5b,%dl
jge    11dd <main+0x5d>
movzbl %dl,%esi
mov    %sil,0xd(%rsp,%rax,1)
add    $0x1,%sil
mov    $0x41,%edx
cmp    $0x5b,%sil
jge    11f5 <main+0x75>
movzbl %sil,%edx
mov    %dl,0xe(%rsp,%rax,1)
add    $0x1,%dl
cmp    $0x5b,%dl
jge    1204 <main+0x84>
movzbl %dl,%ecx
mov    %cl,0xf(%rsp,%rax,1)
cmp    $0x8000,%rax
je     1222 <main+0xa2>
add    $0x1,%cl
mov    $0x41,%edx
cmp    $0x5b,%cl
jge    11c0 <main+0x40>
movzbl %cl,%edx
jmp    11c0 <main+0x40>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     12f4 <main+0x174>
mov    $0x7a120,%edi
call   10a0 <usleep@plt>
mov    0x8(%rsp),%edi
lea    0x8010(%rsp),%rsi
mov    $0x2000,%edx
xor    %eax,%eax
call   1070 <read@plt>
mov    %eax,%ebx
lea    0xdfe(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xf4240,%edi
call   10a0 <usleep@plt>
mov    0x8(%rsp),%edi
movslq %ebx,%rbx
lea    (%rsp,%rbx,1),%rsi
add    $0x8010,%rsi
mov    $0x4000,%edx
xor    %eax,%eax
call   1070 <read@plt>
add    %eax,%ebx
lea    0xde8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
jle    13b6 <main+0x236>
mov    %ebx,%r15d
add    $0xffffffffffffffff,%r15
mov    $0x41,%dl
lea    0xddc(%rip),%r14
xor    %ebx,%ebx
xor    %eax,%eax
nopl   0x0(%rax)
movsbl 0x8010(%rsp,%rbx,1),%ecx
cmp    %cl,%dl
je     12e0 <main+0x160>
movsbl %dl,%edx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
cmp    %rbx,%r15
je     13a9 <main+0x229>
movzbl 0x11(%rsp,%rbx,1),%edx
add    $0x1,%rbx
jmp    12c0 <main+0x140>
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x1000,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    0xc(%rsp),%edi
movslq %eax,%rbx
lea    (%rsp,%rbx,1),%rsi
add    $0x10,%rsi
mov    $0x1000,%edx
xor    %eax,%eax
call   1040 <write@plt>
add    %eax,%ebx
mov    0xc(%rsp),%edi
movslq %ebx,%rbx
lea    (%rsp,%rbx,1),%rsi
add    $0x10,%rsi
mov    $0xfa0,%edx
xor    %eax,%eax
call   1040 <write@plt>
add    %eax,%ebx
lea    0xccd(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xf4240,%edi
call   10a0 <usleep@plt>
mov    0xc(%rsp),%edi
movslq %ebx,%rbx
lea    (%rsp,%rbx,1),%rsi
add    $0x10,%rsi
mov    $0xbb8,%edx
xor    %eax,%eax
call   1040 <write@plt>
add    %eax,%ebx
mov    0xc(%rsp),%edi
movslq %ebx,%rbx
lea    (%rsp,%rbx,1),%rsi
add    $0x10,%rsi
mov    $0xbb8,%edx
xor    %eax,%eax
call   1040 <write@plt>
add    %eax,%ebx
lea    0xc93(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    13c2 <main+0x242>
test   %eax,%eax
je     13b6 <main+0x236>
lea    0xd0e(%rip),%rdi
jmp    13bd <main+0x23d>
lea    0xcfd(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10010,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [23 x i8] c"Couldn't allocate fds\0A\00"
@.str.1 = [26 x i8] c"Wrote %d bytes, sleeping\0A\00"
@.str.2 = [42 x i8] c"Wrote another 6000 bytes, %d total, done\0A\00"
@.str.3 = [36 x i8] c"Read %d bytes, going back to sleep\0A\00"
@.str.4 = [21 x i8] c"Read %d bytes, done\0A\00"
@.str.5 = [38 x i8] c"Location %d input: %hhx output: %hhx\0A\00"
@.str.6 = [9 x i8] c"FAILURE\0A\00"
@.str.7 = [9 x i8] c"SUCCESS\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [32768 x i8]
%3 = alloca [32768 x i8]
%4 = alloca [2 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.stat
%11 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %5
store i32 0, i32* %9
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%13 = call i32 @pipe(i32* %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 @err(i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %0
%19 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 0
store i8 65, i8* %19
store i32 1, i32* %7
br label %20
20: ; preds = %46, %18
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 32768
br i1 %22, label %23, label %49
23: ; preds = %20
%24 = load i32, i32* %7
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = add nsw i32 %29, 1
%31 = trunc i32 %30 to i8
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 %33
store i8 %31, i8* %34
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp sgt i32 %39, 90
br i1 %40, label %41, label %45
41: ; preds = %23
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 %43
store i8 65, i8* %44
br label %45
45: ; preds = %41, %23
br label %46
46: ; preds = %45
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %20
49: ; preds = %20
%50 = call i64 (...) @fork()
store i64 %50, i64* %11
%51 = load i64, i64* %11
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %101
53: ; preds = %49
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%55 = load i32, i32* %54
%56 = call i32 (i32, ...) @write(i32 %55, [32768 x i8]* %2, i32 4096)
store i32 %56, i32* %6
%57 = load i32, i32* %6
%58 = load i32, i32* %9
%59 = add nsw i32 %58, %57
store i32 %59, i32* %9
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%61 = load i32, i32* %60
%62 = load i32, i32* %9
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 %63
%65 = call i32 (i32, ...) @write(i32 %61, i8* %64, i32 4096)
store i32 %65, i32* %6
%66 = load i32, i32* %6
%67 = load i32, i32* %9
%68 = add nsw i32 %67, %66
store i32 %68, i32* %9
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%70 = load i32, i32* %69
%71 = load i32, i32* %9
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 %72
%74 = call i32 (i32, ...) @write(i32 %70, i8* %73, i32 4000)
store i32 %74, i32* %6
%75 = load i32, i32* %6
%76 = load i32, i32* %9
%77 = add nsw i32 %76, %75
store i32 %77, i32* %9
%78 = load i32, i32* %9
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %78)
%80 = call i32 @usleep(i32 1000000)
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%82 = load i32, i32* %81
%83 = load i32, i32* %9
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 %84
%86 = call i32 (i32, ...) @write(i32 %82, i8* %85, i32 3000)
store i32 %86, i32* %6
%87 = load i32, i32* %6
%88 = load i32, i32* %9
%89 = add nsw i32 %88, %87
store i32 %89, i32* %9
%90 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%91 = load i32, i32* %90
%92 = load i32, i32* %9
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 %93
%95 = call i32 (i32, ...) @write(i32 %91, i8* %94, i32 3000)
store i32 %95, i32* %6
%96 = load i32, i32* %6
%97 = load i32, i32* %9
%98 = add nsw i32 %97, %96
store i32 %98, i32* %9
%99 = load i32, i32* %9
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %99)
br label %164
101: ; preds = %49
%102 = call i32 @usleep(i32 500000)
%103 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%104 = load i32, i32* %103
%105 = call i32 (i32, ...) @read(i32 %104, [32768 x i8]* %3, i32 8192)
store i32 %105, i32* %6
%106 = load i32, i32* %6
%107 = load i32, i32* %9
%108 = add nsw i32 %107, %106
store i32 %108, i32* %9
%109 = load i32, i32* %6
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %109)
%111 = call i32 @usleep(i32 1000000)
%112 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%113 = load i32, i32* %112
%114 = load i32, i32* %9
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds [32768 x i8], [32768 x i8]* %3, i64 0, i64 %115
%117 = call i32 (i32, ...) @read(i32 %113, i8* %116, i32 16384)
store i32 %117, i32* %6
%118 = load i32, i32* %6
%119 = load i32, i32* %9
%120 = add nsw i32 %119, %118
store i32 %120, i32* %9
%121 = load i32, i32* %6
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %121)
store i32 0, i32* %7
br label %123
123: ; preds = %153, %101
%124 = load i32, i32* %7
%125 = load i32, i32* %9
%126 = icmp slt i32 %124, %125
br i1 %126, label %127, label %156
127: ; preds = %123
%128 = load i32, i32* %7
%129 = sext i32 %128 to i64
%130 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 %129
%131 = load i8, i8* %130
%132 = sext i8 %131 to i32
%133 = load i32, i32* %7
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds [32768 x i8], [32768 x i8]* %3, i64 0, i64 %134
%136 = load i8, i8* %135
%137 = sext i8 %136 to i32
%138 = icmp ne i32 %132, %137
br i1 %138, label %139, label %152
139: ; preds = %127
store i32 1, i32* %5
%140 = load i32, i32* %7
%141 = load i32, i32* %7
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 %142
%144 = load i8, i8* %143
%145 = sext i8 %144 to i32
%146 = load i32, i32* %7
%147 = sext i32 %146 to i64
%148 = getelementptr inbounds [32768 x i8], [32768 x i8]* %3, i64 0, i64 %147
%149 = load i8, i8* %148
%150 = sext i8 %149 to i32
%151 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %140, i32 %145, i32 %150)
br label %152
152: ; preds = %139, %127
br label %153
153: ; preds = %152
%154 = load i32, i32* %7
%155 = add nsw i32 %154, 1
store i32 %155, i32* %7
br label %123
156: ; preds = %123
%157 = load i32, i32* %5
%158 = icmp ne i32 %157, 0
br i1 %158, label %159, label %161
159: ; preds = %156
%160 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %163
161: ; preds = %156
%162 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %163
163: ; preds = %161, %159
br label %164
164: ; preds = %163, %53
%165 = load i32, i32* %1
ret i32 %165
}

LLVM IR (-O2):
@.str = [23 x i8] c"Couldn't allocate fds\0A\00"
@.str.1 = [26 x i8] c"Wrote %d bytes, sleeping\0A\00"
@.str.2 = [42 x i8] c"Wrote another 6000 bytes, %d total, done\0A\00"
@.str.3 = [36 x i8] c"Read %d bytes, going back to sleep\0A\00"
@.str.4 = [21 x i8] c"Read %d bytes, done\0A\00"
@.str.5 = [38 x i8] c"Location %d input: %hhx output: %hhx\0A\00"
@str = [8 x i8] c"SUCCESS\00"
@str.8 = [8 x i8] c"FAILURE\00"
define i32 @main() {
%1 = alloca [32768 x i8]
%2 = alloca [32768 x i8]
%3 = alloca [2 x i32]
%4 = getelementptr inbounds [32768 x i8], [32768 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 0
%6 = bitcast [2 x i32]* %3 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = call i32 @err(i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
store i8 65, i8* %4
br label %13
13: ; preds = %32, %12
%14 = phi i8 [ 65, %12 ], [ %36, %32 ]
%15 = phi i64 [ 1, %12 ], [ %37, %32 ]
%16 = add i8 %14, 1
%17 = getelementptr inbounds [32768 x i8], [32768 x i8]* %1, i64 0, i64 %15
%18 = icmp sgt i8 %16, 90
%19 = select i1 %18, i8 65, i8 %16
store i8 %19, i8* %17
%20 = add nuw nsw i64 %15, 1
%21 = add i8 %19, 1
%22 = getelementptr inbounds [32768 x i8], [32768 x i8]* %1, i64 0, i64 %20
%23 = icmp sgt i8 %21, 90
%24 = select i1 %23, i8 65, i8 %21
store i8 %24, i8* %22
%25 = add nuw nsw i64 %15, 2
%26 = add i8 %24, 1
%27 = getelementptr inbounds [32768 x i8], [32768 x i8]* %1, i64 0, i64 %25
%28 = icmp sgt i8 %26, 90
%29 = select i1 %28, i8 65, i8 %26
store i8 %29, i8* %27
%30 = add nuw nsw i64 %15, 3
%31 = icmp eq i64 %30, 32768
br i1 %31, label %38, label %32
32: ; preds = %13
%33 = add i8 %29, 1
%34 = getelementptr inbounds [32768 x i8], [32768 x i8]* %1, i64 0, i64 %30
%35 = icmp sgt i8 %33, 90
%36 = select i1 %35, i8 65, i8 %33
store i8 %36, i8* %34
%37 = add nuw nsw i64 %15, 4
br label %13
38: ; preds = %13
%39 = call i64 (...) @fork()
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %68
41: ; preds = %38
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%43 = load i32, i32* %42
%44 = call i32 (i32, ...) @write(i32 %43, [32768 x i8]* %1, i32 4096)
%45 = load i32, i32* %42
%46 = sext i32 %44 to i64
%47 = getelementptr inbounds [32768 x i8], [32768 x i8]* %1, i64 0, i64 %46
%48 = call i32 (i32, ...) @write(i32 %45, i8* %47, i32 4096)
%49 = add nsw i32 %48, %44
%50 = load i32, i32* %42
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds [32768 x i8], [32768 x i8]* %1, i64 0, i64 %51
%53 = call i32 (i32, ...) @write(i32 %50, i8* %52, i32 4000)
%54 = add nsw i32 %53, %49
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %54)
%56 = call i32 @usleep(i32 1000000)
%57 = load i32, i32* %42
%58 = sext i32 %54 to i64
%59 = getelementptr inbounds [32768 x i8], [32768 x i8]* %1, i64 0, i64 %58
%60 = call i32 (i32, ...) @write(i32 %57, i8* %59, i32 3000)
%61 = add nsw i32 %60, %54
%62 = load i32, i32* %42
%63 = sext i32 %61 to i64
%64 = getelementptr inbounds [32768 x i8], [32768 x i8]* %1, i64 0, i64 %63
%65 = call i32 (i32, ...) @write(i32 %62, i8* %64, i32 3000)
%66 = add nsw i32 %65, %61
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %66)
br label %108
68: ; preds = %38
%69 = call i32 @usleep(i32 500000)
%70 = load i32, i32* %7
%71 = call i32 (i32, ...) @read(i32 %70, [32768 x i8]* %2, i32 8192)
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %71)
%73 = call i32 @usleep(i32 1000000)
%74 = load i32, i32* %7
%75 = sext i32 %71 to i64
%76 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 %75
%77 = call i32 (i32, ...) @read(i32 %74, i8* %76, i32 16384)
%78 = add i32 %77, %71
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %77)
%80 = icmp sgt i32 %78, 0
br i1 %80, label %81, label %106
81: ; preds = %68
%82 = zext i32 %78 to i64
br label %83
83: ; preds = %99, %81
%84 = phi i8 [ 65, %81 ], [ %101, %99 ]
%85 = phi i64 [ 0, %81 ], [ %97, %99 ]
%86 = phi i32 [ 0, %81 ], [ %96, %99 ]
%87 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 %85
%88 = load i8, i8* %87
%89 = icmp eq i8 %84, %88
br i1 %89, label %95, label %90
90: ; preds = %83
%91 = sext i8 %88 to i32
%92 = sext i8 %84 to i32
%93 = trunc i64 %85 to i32
%94 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %93, i32 %92, i32 %91)
br label %95
95: ; preds = %83, %90
%96 = phi i32 [ 1, %90 ], [ %86, %83 ]
%97 = add nuw nsw i64 %85, 1
%98 = icmp eq i64 %97, %82
br i1 %98, label %102, label %99
99: ; preds = %95
%100 = getelementptr inbounds [32768 x i8], [32768 x i8]* %1, i64 0, i64 %97
%101 = load i8, i8* %100
br label %83
102: ; preds = %95
%103 = icmp eq i32 %96, 0
br i1 %103, label %106, label %104
104: ; preds = %102
%105 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.8, i64 0, i64 0))
br label %108
106: ; preds = %68, %102
%107 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %108
108: ; preds = %104, %106, %41
ret i32 0
}