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

/* Variables and functions */
struct hostent *gethostbyname(char const *);
int /*<<< orphan*/ herror(char *);
uint32_t tm_hostname_lookup(const uint8_t *hostname) {
  struct hostent *h;
  if ((h = gethostbyname((const char *)hostname)) == NULL) {
    herror("gethostbyname(): ");
    return 0;
  }
  return ((struct in_addr *)h->h_addr)->s_addr;
}


x86 assembly (clang, -O0):
<tm_hostname_lookup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    115b <tm_hostname_lookup+0x3b>
lea    0xeb6(%rip),%rdi
call   1040 <herror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1167 <tm_hostname_lookup+0x47>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tm_hostname_lookup>:
push   %rax
call   1030 <gethostbyname@plt>
test   %rax,%rax
je     1132 <tm_hostname_lookup+0x12>
mov    (%rax),%rax
mov    (%rax),%eax
pop    %rcx
ret
lea    0xec7(%rip),%rdi
call   1040 <herror@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.hostent = type { i64 }
%struct.in_addr = type { i32 }
@.str = [18 x i8] c"gethostbyname(): \00"
define i32 @tm_hostname_lookup(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca %struct.hostent*
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = bitcast i32* %5 to i8*
%7 = call %struct.hostent* @gethostbyname(i8* %6)
store %struct.hostent* %7, %struct.hostent** %4
%8 = icmp eq %struct.hostent* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @herror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %18
11: ; preds = %1
%12 = load %struct.hostent*, %struct.hostent** %4
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i32 0, i32 0
%14 = load i64, i64* %13
%15 = inttoptr i64 %14 to %struct.in_addr*
%16 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %15, i32 0, i32 0
%17 = load i32, i32* %16
store i32 %17, i32* %2
br label %18
18: ; preds = %11, %9
%19 = load i32, i32* %2
ret i32 %19
}

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