#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 FB {
  int dummy;
};

/* Variables and functions */
scalar_t__ _fb_info(struct FB *);
scalar_t__ _fb_mmap(struct FB *, int);
scalar_t__ _fb_open(struct FB *, int);
int /*<<< orphan*/ fb_close(struct FB *);
int fb_open(struct FB *fb, int readonly) {
  int ret = -1;
  do {
    if (_fb_open(fb, readonly) < 0) {
      break;
    }
    if (_fb_info(fb) < 0) {
      break;
    }
    if (_fb_mmap(fb, readonly) < 0) {
      break;
    }
    ret = 0;
  } while (0);
  if (ret < 0) {
    fb_close(fb);
  }
  return ret;
}


x86 assembly (clang, -O0):
<fb_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <_fb_open@plt>
cmp    $0x0,%rax
jge    1171 <fb_open+0x31>
jmp    11ab <fb_open+0x6b>
mov    -0x8(%rbp),%rdi
call   1060 <_fb_info@plt>
cmp    $0x0,%rax
jge    1189 <fb_open+0x49>
jmp    11ab <fb_open+0x6b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <_fb_mmap@plt>
cmp    $0x0,%rax
jge    11a4 <fb_open+0x64>
jmp    11ab <fb_open+0x6b>
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11be <fb_open+0x7e>
mov    -0x8(%rbp),%rdi
call   1030 <fb_close@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fb_open>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <_fb_open@plt>
test   %rax,%rax
js     1173 <fb_open+0x33>
mov    %rbx,%rdi
call   1060 <_fb_info@plt>
test   %rax,%rax
js     1173 <fb_open+0x33>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <_fb_mmap@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jns    1180 <fb_open+0x40>
mov    %rbx,%rdi
call   1030 <fb_close@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.FB = type { i32 }
define i32 @fb_open(%struct.FB* %0, i32 %1) {
%3 = alloca %struct.FB*
%4 = alloca i32
%5 = alloca i32
store %struct.FB* %0, %struct.FB** %3
store i32 %1, i32* %4
store i32 -1, i32* %5
br label %6
6: ; preds = %2
%7 = load %struct.FB*, %struct.FB** %3
%8 = load i32, i32* %4
%9 = call i64 @_fb_open(%struct.FB* %7, i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %6
br label %24
12: ; preds = %6
%13 = load %struct.FB*, %struct.FB** %3
%14 = call i64 @_fb_info(%struct.FB* %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
br label %24
17: ; preds = %12
%18 = load %struct.FB*, %struct.FB** %3
%19 = load i32, i32* %4
%20 = call i64 @_fb_mmap(%struct.FB* %18, i32 %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17
br label %24
23: ; preds = %17
store i32 0, i32* %5
br label %24
24: ; preds = %23, %22, %16, %11
%25 = load i32, i32* %5
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load %struct.FB*, %struct.FB** %3
%29 = call i32 @fb_close(%struct.FB* %28)
br label %30
30: ; preds = %27, %24
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
%struct.FB = type { i32 }
define i32 @fb_open(%struct.FB* %0, i32 %1) {
%3 = tail call i64 @_fb_open(%struct.FB* %0, i32 %1)
%4 = icmp slt i64 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = tail call i64 @_fb_info(%struct.FB* %0)
%7 = icmp slt i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i64 @_fb_mmap(%struct.FB* %0, i32 %1)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2, %5, %8
%12 = tail call i32 @fb_close(%struct.FB* %0)
br label %13
13: ; preds = %11, %8
%14 = phi i32 [ -1, %11 ], [ 0, %8 ]
ret i32 %14
}