#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*/ fclose(int /*<<< orphan*/ *);
int stbi__err(char *);
int /*<<< orphan*/ *stbi__fopen(char const *, char *);
int stbi_is_16_bit_from_file(int /*<<< orphan*/ *);
extern int stbi_is_16_bit(char const *filename) {
  FILE *f = stbi__fopen(filename, "rb");
  int result;
  if (!f)
    return stbi__err("can't fopen");
  result = stbi_is_16_bit_from_file(f);
  fclose(f);
  return result;
}


x86 assembly (clang, -O0):
<stbi_is_16_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <stbi__fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117f <stbi_is_16_bit+0x3f>
lea    0xe91(%rip),%rdi
call   1060 <stbi__err@plt>
mov    %eax,-0x4(%rbp)
jmp    119a <stbi_is_16_bit+0x5a>
mov    -0x18(%rbp),%rdi
call   1040 <stbi_is_16_bit_from_file@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stbi_is_16_bit>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rsi
call   1050 <stbi__fopen@plt>
test   %rax,%rax
je     1172 <stbi_is_16_bit+0x32>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <stbi_is_16_bit_from_file@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe8a(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <stbi__err@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [12 x i8] c"can't fopen\00"
define i32 @stbi_is_16_bit(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @stbi__fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = call i32 @stbi__err(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 %11, i32* %2
br label %18
12: ; preds = %1
%13 = load i32*, i32** %4
%14 = call i32 @stbi_is_16_bit_from_file(i32* %13)
store i32 %14, i32* %5
%15 = load i32*, i32** %4
%16 = call i32 @fclose(i32* %15)
%17 = load i32, i32* %5
store i32 %17, i32* %2
br label %18
18: ; preds = %12, %10
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [12 x i8] c"can't fopen\00"
define i32 @stbi_is_16_bit(i8* %0) {
%2 = tail call i32* @stbi__fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @stbi__err(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %9
6: ; preds = %1
%7 = tail call i32 @stbi_is_16_bit_from_file(i32* %2)
%8 = tail call i32 @fclose(i32* %2)
br label %9
9: ; preds = %6, %4
%10 = phi i32 [ %7, %6 ], [ %5, %4 ]
ret i32 %10
}