#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 */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int dup(int /*<<< orphan*/);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ phone_number_letters(char *, int);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int main() {
  int failed = 0;
  char buffer[] = {[20] = '\0'};
  int pipefds[2];
  int stdoutfd = dup(STDOUT_FILENO);
  if (pipe(pipefds) != 0) {
    return -1;
  }
  dup2(pipefds[1], STDOUT_FILENO);
  close(pipefds[1]);
  phone_number_letters("012", 3);
  fflush(stdout);
  read(pipefds[0], buffer, 20);
  if (strcmp(buffer, "YZA\nYZB\nYZC\n")) {
    failed = -1;
    printf("error, buffer %s not equal to 'YZA\nYZB\nYZC\n'", buffer);
  }
  dup2(stdoutfd, STDOUT_FILENO);
  return failed;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x15,%edx
call   1060 <memset@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1050 <dup@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x28(%rbp),%rdi
call   1080 <pipe@plt>
cmp    $0x0,%rax
je     11f6 <main+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    1287 <main+0xe7>
mov    -0x24(%rbp),%edi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x24(%rbp),%edi
call   1070 <close@plt>
lea    0xdea(%rip),%rdi
mov    $0x3,%esi
call   10b0 <phone_number_letters@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
mov    -0x28(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x14,%edx
call   1090 <read@plt>
lea    -0x20(%rbp),%rdi
lea    0xdba(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1270 <main+0xd0>
movl   $0xffffffff,-0x8(%rbp)
lea    -0x20(%rbp),%rsi
lea    0xda6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x2c(%rbp),%edi
mov    0x2d76(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x1d(%rsp)
mov    0x2e40(%rip),%r14
mov    (%r14),%edi
call   1050 <dup@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    1254 <main+0xc4>
mov    0xc(%rsp),%edi
mov    (%r14),%esi
call   1030 <dup2@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
lea    0xe12(%rip),%rdi
mov    $0x3,%esi
call   10a0 <phone_number_letters@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbp
mov    %rbp,%rsi
mov    $0x14,%edx
call   1080 <read@plt>
lea    0xde1(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1248 <main+0xb8>
lea    0xdda(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%ebp
jmp    124a <main+0xba>
xor    %ebp,%ebp
mov    (%r14),%esi
mov    %ebx,%edi
call   1030 <dup2@plt>
mov    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@.str = [4 x i8] c"012\00"
@stdout = global i32 0
@.str.1 = [13 x i8] c"YZA\0AYZB\0AYZC\0A\00"
@.str.2 = [45 x i8] c"error, buffer %s not equal to 'YZA\0AYZB\0AYZC\0A'\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [21 x i8]
%4 = alloca [2 x i32]
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%6 = bitcast [21 x i8]* %3 to i8*
%7 = load i32, i32* @STDOUT_FILENO
%8 = call i32 @dup(i32 %7)
store i32 %8, i32* %5
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%10 = call i64 @pipe(i32* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %0
store i32 -1, i32* %1
br label %39
13: ; preds = %0
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%15 = load i32, i32* %14
%16 = load i32, i32* @STDOUT_FILENO
%17 = call i32 @dup2(i32 %15, i32 %16)
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%19 = load i32, i32* %18
%20 = call i32 @close(i32 %19)
%21 = call i32 @phone_number_letters(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%22 = load i32, i32* @stdout
%23 = call i32 @fflush(i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%25 = load i32, i32* %24
%26 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 0
%27 = call i32 @read(i32 %25, i8* %26, i32 20)
%28 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 0
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %13
store i32 -1, i32* %2
%32 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 0
%33 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %31, %13
%35 = load i32, i32* %5
%36 = load i32, i32* @STDOUT_FILENO
%37 = call i32 @dup2(i32 %35, i32 %36)
%38 = load i32, i32* %2
store i32 %38, i32* %1
br label %39
39: ; preds = %34, %12
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@.str = [4 x i8] c"012\00"
@stdout = global i32 0
@.str.1 = [13 x i8] c"YZA\0AYZB\0AYZC\0A\00"
@.str.2 = [45 x i8] c"error, buffer %s not equal to 'YZA\0AYZB\0AYZC\0A'\00"
define i32 @main() {
%1 = alloca [21 x i8]
%2 = alloca [2 x i32]
%3 = getelementptr inbounds [21 x i8], [21 x i8]* %1, i64 0, i64 0
%4 = bitcast [2 x i32]* %2 to i8*
%5 = load i32, i32* @STDOUT_FILENO
%6 = tail call i32 @dup(i32 %5)
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%8 = call i64 @pipe(i32* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %30
10: ; preds = %0
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%12 = load i32, i32* %11
%13 = load i32, i32* @STDOUT_FILENO
%14 = call i32 @dup2(i32 %12, i32 %13)
%15 = load i32, i32* %11
%16 = call i32 @close(i32 %15)
%17 = call i32 @phone_number_letters(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%18 = load i32, i32* @stdout
%19 = call i32 @fflush(i32 %18)
%20 = load i32, i32* %7
%21 = call i32 @read(i32 %20, i8* %3, i32 20)
%22 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %10
%25 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %26
26: ; preds = %24, %10
%27 = phi i32 [ -1, %24 ], [ 0, %10 ]
%28 = load i32, i32* @STDOUT_FILENO
%29 = call i32 @dup2(i32 %6, i32 %28)
br label %30
30: ; preds = %0, %26
%31 = phi i32 [ %27, %26 ], [ -1, %0 ]
ret i32 %31
}