#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 */
typedef int /*<<< orphan*/ u_int32_t;
struct in_addr {
  int /*<<< orphan*/ s_addr;
};
struct hostent {
  scalar_t__ *h_addr_list;
};

/* Variables and functions */
struct hostent *gethostbyname(char *);
scalar_t__ inet_aton(char *, struct in_addr *);
int /*<<< orphan*/ ntohl(int /*<<< orphan*/);
int /*<<< orphan*/ panic(char *, char *);
scalar_t__ strtou32(int /*<<< orphan*/ *, char *);
u_int32_t aspectou32(char *astr, int dns) {
  u_int32_t addr;
  struct hostent *h;
  struct in_addr s;
  if (strtou32(&addr, astr))
    ;
  else if (dns && ((h = gethostbyname(astr)) != NULL))
    addr = ntohl(*((u_int32_t *)h->h_addr_list[0]));
  else if (inet_aton(astr, &s))
    addr = ntohl(s.s_addr);
  else
    panic("unable to parse \"%s\"", astr);
  return (addr);
}


x86 assembly (clang, -O0):
<aspectou32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdi
call   1050 <strtou32@plt>
cmp    $0x0,%rax
je     117b <aspectou32+0x2b>
jmp    11f6 <aspectou32+0xa6>
cmpl   $0x0,-0xc(%rbp)
je     11b5 <aspectou32+0x65>
mov    -0x8(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11b5 <aspectou32+0x65>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1070 <ntohl@plt>
mov    %eax,-0x10(%rbp)
jmp    11f1 <aspectou32+0xa1>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <inet_aton@plt>
cmp    $0x0,%rax
je     11dc <aspectou32+0x8c>
mov    -0x20(%rbp),%edi
call   1070 <ntohl@plt>
mov    %eax,-0x10(%rbp)
jmp    11ec <aspectou32+0x9c>
mov    -0x8(%rbp),%rsi
lea    0xe19(%rip),%rdi
call   1030 <panic@plt>
jmp    11f1 <aspectou32+0xa1>
jmp    11f6 <aspectou32+0xa6>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aspectou32>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
call   1050 <strtou32@plt>
test   %rax,%rax
jne    11b8 <aspectou32+0x68>
test   %ebp,%ebp
je     1188 <aspectou32+0x38>
mov    %rbx,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1188 <aspectou32+0x38>
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%edi
jmp    119e <aspectou32+0x4e>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <inet_aton@plt>
test   %rax,%rax
je     11a9 <aspectou32+0x59>
mov    0x10(%rsp),%edi
call   1070 <ntohl@plt>
mov    %eax,0xc(%rsp)
jmp    11b8 <aspectou32+0x68>
lea    0xe50(%rip),%rdi
mov    %rbx,%rsi
call   1030 <panic@plt>
mov    0xc(%rsp),%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i64* }
%struct.in_addr = type { i32 }
@.str = [21 x i8] c"unable to parse \22%s\22\00"
define i32 @aspectou32(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.hostent*
%7 = alloca %struct.in_addr
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = call i64 @strtou32(i32* %5, i8* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
br label %41
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %12
%16 = load i8*, i8** %3
%17 = call %struct.hostent* @gethostbyname(i8* %16)
store %struct.hostent* %17, %struct.hostent** %6
%18 = icmp ne %struct.hostent* %17, null
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load %struct.hostent*, %struct.hostent** %6
%21 = getelementptr inbounds %struct.hostent, %struct.hostent* %20, i32 0, i32 0
%22 = load i64*, i64** %21
%23 = getelementptr inbounds i64, i64* %22, i64 0
%24 = load i64, i64* %23
%25 = inttoptr i64 %24 to i32*
%26 = load i32, i32* %25
%27 = call i32 @ntohl(i32 %26)
store i32 %27, i32* %5
br label %40
28: ; preds = %15, %12
%29 = load i8*, i8** %3
%30 = call i64 @inet_aton(i8* %29, %struct.in_addr* %7)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @ntohl(i32 %34)
store i32 %35, i32* %5
br label %39
36: ; preds = %28
%37 = load i8*, i8** %3
%38 = call i32 @panic(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %36, %32
br label %40
40: ; preds = %39, %19
br label %41
41: ; preds = %40, %11
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i64* }
@.str = [21 x i8] c"unable to parse \22%s\22\00"
define i32 @aspectou32(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.in_addr
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.in_addr* %4 to i8*
%7 = call i64 @strtou32(i32* %3, i8* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %30
9: ; preds = %2
%10 = icmp eq i32 %1, 0
br i1 %10, label %21, label %11
11: ; preds = %9
%12 = call %struct.hostent* @gethostbyname(i8* %0)
%13 = icmp eq %struct.hostent* %12, null
br i1 %13, label %21, label %14
14: ; preds = %11
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i64 0, i32 0
%16 = load i64*, i64** %15
%17 = load i64, i64* %16
%18 = inttoptr i64 %17 to i32*
%19 = load i32, i32* %18
%20 = call i32 @ntohl(i32 %19)
store i32 %20, i32* %3
br label %30
21: ; preds = %11, %9
%22 = call i64 @inet_aton(i8* %0, %struct.in_addr* %4)
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i64 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @ntohl(i32 %26)
store i32 %27, i32* %3
br label %30
28: ; preds = %21
%29 = call i32 @panic(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %30
30: ; preds = %14, %28, %24, %2
%31 = load i32, i32* %3
ret i32 %31
}