#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 {
  char **h_addr_list;
  char *h_name;
};

/* Variables and functions */
int /*<<< orphan*/ ares_free_errmem(char *);
char *ares_strerror(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ memcpy(struct in_addr *, char *, int);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ stderr;
void callback(void *arg, int status, struct hostent *host) {
  struct in_addr addr;
  char *mem, **p;
  if (status != 0) {
    fprintf(stderr, "%s: %s\n", (char *)arg, ares_strerror(status));
    ares_free_errmem(mem);
    return;
  }
  for (p = host->h_addr_list; *p; p++) {
    memcpy(&addr, *p, sizeof(struct in_addr));
    printf("%-32s\t%s\n", host->h_name, inet_ntoa(addr));
  }
}


x86 assembly (clang, -O0):
<callback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11bd <callback+0x5d>
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <ares_strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xe56(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1080 <ares_free_errmem@plt>
jmp    1223 <callback+0xc3>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
je     1223 <callback+0xc3>
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
lea    -0x20(%rbp),%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    -0x48(%rbp),%rsi
mov    %rax,%rdx
lea    0xdfb(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
jmp    11c8 <callback+0x68>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<callback>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
je     11aa <callback+0x4a>
mov    %rdi,%r14
mov    0x2e65(%rip),%rax
mov    (%rax),%ebx
mov    %esi,%edi
call   1040 <ares_strerror@plt>
lea    0xe75(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1060 <fprintf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1080 <ares_free_errmem@plt>
mov    %rdx,%r12
mov    (%rdx),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1205 <callback+0xa5>
add    $0x8,%rbx
lea    0x8(%rsp),%r14
lea    0xe40(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
mov    0x8(%r12),%r13
mov    0x8(%rsp),%edi
call   1030 <inet_ntoa@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rax,%rdx
call   1050 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    11d0 <callback+0x70>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.hostent = type { i8**, i8* }
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [8 x i8] c"%s: %s\0A\00"
@.str.1 = [10 x i8] c"%-32s\09%s\0A\00"
define void @callback(i8* %0, i32 %1, %struct.hostent* nocapture %2) {
%4 = alloca %struct.in_addr
%5 = bitcast %struct.in_addr* %4 to i8*
%6 = icmp eq i32 %1, 0
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i8* @ares_strerror(i32 %1)
%10 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %9)
%11 = tail call i32 @ares_free_errmem(i8* undef)
br label %31
12: ; preds = %3
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 0
%14 = load i8**, i8*** %13
%15 = load i8*, i8** %14
%16 = icmp eq i8* %15, null
br i1 %16, label %31, label %17
17: ; preds = %12
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 1
%19 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i64 0, i32 0
br label %20
20: ; preds = %17, %20
%21 = phi i8* [ %15, %17 ], [ %29, %20 ]
%22 = phi i8** [ %14, %17 ], [ %28, %20 ]
%23 = call i32 @memcpy(%struct.in_addr* %4, i8* %21, i32 4)
%24 = load i8*, i8** %18
%25 = load i32, i32* %19
%26 = call i8* @inet_ntoa(i32 %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* %26)
%28 = getelementptr inbounds i8*, i8** %22, i64 1
%29 = load i8*, i8** %28
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %20
31: ; preds = %20, %12, %7
ret void
}