#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 in_addr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ herror(char *);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, struct in_addr *);
int /*<<< orphan*/ memcpy(struct in_addr *, int /*<<< orphan*/, int);
bool parse(struct in_addr *output, char *source) {
  if (inet_pton(AF_INET, source, output))
    return false;
  struct hostent *he;
  if (!(he = gethostbyname(source))) {
    herror("gethostbyname");
    return true;
  }
  memcpy(output, he->h_addr, sizeof(struct in_addr));
  return false;
}


x86 assembly (clang, -O0):
<parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <inet_pton@plt>
cmp    $0x0,%rax
je     117c <parse+0x3c>
movl   $0x0,-0x4(%rbp)
jmp    11c6 <parse+0x86>
mov    -0x18(%rbp),%rdi
call   1030 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11ab <parse+0x6b>
lea    0xe66(%rip),%rdi
call   1060 <herror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c6 <parse+0x86>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
mov    $0x4,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rdx
call   1050 <inet_pton@plt>
xor    %r14d,%r14d
test   %rax,%rax
jne    1193 <parse+0x53>
mov    %rbp,%rdi
call   1030 <gethostbyname@plt>
test   %rax,%rax
je     1181 <parse+0x41>
mov    (%rax),%esi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
jmp    1193 <parse+0x53>
lea    0xe78(%rip),%rdi
call   1060 <herror@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.hostent = type { i32 }
@AF_INET = global i32 0
@.str = [14 x i8] c"gethostbyname\00"
define i32 @parse(%struct.in_addr* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.in_addr*
%5 = alloca i8*
%6 = alloca %struct.hostent*
store %struct.in_addr* %0, %struct.in_addr** %4
store i8* %1, i8** %5
%7 = load i32, i32* @AF_INET
%8 = load i8*, i8** %5
%9 = load %struct.in_addr*, %struct.in_addr** %4
%10 = call i64 @inet_pton(i32 %7, i8* %8, %struct.in_addr* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %25
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = call %struct.hostent* @gethostbyname(i8* %14)
store %struct.hostent* %15, %struct.hostent** %6
%16 = icmp ne %struct.hostent* %15, null
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = call i32 @herror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %25
19: ; preds = %13
%20 = load %struct.in_addr*, %struct.in_addr** %4
%21 = load %struct.hostent*, %struct.hostent** %6
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @memcpy(%struct.in_addr* %20, i32 %23, i32 4)
store i32 0, i32* %3
br label %25
25: ; preds = %19, %17, %12
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i32 }
@AF_INET = global i32 0
@.str = [14 x i8] c"gethostbyname\00"
define i32 @parse(%struct.in_addr* %0, i8* %1) {
%3 = load i32, i32* @AF_INET
%4 = tail call i64 @inet_pton(i32 %3, i8* %1, %struct.in_addr* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = tail call %struct.hostent* @gethostbyname(i8* %1)
%8 = icmp eq %struct.hostent* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @herror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %15
11: ; preds = %6
%12 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 0
%13 = load i32, i32* %12
%14 = tail call i32 @memcpy(%struct.in_addr* %0, i32 %13, i32 4)
br label %15
15: ; preds = %9, %11, %2
%16 = phi i32 [ 0, %2 ], [ 0, %11 ], [ 1, %9 ]
ret i32 %16
}