#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*/ assert(int);
scalar_t__ stderr;
scalar_t__ stdin;
scalar_t__ stdout;
char *getstdfileptr(int fd) {
  assert(fd >= 0);
  assert(fd <= 2);
  assert(((uintptr_t)((char *)stdin)) == ((uintptr_t)stdin));
  switch (fd) {
  case 0:
    return (char *)stdin;
  case 1:
    return (char *)stdout;
  case 2:
    return (char *)stderr;
  default:
    assert(0);
  }
}


x86 assembly (clang, -O0):
<getstdfileptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
mov    -0xc(%rbp),%eax
sub    $0x3,%eax
setl   %al
movzbl %al,%edi
call   1030 <assert@plt>
mov    $0x1,%edi
call   1030 <assert@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
test   %eax,%eax
je     1178 <getstdfileptr+0x68>
jmp    1156 <getstdfileptr+0x46>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
je     118b <getstdfileptr+0x7b>
jmp    1167 <getstdfileptr+0x57>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
je     119e <getstdfileptr+0x8e>
jmp    11b1 <getstdfileptr+0xa1>
mov    0x2e69(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11b8 <getstdfileptr+0xa8>
mov    0x2e3e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11b8 <getstdfileptr+0xa8>
mov    0x2e33(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11b8 <getstdfileptr+0xa8>
xor    %edi,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getstdfileptr>:
push   %rbx
mov    %edi,%ebx
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
xor    %edi,%edi
cmp    $0x3,%ebx
setl   %dil
call   1030 <assert@plt>
mov    $0x1,%edi
call   1030 <assert@plt>
cmp    $0x2,%ebx
je     114c <getstdfileptr+0x3c>
cmp    $0x1,%ebx
je     1155 <getstdfileptr+0x45>
test   %ebx,%ebx
jne    1161 <getstdfileptr+0x51>
mov    0x2e9e(%rip),%rax
jmp    115c <getstdfileptr+0x4c>
mov    0x2e85(%rip),%rax
jmp    115c <getstdfileptr+0x4c>
mov    0x2e74(%rip),%rax
mov    (%rax),%rax
pop    %rbx
ret
xor    %edi,%edi
call   1030 <assert@plt>
pop    %rbx
ret

LLVM IR (-O0):
@stdin = global i64 0
@stdout = global i64 0
@stderr = global i64 0
define i8* @getstdfileptr(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp sge i32 %4, 0
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = load i32, i32* %3
%9 = icmp sle i32 %8, 2
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i64, i64* @stdin
%13 = inttoptr i64 %12 to i8*
%14 = ptrtoint i8* %13 to i64
%15 = load i64, i64* @stdin
%16 = icmp eq i64 %14, %15
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32, i32* %3
switch i32 %19, label %29 [
i32 0, label %20
i32 1, label %23
i32 2, label %26
]
20: ; preds = %1
%21 = load i64, i64* @stdin
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %2
br label %31
23: ; preds = %1
%24 = load i64, i64* @stdout
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %2
br label %31
26: ; preds = %1
%27 = load i64, i64* @stderr
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %2
br label %31
29: ; preds = %1
%30 = call i32 @assert(i32 0)
br label %31
31: ; preds = %20, %23, %26, %29
%32 = load i8*, i8** %2
ret i8* %32
}

LLVM IR (-O2):
@stdin = global i64 0
@stdout = global i64 0
@stderr = global i64 0
define i8* @getstdfileptr(i32 %0) {
%2 = xor i32 %0, -1
%3 = lshr i32 %2, 31
%4 = tail call i32 @assert(i32 %3)
%5 = icmp slt i32 %0, 3
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i32 @assert(i32 1)
switch i32 %0, label %18 [
i32 0, label %9
i32 1, label %12
i32 2, label %15
]
9: ; preds = %1
%10 = load i64, i64* @stdin
%11 = inttoptr i64 %10 to i8*
br label %20
12: ; preds = %1
%13 = load i64, i64* @stdout
%14 = inttoptr i64 %13 to i8*
br label %20
15: ; preds = %1
%16 = load i64, i64* @stderr
%17 = inttoptr i64 %16 to i8*
br label %20
18: ; preds = %1
%19 = tail call i32 @assert(i32 0)
br label %20
20: ; preds = %9, %12, %15, %18
%21 = phi i8* [ undef, %18 ], [ %17, %15 ], [ %14, %12 ], [ %11, %9 ]
ret i8* %21
}