#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 */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdout;
FILE *fdopenw(int fd) {
  assert(fd != 0);
  switch (fd) {
  case 1:
    return stdout;
  case 2:
    return stderr;
  default:
    return fdopen(fd, "w");
  }
}


x86 assembly (clang, -O0):
<fdopenw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
test   %eax,%eax
setne  %al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x1,%eax
je     1160 <fdopenw+0x40>
jmp    114f <fdopenw+0x2f>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
je     1173 <fdopenw+0x53>
jmp    1186 <fdopenw+0x66>
mov    0x2e71(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    1199 <fdopenw+0x79>
mov    0x2e66(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    1199 <fdopenw+0x79>
mov    -0xc(%rbp),%edi
lea    0xe70(%rip),%rsi
call   1040 <fdopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fdopenw>:
push   %rbx
mov    %edi,%ebx
xor    %edi,%edi
test   %ebx,%ebx
setne  %dil
call   1030 <assert@plt>
cmp    $0x2,%ebx
je     1143 <fdopenw+0x23>
cmp    $0x1,%ebx
jne    114f <fdopenw+0x2f>
mov    0x2e97(%rip),%rax
jmp    114a <fdopenw+0x2a>
mov    0x2e96(%rip),%rax
mov    (%rax),%rax
pop    %rbx
ret
lea    0xeaa(%rip),%rsi
mov    %ebx,%edi
pop    %rbx
jmp    1040 <fdopen@plt>

LLVM IR (-O0):
@stdout = global i32* null
@stderr = global i32* null
@.str = [2 x i8] c"w\00"
define i32* @fdopenw(i32 %0) {
%2 = alloca i32*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp ne i32 %4, 0
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = load i32, i32* %3
switch i32 %8, label %13 [
i32 1, label %9
i32 2, label %11
]
9: ; preds = %1
%10 = load i32*, i32** @stdout
store i32* %10, i32** %2
br label %16
11: ; preds = %1
%12 = load i32*, i32** @stderr
store i32* %12, i32** %2
br label %16
13: ; preds = %1
%14 = load i32, i32* %3
%15 = call i32* @fdopen(i32 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %2
br label %16
16: ; preds = %13, %11, %9
%17 = load i32*, i32** %2
ret i32* %17
}

LLVM IR (-O2):
@stdout = global i32* null
@stderr = global i32* null
@.str = [2 x i8] c"w\00"
define i32* @fdopenw(i32 %0) {
%2 = icmp ne i32 %0, 0
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
switch i32 %0, label %9 [
i32 1, label %5
i32 2, label %7
]
5: ; preds = %1
%6 = load i32*, i32** @stdout
br label %11
7: ; preds = %1
%8 = load i32*, i32** @stderr
br label %11
9: ; preds = %1
%10 = tail call i32* @fdopen(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %7, %5
%12 = phi i32* [ %10, %9 ], [ %8, %7 ], [ %6, %5 ]
ret i32* %12
}