#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 {
  int /*<<< orphan*/ **h_addr_list;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
struct hostent *gethostbyname(char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  unsigned int i = 0;
  struct hostent *he;
  struct in_addr *in;
  char *ip = NULL;
  if (argc != 2) {
    fputs("Usage: resolver <domain>\n", stderr);
    return 1;
  }
  he = gethostbyname(*++argv);
  if (!he) {
    fprintf(stderr, "Cannot resolve \"%s\"\n", *argv);
    return 1;
  }
  while (he->h_addr_list[i] != NULL) {
    in = (struct in_addr *)he->h_addr_list[i];
    ip = inet_ntoa(*in);
    printf("%s\n", ip);
    i++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a0 <main+0x50>
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    124f <main+0xff>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ef <main+0x9f>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe3c(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    124f <main+0xff>
jmp    11f4 <main+0xa4>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x14(%rbp),%ecx
cmpq   $0x0,(%rax,%rcx,8)
je     1248 <main+0xf8>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xdfa(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f4 <main+0xa4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11b5 <main+0x65>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     11cc <main+0x7c>
mov    %rax,%rbx
mov    (%rax),%rax
mov    (%rax),%rax
xor    %r14d,%r14d
test   %rax,%rax
je     11eb <main+0x9b>
mov    $0x1,%ebp
lea    0xea5(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    (%rbx),%rax
mov    %ebp,%ecx
mov    (%rax,%rcx,8),%rax
add    $0x1,%ebp
test   %rax,%rax
jne    1190 <main+0x40>
jmp    11eb <main+0x9b>
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
lea    0xe3b(%rip),%rdi
call   1050 <fputs@plt>
jmp    11e5 <main+0x95>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xe3a(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i32** }
%struct.in_addr = type { i32 }
@.str = [26 x i8] c"Usage: resolver <domain>\0A\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Cannot resolve \22%s\22\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.hostent*
%8 = alloca %struct.in_addr*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i8* null, i8** %9
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fputs(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 1, i32* %3
br label %55
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i32 1
store i8** %17, i8*** %5
%18 = load i8*, i8** %17
%19 = call %struct.hostent* @gethostbyname(i8* %18)
store %struct.hostent* %19, %struct.hostent** %7
%20 = load %struct.hostent*, %struct.hostent** %7
%21 = icmp ne %struct.hostent* %20, null
br i1 %21, label %27, label %22
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %5
%25 = load i8*, i8** %24
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %25)
store i32 1, i32* %3
br label %55
27: ; preds = %15
br label %28
28: ; preds = %37, %27
%29 = load %struct.hostent*, %struct.hostent** %7
%30 = getelementptr inbounds %struct.hostent, %struct.hostent* %29, i32 0, i32 0
%31 = load i32**, i32*** %30
%32 = load i32, i32* %6
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i32*, i32** %31, i64 %33
%35 = load i32*, i32** %34
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %54
37: ; preds = %28
%38 = load %struct.hostent*, %struct.hostent** %7
%39 = getelementptr inbounds %struct.hostent, %struct.hostent* %38, i32 0, i32 0
%40 = load i32**, i32*** %39
%41 = load i32, i32* %6
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i32*, i32** %40, i64 %42
%44 = load i32*, i32** %43
%45 = bitcast i32* %44 to %struct.in_addr*
store %struct.in_addr* %45, %struct.in_addr** %8
%46 = load %struct.in_addr*, %struct.in_addr** %8
%47 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = call i8* @inet_ntoa(i32 %48)
store i8* %49, i8** %9
%50 = load i8*, i8** %9
%51 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %50)
%52 = load i32, i32* %6
%53 = add i32 %52, 1
store i32 %53, i32* %6
br label %28
54: ; preds = %28
store i32 0, i32* %3
br label %55
55: ; preds = %54, %22, %12
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
%struct.hostent = type { i32** }
@.str = [26 x i8] c"Usage: resolver <domain>\0A\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Cannot resolve \22%s\22\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fputs(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %33
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call %struct.hostent* @gethostbyname(i8* %9)
%11 = icmp eq %struct.hostent* %10, null
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %10, i64 0, i32 0
%14 = load i32**, i32*** %13
%15 = load i32*, i32** %14
%16 = icmp eq i32* %15, null
br i1 %16, label %33, label %21
17: ; preds = %7
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %8
%20 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %33
21: ; preds = %12, %21
%22 = phi i32* [ %31, %21 ], [ %15, %12 ]
%23 = phi i32 [ %27, %21 ], [ 0, %12 ]
%24 = load i32, i32* %22
%25 = tail call i8* @inet_ntoa(i32 %24)
%26 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = add i32 %23, 1
%28 = load i32**, i32*** %13
%29 = zext i32 %27 to i64
%30 = getelementptr inbounds i32*, i32** %28, i64 %29
%31 = load i32*, i32** %30
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %21
33: ; preds = %21, %12, %17, %4
%34 = phi i32 [ 1, %4 ], [ 1, %17 ], [ 0, %12 ], [ 0, %21 ]
ret i32 %34
}