#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*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int test_file();
int test_membuf();
int test_stdio();
int main(int argc, char *argv[]) {
  int rv;
  rv = test_file();
  if (rv < 0) {
    fprintf(stderr, "test_file() failed: %d\n", rv);
  }
  rv = test_stdio();
  if (rv < 0) {
    fprintf(stderr, "test_stdio() failed: %d\n", rv);
  }
  rv = test_membuf();
  if (rv < 0) {
    fprintf(stderr, "test_mem() failed: %d\n", rv);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <test_file@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1182 <main+0x42>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe83(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1060 <test_stdio@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ae <main+0x6e>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe6f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1050 <test_membuf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11da <main+0x9a>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe5c(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1030 <test_file@plt>
test   %eax,%eax
jns    1163 <main+0x23>
mov    0x2e8d(%rip),%rcx
mov    (%rcx),%edi
lea    0xea4(%rip),%rsi
mov    %eax,%edx
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1060 <test_stdio@plt>
test   %eax,%eax
jns    1185 <main+0x45>
mov    0x2e6b(%rip),%rcx
mov    (%rcx),%edi
lea    0xe9a(%rip),%rsi
mov    %eax,%edx
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1050 <test_membuf@plt>
test   %eax,%eax
jns    11a7 <main+0x67>
mov    0x2e49(%rip),%rcx
mov    (%rcx),%edi
lea    0xe91(%rip),%rsi
mov    %eax,%edx
call   1040 <fprintf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"test_file() failed: %d\0A\00"
@.str.1 = [25 x i8] c"test_stdio() failed: %d\0A\00"
@.str.2 = [23 x i8] c"test_mem() failed: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (...) @test_file()
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i32, i32* %6
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %10, %2
%15 = call i32 (...) @test_stdio()
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = load i32, i32* %6
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %14
%23 = call i32 (...) @test_membuf()
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = load i32, i32* %6
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %26, %22
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"test_file() failed: %d\0A\00"
@.str.1 = [25 x i8] c"test_stdio() failed: %d\0A\00"
@.str.2 = [23 x i8] c"test_mem() failed: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @test_file()
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %8
8: ; preds = %5, %2
%9 = tail call i32 (...) @test_stdio()
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %14
14: ; preds = %11, %8
%15 = tail call i32 (...) @test_membuf()
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %20
20: ; preds = %17, %14
ret i32 0
}