#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;
};

/* Variables and functions */
scalar_t__ NETDB_INTERNAL;
scalar_t__ dns_getaddr(void *, struct in_addr *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ h_errno;
int /*<<< orphan*/ herror(char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ stderr;
void *do_resolve(void *host) {
  struct in_addr addr;
  printf("resolving %-40s\n", (char *)host);
  if (dns_getaddr(host, &addr, (2 * 1000000LL)) < 0) {
    fprintf(stderr, "dns_getaddr: can't resolve %s: ", (char *)host);
    if (h_errno == NETDB_INTERNAL)
      perror("");
    else
      herror("");
  } else
    printf("%-40s %s\n", (char *)host, inet_ntoa(addr));
  return NULL;
}


x86 assembly (clang, -O0):
<do_resolve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x1e8480,%edx
call   1060 <dns_getaddr@plt>
cmp    $0x0,%rax
jge    11ef <do_resolve+0x8f>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe63(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%rax
mov    0x2e1c(%rip),%rcx
cmp    (%rcx),%rax
jne    11de <do_resolve+0x7e>
lea    0xe66(%rip),%rdi
call   1080 <perror@plt>
jmp    11ea <do_resolve+0x8a>
lea    0xe55(%rip),%rdi
call   1070 <herror@plt>
jmp    1214 <do_resolve+0xb4>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    -0x18(%rbp),%rsi
mov    %rax,%rdx
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_resolve>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xe91(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x1e8480,%edx
call   1060 <dns_getaddr@plt>
test   %rax,%rax
js     11af <do_resolve+0x4f>
mov    0x8(%rsp),%edi
call   1030 <inet_ntoa@plt>
lea    0xe91(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e9 <do_resolve+0x89>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%rax
mov    0x2e08(%rip),%rcx
cmp    (%rcx),%rax
je     11f1 <do_resolve+0x91>
lea    0xe56(%rip),%rdi
call   1070 <herror@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe42(%rip),%rdi
call   1080 <perror@plt>
jmp    11e9 <do_resolve+0x89>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [17 x i8] c"resolving %-40s\0A\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"dns_getaddr: can't resolve %s: \00"
@h_errno = global i64 0
@NETDB_INTERNAL = global i64 0
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [10 x i8] c"%-40s %s\0A\00"
define i8* @do_resolve(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.in_addr
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = load i8*, i8** %2
%7 = call i64 @dns_getaddr(i8* %6, %struct.in_addr* %3, i32 2000000)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %2
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i64, i64* @h_errno
%14 = load i64, i64* @NETDB_INTERNAL
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %20
18: ; preds = %9
%19 = call i32 @herror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %16
br label %27
21: ; preds = %1
%22 = load i8*, i8** %2
%23 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i8* @inet_ntoa(i32 %24)
%26 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %22, i8* %25)
br label %27
27: ; preds = %21, %20
ret i8* null
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@.str = [17 x i8] c"resolving %-40s\0A\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"dns_getaddr: can't resolve %s: \00"
@h_errno = global i64 0
@NETDB_INTERNAL = global i64 0
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [10 x i8] c"%-40s %s\0A\00"
define noalias i8* @do_resolve(i8* %0) {
%2 = alloca %struct.in_addr
%3 = bitcast %struct.in_addr* %2 to i8*
%4 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i64 @dns_getaddr(i8* %0, %struct.in_addr* %2, i32 2000000)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%10 = load i64, i64* @h_errno
%11 = load i64, i64* @NETDB_INTERNAL
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %22
15: ; preds = %7
%16 = call i32 @herror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %22
17: ; preds = %1
%18 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i8* @inet_ntoa(i32 %19)
%21 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %20)
br label %22
22: ; preds = %13, %15, %17
ret i8* null
}