#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 */
struct resource {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
struct resource *fdstream_resource(char const *, int, char const *);
int open(char const *, int /*<<< orphan*/);
struct resource *fdstream_resource_open(const char *urlpath,
                                        const char *filepath,
                                        const char *content_type) {
  int fd;
  if ((fd = open(filepath, O_RDONLY)) == -1)
    return NULL;
  return fdstream_resource(urlpath, fd, content_type);
}


x86 assembly (clang, -O0):
<fdstream_resource_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    115f <fdstream_resource_open+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    1173 <fdstream_resource_open+0x53>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1030 <fdstream_resource@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fdstream_resource_open>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rax
mov    %rdi,%rbx
mov    0x2eb4(%rip),%rcx
mov    (%rcx),%esi
mov    %rax,%rdi
call   1040 <open@plt>
cmp    $0xffffffff,%eax
je     1157 <fdstream_resource_open+0x37>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fdstream_resource@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.resource = type { i32 }
@O_RDONLY = global i32 0
define %struct.resource* @fdstream_resource_open(i8* %0, i8* %1, i8* %2) {
%4 = alloca %struct.resource*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %6
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %8
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %3
store %struct.resource* null, %struct.resource** %4
br label %19
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = load i32, i32* %8
%17 = load i8*, i8** %7
%18 = call %struct.resource* @fdstream_resource(i8* %15, i32 %16, i8* %17)
store %struct.resource* %18, %struct.resource** %4
br label %19
19: ; preds = %14, %13
%20 = load %struct.resource*, %struct.resource** %4
ret %struct.resource* %20
}

LLVM IR (-O2):
%struct.resource = type { i32 }
@O_RDONLY = global i32 0
define %struct.resource* @fdstream_resource_open(i8* %0, i8* nocapture %1, i8* %2) {
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %1, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call %struct.resource* @fdstream_resource(i8* %0, i32 %5, i8* %2)
br label %9
9: ; preds = %3, %7
%10 = phi %struct.resource* [ %8, %7 ], [ null, %3 ]
ret %struct.resource* %10
}