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

/* Variables and functions */
int /*<<< orphan*/ cxl_afu_free(struct cxl_afu_h *);
struct cxl_afu_h *malloc_afu();
scalar_t__ open_afu_dev(struct cxl_afu_h *, char *);
struct cxl_afu_h *cxl_afu_open_dev(char *path) {
  struct cxl_afu_h *afu;
  if (!(afu = malloc_afu()))
    return NULL;
  if (open_afu_dev(afu, path) < 0)
    goto err;
  return afu;
err:
  cxl_afu_free(afu);
  return NULL;
}


x86 assembly (clang, -O0):
<cxl_afu_open_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <malloc_afu@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    115e <cxl_afu_open_dev+0x2e>
movq   $0x0,-0x8(%rbp)
jmp    1198 <cxl_afu_open_dev+0x68>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <open_afu_dev@plt>
cmp    $0x0,%rax
jge    117a <cxl_afu_open_dev+0x4a>
jmp    1187 <cxl_afu_open_dev+0x57>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1198 <cxl_afu_open_dev+0x68>
mov    -0x18(%rbp),%rdi
call   1030 <cxl_afu_free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cxl_afu_open_dev>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <malloc_afu@plt>
test   %rax,%rax
je     115e <cxl_afu_open_dev+0x2e>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <open_afu_dev@plt>
test   %rax,%rax
jns    1160 <cxl_afu_open_dev+0x30>
mov    %rbx,%rdi
call   1030 <cxl_afu_free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.cxl_afu_h = type { i32 }
define %struct.cxl_afu_h* @cxl_afu_open_dev(i8* %0) {
%2 = alloca %struct.cxl_afu_h*
%3 = alloca i8*
%4 = alloca %struct.cxl_afu_h*
store i8* %0, i8** %3
%5 = call %struct.cxl_afu_h* (...) @malloc_afu()
store %struct.cxl_afu_h* %5, %struct.cxl_afu_h** %4
%6 = icmp ne %struct.cxl_afu_h* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store %struct.cxl_afu_h* null, %struct.cxl_afu_h** %2
br label %19
8: ; preds = %1
%9 = load %struct.cxl_afu_h*, %struct.cxl_afu_h** %4
%10 = load i8*, i8** %3
%11 = call i64 @open_afu_dev(%struct.cxl_afu_h* %9, i8* %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %8
br label %16
14: ; preds = %8
%15 = load %struct.cxl_afu_h*, %struct.cxl_afu_h** %4
store %struct.cxl_afu_h* %15, %struct.cxl_afu_h** %2
br label %19
16: ; preds = %13
%17 = load %struct.cxl_afu_h*, %struct.cxl_afu_h** %4
%18 = call i32 @cxl_afu_free(%struct.cxl_afu_h* %17)
store %struct.cxl_afu_h* null, %struct.cxl_afu_h** %2
br label %19
19: ; preds = %16, %14, %7
%20 = load %struct.cxl_afu_h*, %struct.cxl_afu_h** %2
ret %struct.cxl_afu_h* %20
}

LLVM IR (-O2):
%struct.cxl_afu_h = type { i32 }
define %struct.cxl_afu_h* @cxl_afu_open_dev(i8* %0) {
%2 = tail call %struct.cxl_afu_h* (...) @malloc_afu()
%3 = icmp eq %struct.cxl_afu_h* %2, null
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = tail call i64 @open_afu_dev(%struct.cxl_afu_h* %2, i8* %0)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @cxl_afu_free(%struct.cxl_afu_h* %2)
br label %9
9: ; preds = %4, %1, %7
%10 = phi %struct.cxl_afu_h* [ null, %7 ], [ null, %1 ], [ %2, %4 ]
ret %struct.cxl_afu_h* %10
}