#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 exfat_inode {
  int dummy;
};
struct exfat_de_iter {
  int dummy;
};

/* Variables and functions */
int EINVAL;
int check_inode(struct exfat_de_iter *, struct exfat_inode *);
int /*<<< orphan*/ free_exfat_inode(struct exfat_inode *);
int read_file_dentries(struct exfat_de_iter *, struct exfat_inode **, int *);
int read_file(struct exfat_de_iter *de_iter, struct exfat_inode **new_node,
              int *dentry_count) {
  struct exfat_inode *node;
  int ret;
  *new_node = NULL;
  ret = read_file_dentries(de_iter, &node, dentry_count);
  if (ret)
    return ret;
  ret = check_inode(de_iter, node);
  if (ret < 0) {
    free_exfat_inode(node);
    return -EINVAL;
  }
  *new_node = node;
  return ret;
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rsi
call   1030 <read_file_dentries@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1178 <read_file+0x48>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11bf <read_file+0x8f>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <check_inode@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11ae <read_file+0x7e>
mov    -0x28(%rbp),%rdi
call   1040 <free_exfat_inode@plt>
xor    %eax,%eax
mov    0x2e3c(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11bf <read_file+0x8f>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,(%rsi)
mov    %rsp,%rsi
call   1030 <read_file_dentries@plt>
test   %eax,%eax
jne    1176 <read_file+0x46>
mov    (%rsp),%rsi
mov    %rbx,%rdi
call   1050 <check_inode@plt>
mov    (%rsp),%rdi
test   %eax,%eax
js     1166 <read_file+0x36>
mov    %rdi,(%r14)
jmp    1176 <read_file+0x46>
call   1040 <free_exfat_inode@plt>
mov    0x2e6e(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.exfat_de_iter = type { i32 }
%struct.exfat_inode = type { i32 }
@EINVAL = global i32 0
define i32 @read_file(%struct.exfat_de_iter* %0, %struct.exfat_inode** %1, i32* %2) {
%4 = alloca i32
%5 = alloca %struct.exfat_de_iter*
%6 = alloca %struct.exfat_inode**
%7 = alloca i32*
%8 = alloca %struct.exfat_inode*
%9 = alloca i32
store %struct.exfat_de_iter* %0, %struct.exfat_de_iter** %5
store %struct.exfat_inode** %1, %struct.exfat_inode*** %6
store i32* %2, i32** %7
%10 = load %struct.exfat_inode**, %struct.exfat_inode*** %6
store %struct.exfat_inode* null, %struct.exfat_inode** %10
%11 = load %struct.exfat_de_iter*, %struct.exfat_de_iter** %5
%12 = load i32*, i32** %7
%13 = call i32 @read_file_dentries(%struct.exfat_de_iter* %11, %struct.exfat_inode** %8, i32* %12)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = load i32, i32* %9
store i32 %17, i32* %4
br label %33
18: ; preds = %3
%19 = load %struct.exfat_de_iter*, %struct.exfat_de_iter** %5
%20 = load %struct.exfat_inode*, %struct.exfat_inode** %8
%21 = call i32 @check_inode(%struct.exfat_de_iter* %19, %struct.exfat_inode* %20)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %18
%25 = load %struct.exfat_inode*, %struct.exfat_inode** %8
%26 = call i32 @free_exfat_inode(%struct.exfat_inode* %25)
%27 = load i32, i32* @EINVAL
%28 = sub nsw i32 0, %27
store i32 %28, i32* %4
br label %33
29: ; preds = %18
%30 = load %struct.exfat_inode*, %struct.exfat_inode** %8
%31 = load %struct.exfat_inode**, %struct.exfat_inode*** %6
store %struct.exfat_inode* %30, %struct.exfat_inode** %31
%32 = load i32, i32* %9
store i32 %32, i32* %4
br label %33
33: ; preds = %29, %24, %16
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
%struct.exfat_de_iter = type { i32 }
%struct.exfat_inode = type { i32 }
@EINVAL = global i32 0
define i32 @read_file(%struct.exfat_de_iter* %0, %struct.exfat_inode** nocapture writeonly %1, i32* %2) {
%4 = alloca %struct.exfat_inode*
%5 = bitcast %struct.exfat_inode** %4 to i8*
store %struct.exfat_inode* null, %struct.exfat_inode** %1
%6 = call i32 @read_file_dentries(%struct.exfat_de_iter* %0, %struct.exfat_inode** %4, i32* %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %3
%9 = load %struct.exfat_inode*, %struct.exfat_inode** %4
%10 = call i32 @check_inode(%struct.exfat_de_iter* %0, %struct.exfat_inode* %9)
%11 = icmp slt i32 %10, 0
%12 = load %struct.exfat_inode*, %struct.exfat_inode** %4
br i1 %11, label %13, label %17
13: ; preds = %8
%14 = call i32 @free_exfat_inode(%struct.exfat_inode* %12)
%15 = load i32, i32* @EINVAL
%16 = sub nsw i32 0, %15
br label %18
17: ; preds = %8
store %struct.exfat_inode* %12, %struct.exfat_inode** %1
br label %18
18: ; preds = %3, %17, %13
%19 = phi i32 [ %16, %13 ], [ %10, %17 ], [ %6, %3 ]
ret i32 %19
}