#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*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int write(int /*<<< orphan*/, char *, int);
int main() {
  int rc = 0;
  if (write(STDIN_FILENO, "test\n", 5) != 5)
    rc |= 1;
  if (write(STDOUT_FILENO, "test\n", 5) != 5)
    rc |= 2;
  if (write(STDERR_FILENO, "test\n", 5) != 5)
    rc |= 4;
  return rc;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%edi
lea    0xeca(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
cmp    $0x5,%eax
je     1152 <main+0x42>
mov    -0x8(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
lea    0xe9e(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
cmp    $0x5,%eax
je     117e <main+0x6e>
mov    -0x8(%rbp),%eax
or     $0x2,%eax
mov    %eax,-0x8(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
cmp    $0x5,%eax
je     11aa <main+0x9a>
mov    -0x8(%rbp),%eax
or     $0x4,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2eb4(%rip),%rax
mov    (%rax),%edi
lea    0xedb(%rip),%r14
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <write@plt>
xor    %r15d,%r15d
cmp    $0x5,%eax
setne  %r15b
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <write@plt>
lea    0x2(%r15),%ebx
cmp    $0x5,%eax
cmove  %r15d,%ebx
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <write@plt>
lea    0x4(%rbx),%ecx
cmp    $0x5,%eax
cmove  %ebx,%ecx
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@.str = [6 x i8] c"test\0A\00"
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%3 = load i32, i32* @STDIN_FILENO
%4 = call i32 @write(i32 %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%5 = icmp ne i32 %4, 5
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* %2
%8 = or i32 %7, 1
store i32 %8, i32* %2
br label %9
9: ; preds = %6, %0
%10 = load i32, i32* @STDOUT_FILENO
%11 = call i32 @write(i32 %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%12 = icmp ne i32 %11, 5
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* %2
%15 = or i32 %14, 2
store i32 %15, i32* %2
br label %16
16: ; preds = %13, %9
%17 = load i32, i32* @STDERR_FILENO
%18 = call i32 @write(i32 %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%19 = icmp ne i32 %18, 5
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* %2
%22 = or i32 %21, 4
store i32 %22, i32* %2
br label %23
23: ; preds = %20, %16
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@.str = [6 x i8] c"test\0A\00"
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define i32 @main() {
%1 = load i32, i32* @STDIN_FILENO
%2 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%3 = icmp ne i32 %2, 5
%4 = zext i1 %3 to i32
%5 = load i32, i32* @STDOUT_FILENO
%6 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%7 = icmp eq i32 %6, 5
%8 = or i32 %4, 2
%9 = select i1 %7, i32 %4, i32 %8
%10 = load i32, i32* @STDERR_FILENO
%11 = tail call i32 @write(i32 %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%12 = icmp eq i32 %11, 5
%13 = or i32 %9, 4
%14 = select i1 %12, i32 %9, i32 %13
ret i32 %14
}