#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, char **);
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, &mem));
    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     11c1 <callback+0x61>
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1040 <ares_strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xe52(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1080 <ares_free_errmem@plt>
jmp    1227 <callback+0xc7>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
je     1227 <callback+0xc7>
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    0xdf7(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
jmp    11cc <callback+0x6c>
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     11ac <callback+0x4c>
mov    %rdi,%r14
mov    0x2e65(%rip),%rax
mov    (%rax),%ebx
lea    0x8(%rsp),%rax
mov    %esi,%edi
mov    %rax,%rsi
call   1040 <ares_strerror@plt>
lea    0xe6d(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1060 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1080 <ares_free_errmem@plt>
jmp    1204 <callback+0xa4>
mov    %rdx,%r12
mov    (%rdx),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1204 <callback+0xa4>
add    $0x8,%rbx
mov    %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    (%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, i8** %8)
%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 = alloca i8*
%6 = bitcast %struct.in_addr* %4 to i8*
%7 = bitcast i8** %5 to i8*
%8 = icmp eq i32 %1, 0
br i1 %8, label %15, label %9
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = call i8* @ares_strerror(i32 %1, i8** %5)
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %11)
%13 = load i8*, i8** %5
%14 = call i32 @ares_free_errmem(i8* %13)
br label %34
15: ; preds = %3
%16 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 0
%17 = load i8**, i8*** %16
%18 = load i8*, i8** %17
%19 = icmp eq i8* %18, null
br i1 %19, label %34, label %20
20: ; preds = %15
%21 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 1
%22 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i64 0, i32 0
br label %23
23: ; preds = %20, %23
%24 = phi i8* [ %18, %20 ], [ %32, %23 ]
%25 = phi i8** [ %17, %20 ], [ %31, %23 ]
%26 = call i32 @memcpy(%struct.in_addr* %4, i8* %24, i32 4)
%27 = load i8*, i8** %21
%28 = load i32, i32* %22
%29 = call i8* @inet_ntoa(i32 %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %29)
%31 = getelementptr inbounds i8*, i8** %25, i64 1
%32 = load i8*, i8** %31
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %23
34: ; preds = %23, %15, %9
ret void
}