#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
scalar_t__ errno;
int /*<<< orphan*/ *fdopen(int, char *);
scalar_t__ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ puts(char *);
int main(void) {
  int fd[2];
  FILE *f;
  if (pipe(fd)) {
    perror("pipe");
    return 1;
  }
  f = fdopen(fd[1], "w");
  if (f == NULL) {
    perror("fdopen");
    return 1;
  }
  errno = 0;
  if (fputs("fnord", f) == EOF) {
    perror("fputs");
    return 1;
  }
  if (errno) {
    perror("errno gratuitously set -- TEST FAILED");
    return 1;
  }
  puts("Test succeeded.");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0x0,%rax
je     118a <main+0x3a>
lea    0xe87(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1242 <main+0xf2>
mov    -0x8(%rbp),%edi
lea    0xe71(%rip),%rsi
call   1060 <fdopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c0 <main+0x70>
lea    0xe58(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1242 <main+0xf2>
mov    0x2e11(%rip),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rsi
lea    0xe35(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e03(%rip),%rcx
cmp    (%rcx),%rax
jne    1206 <main+0xb6>
lea    0xe1f(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1242 <main+0xf2>
mov    0x2dcb(%rip),%rax
cmpq   $0x0,(%rax)
je     122f <main+0xdf>
lea    0xdfc(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1242 <main+0xf2>
lea    0xe0a(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
test   %rax,%rax
jne    11b8 <main+0x68>
mov    0xc(%rsp),%edi
lea    0xe96(%rip),%rsi
call   1060 <fdopen@plt>
test   %rax,%rax
je     11c1 <main+0x71>
mov    0x2e58(%rip),%rbx
movq   $0x0,(%rbx)
lea    0xe80(%rip),%rdi
mov    %rax,%rsi
call   1040 <fputs@plt>
mov    0x2e4b(%rip),%rcx
cmp    (%rcx),%rax
je     11ca <main+0x7a>
cmpq   $0x0,(%rbx)
jne    11d3 <main+0x83>
lea    0xe91(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    11e4 <main+0x94>
lea    0xe41(%rip),%rdi
jmp    11da <main+0x8a>
lea    0xe3f(%rip),%rdi
jmp    11da <main+0x8a>
lea    0xe43(%rip),%rdi
jmp    11da <main+0x8a>
lea    0xe40(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"fdopen\00"
@errno = global i64 0
@.str.3 = [6 x i8] c"fnord\00"
@EOF = global i64 0
@.str.4 = [6 x i8] c"fputs\00"
@.str.5 = [38 x i8] c"errno gratuitously set -- TEST FAILED\00"
@.str.6 = [16 x i8] c"Test succeeded.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32*
store i32 0, i32* %1
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%5 = call i64 @pipe(i32* %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %31
9: ; preds = %0
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%11 = load i32, i32* %10
%12 = call i32* @fdopen(i32 %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %3
%13 = load i32*, i32** %3
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %31
17: ; preds = %9
store i64 0, i64* @errno
%18 = load i32*, i32** %3
%19 = call i64 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %18)
%20 = load i64, i64* @EOF
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %31
24: ; preds = %17
%25 = load i64, i64* @errno
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %31
29: ; preds = %24
%30 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %1
br label %31
31: ; preds = %29, %27, %22, %15, %7
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"fdopen\00"
@errno = global i64 0
@.str.3 = [6 x i8] c"fnord\00"
@EOF = global i64 0
@.str.4 = [6 x i8] c"fputs\00"
@.str.5 = [38 x i8] c"errno gratuitously set -- TEST FAILED\00"
@.str.6 = [16 x i8] c"Test succeeded.\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = bitcast [2 x i32]* %1 to i8*
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%4 = call i64 @pipe(i32* %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %28
8: ; preds = %0
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%10 = load i32, i32* %9
%11 = call i32* @fdopen(i32 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %28
15: ; preds = %8
store i64 0, i64* @errno
%16 = call i64 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %11)
%17 = load i64, i64* @EOF
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %28
21: ; preds = %15
%22 = load i64, i64* @errno
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
br label %28
26: ; preds = %21
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %28
28: ; preds = %26, %24, %19, %13, %6
%29 = phi i32 [ 1, %6 ], [ 1, %13 ], [ 1, %19 ], [ 1, %24 ], [ 0, %26 ]
ret i32 %29
}