#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 */
scalar_t__ ENOENT;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int /*<<< orphan*/ *fopen(char *, char *);
int main(void) {
  FILE *fp = NULL;
  errno = 0, fp = fopen("test.txt", "r"), assert(fp == NULL),
  assert(errno == ENOENT);
  errno = 0, fp = fopen("test.txt", "rb"), assert(fp == NULL),
  assert(errno == ENOENT);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    0x2ea2(%rip),%rax
movq   $0x0,(%rax)
lea    0xeb4(%rip),%rdi
lea    0xeb6(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%rax
mov    0x2e51(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    0x2e4a(%rip),%rax
movq   $0x0,(%rax)
lea    0xe5c(%rip),%rdi
lea    0xe60(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%rax
mov    0x2df9(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2eb4(%rip),%rbx
movq   $0x0,(%rbx)
lea    0xec6(%rip),%r14
lea    0xec8(%rip),%rsi
mov    %r14,%rdi
call   1040 <fopen@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1030 <assert@plt>
mov    (%rbx),%rax
mov    0x2e6f(%rip),%r15
xor    %edi,%edi
cmp    (%r15),%rax
sete   %dil
call   1030 <assert@plt>
movq   $0x0,(%rbx)
lea    0xe8e(%rip),%rsi
mov    %r14,%rdi
call   1040 <fopen@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1030 <assert@plt>
mov    (%rbx),%rax
xor    %edi,%edi
cmp    (%r15),%rax
sete   %dil
call   1030 <assert@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@ENOENT = global i64 0
@.str.2 = [3 x i8] c"rb\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
store i32* null, i32** %2
store i64 0, i64* @errno
%3 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = icmp eq i32* %4, null
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = load i64, i64* @errno
%9 = load i64, i64* @ENOENT
%10 = icmp eq i64 %8, %9
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
store i64 0, i64* @errno
%13 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %13, i32** %2
%14 = load i32*, i32** %2
%15 = icmp eq i32* %14, null
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i64, i64* @errno
%19 = load i64, i64* @ENOENT
%20 = icmp eq i64 %18, %19
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
ret i32 0
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@ENOENT = global i64 0
@.str.2 = [3 x i8] c"rb\00"
define i32 @main() {
store i64 0, i64* @errno
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = load i64, i64* @errno
%6 = load i64, i64* @ENOENT
%7 = icmp eq i64 %5, %6
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
store i64 0, i64* @errno
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32* %10, null
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = load i64, i64* @errno
%15 = load i64, i64* @ENOENT
%16 = icmp eq i64 %14, %15
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
ret i32 0
}