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

/* Variables and functions */
int /*<<< orphan*/ dns_hosts_close(struct dns_hosts *);
int dns_hosts_loadpath(struct dns_hosts *, char *);
struct dns_hosts *dns_hosts_open(int *);
struct dns_hosts *dns_hosts_local(int *error_) {
  struct dns_hosts *hosts;
  int error;
  if (!(hosts = dns_hosts_open(&error)))
    goto error;
  if ((error = dns_hosts_loadpath(hosts, "/etc/hosts")))
    goto error;
  return hosts;
error:
  *error_ = error;
  dns_hosts_close(hosts);
  return 0;
}


x86 assembly (clang, -O0):
<dns_hosts_local>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x1c(%rbp),%rdi
call   1040 <dns_hosts_open@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1158 <dns_hosts_local+0x28>
jmp    1186 <dns_hosts_local+0x56>
mov    -0x18(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1030 <dns_hosts_loadpath@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     1179 <dns_hosts_local+0x49>
jmp    1186 <dns_hosts_local+0x56>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a0 <dns_hosts_local+0x70>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rdi
call   1050 <dns_hosts_close@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dns_hosts_local>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0x4(%rsp),%rdi
call   1040 <dns_hosts_open@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1162 <dns_hosts_local+0x32>
lea    0xeb0(%rip),%rsi
mov    %rbx,%rdi
call   1030 <dns_hosts_loadpath@plt>
mov    %eax,0x4(%rsp)
test   %eax,%eax
jne    1166 <dns_hosts_local+0x36>
jmp    1173 <dns_hosts_local+0x43>
mov    0x4(%rsp),%eax
mov    %eax,(%r14)
mov    %rbx,%rdi
call   1050 <dns_hosts_close@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.dns_hosts = type { i32 }
@.str = [11 x i8] c"/etc/hosts\00"
define %struct.dns_hosts* @dns_hosts_local(i32* %0) {
%2 = alloca %struct.dns_hosts*
%3 = alloca i32*
%4 = alloca %struct.dns_hosts*
%5 = alloca i32
store i32* %0, i32** %3
%6 = call %struct.dns_hosts* @dns_hosts_open(i32* %5)
store %struct.dns_hosts* %6, %struct.dns_hosts** %4
%7 = icmp ne %struct.dns_hosts* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
br label %16
9: ; preds = %1
%10 = load %struct.dns_hosts*, %struct.dns_hosts** %4
%11 = call i32 @dns_hosts_loadpath(%struct.dns_hosts* %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %5
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
br label %16
14: ; preds = %9
%15 = load %struct.dns_hosts*, %struct.dns_hosts** %4
store %struct.dns_hosts* %15, %struct.dns_hosts** %2
br label %21
16: ; preds = %13, %8
%17 = load i32, i32* %5
%18 = load i32*, i32** %3
store i32 %17, i32* %18
%19 = load %struct.dns_hosts*, %struct.dns_hosts** %4
%20 = call i32 @dns_hosts_close(%struct.dns_hosts* %19)
store %struct.dns_hosts* null, %struct.dns_hosts** %2
br label %21
21: ; preds = %16, %14
%22 = load %struct.dns_hosts*, %struct.dns_hosts** %2
ret %struct.dns_hosts* %22
}

LLVM IR (-O2):
%struct.dns_hosts = type { i32 }
@.str = [11 x i8] c"/etc/hosts\00"
define %struct.dns_hosts* @dns_hosts_local(i32* nocapture writeonly %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call %struct.dns_hosts* @dns_hosts_open(i32* %2)
%5 = icmp eq %struct.dns_hosts* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = load i32, i32* %2
br label %11
8: ; preds = %1
%9 = call i32 @dns_hosts_loadpath(%struct.dns_hosts* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 %9, i32* %2
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %6, %8
%12 = phi i32 [ %7, %6 ], [ %9, %8 ]
store i32 %12, i32* %0
%13 = call i32 @dns_hosts_close(%struct.dns_hosts* %4)
br label %14
14: ; preds = %8, %11
%15 = phi %struct.dns_hosts* [ null, %11 ], [ %4, %8 ]
ret %struct.dns_hosts* %15
}