#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*/ uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
scalar_t__ librpip_dt_file_open(int, int, int /*<<< orphan*/, int *);
int read(int, int /*<<< orphan*/ *, int);
uint32_t librpip_dt_file_get_raw(uint32_t moduleid, uint32_t fileid,
                                 uint8_t *buf, uint32_t len, uint32_t *rlen) {
  int fd, result;
  result = 0;
  if (librpip_dt_file_open(moduleid, fileid, O_RDONLY, &fd)) {
    *rlen = read(fd, buf, len);
    if (*rlen) {
      result = 1;
    }
    close(fd);
  }
  return result;
}


x86 assembly (clang, -O0):
<librpip_dt_file_get_raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x2e8b(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rcx
call   1040 <librpip_dt_file_open@plt>
cmp    $0x0,%rax
je     11a5 <librpip_dt_file_get_raw+0x75>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <read@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
je     119d <librpip_dt_file_get_raw+0x6d>
movl   $0x1,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <close@plt>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<librpip_dt_file_get_raw>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r14
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    0x2ea1(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
call   1040 <librpip_dt_file_open@plt>
test   %rax,%rax
je     117b <librpip_dt_file_get_raw+0x4b>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <read@plt>
mov    %eax,(%r14)
xor    %ebx,%ebx
test   %eax,%eax
setne  %bl
mov    0xc(%rsp),%edi
call   1030 <close@plt>
jmp    117d <librpip_dt_file_get_raw+0x4d>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @librpip_dt_file_get_raw(i32 %0, i32 %1, i32* %2, i32 %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32 %3, i32* %9
store i32* %4, i32** %10
store i32 0, i32* %12
%13 = load i32, i32* %6
%14 = load i32, i32* %7
%15 = load i32, i32* @O_RDONLY
%16 = call i64 @librpip_dt_file_open(i32 %13, i32 %14, i32 %15, i32* %11)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %5
%19 = load i32, i32* %11
%20 = load i32*, i32** %8
%21 = load i32, i32* %9
%22 = call i32 @read(i32 %19, i32* %20, i32 %21)
%23 = load i32*, i32** %10
store i32 %22, i32* %23
%24 = load i32*, i32** %10
%25 = load i32, i32* %24
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %18
store i32 1, i32* %12
br label %28
28: ; preds = %27, %18
%29 = load i32, i32* %11
%30 = call i32 @close(i32 %29)
br label %31
31: ; preds = %28, %5
%32 = load i32, i32* %12
ret i32 %32
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @librpip_dt_file_get_raw(i32 %0, i32 %1, i32* nocapture %2, i32 %3, i32* nocapture writeonly %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = load i32, i32* @O_RDONLY
%9 = call i64 @librpip_dt_file_open(i32 %0, i32 %1, i32 %8, i32* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %5
%12 = load i32, i32* %6
%13 = call i32 @read(i32 %12, i32* %2, i32 %3)
store i32 %13, i32* %4
%14 = icmp ne i32 %13, 0
%15 = zext i1 %14 to i32
%16 = load i32, i32* %6
%17 = call i32 @close(i32 %16)
br label %18
18: ; preds = %11, %5
%19 = phi i32 [ %15, %11 ], [ 0, %5 ]
ret i32 %19
}