#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_name;
  int h_addrtype;
  char **h_addr_list;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  struct hostent *result;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s hostname\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  result = gethostbyname(argv[1]);
  if (result == NULL) {
    perror("gethostbyname");
    exit(EXIT_FAILURE);
  }
  printf("Name: %s; type: %d\n", result->h_name, result->h_addrtype);
  int i = 0;
  char **p = result->h_addr_list;
  while (p && p[i]) {
    printf("  %s\n", inet_ntoa(*(struct in_addr *)p[i]));
    i++;
  }
  exit(EXIT_SUCCESS);
}


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)
cmpl   $0x2,-0x8(%rbp)
je     11aa <main+0x4a>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e0 <main+0x80>
lea    0xe47(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edx
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x29(%rbp)
je     1232 <main+0xd2>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1242 <main+0xe2>
jmp    1274 <main+0x114>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    120f <main+0xaf>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1185 <main+0x25>
mov    0x8(%rsi),%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
jne    11ab <main+0x4b>
lea    0xe96(%rip),%rdi
call   1070 <perror@plt>
jmp    119d <main+0x3d>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe68(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    %rax,%rbx
mov    (%rax),%rsi
mov    0x8(%rax),%edx
lea    0xe67(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%rbx
test   %rbx,%rbx
je     1200 <main+0xa0>
mov    (%rbx),%rax
test   %rax,%rax
je     1200 <main+0xa0>
add    $0x8,%rbx
lea    0xe58(%rip),%r14
xchg   %ax,%ax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rax
add    $0x8,%rbx
test   %rax,%rax
jne    11e0 <main+0x80>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i8*, i32, i8** }
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s hostname\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"gethostbyname\00"
@.str.2 = [20 x i8] c"Name: %s; type: %d\0A\00"
@.str.3 = [6 x i8] c" %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.hostent*
%7 = alloca i32
%8 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call %struct.hostent* @gethostbyname(i8* %22)
store %struct.hostent* %23, %struct.hostent** %6
%24 = load %struct.hostent*, %struct.hostent** %6
%25 = icmp eq %struct.hostent* %24, null
br i1 %25, label %26, label %30
26: ; preds = %19
%27 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %19
%31 = load %struct.hostent*, %struct.hostent** %6
%32 = getelementptr inbounds %struct.hostent, %struct.hostent* %31, i32 0, i32 0
%33 = load i8*, i8** %32
%34 = load %struct.hostent*, %struct.hostent** %6
%35 = getelementptr inbounds %struct.hostent, %struct.hostent* %34, i32 0, i32 1
%36 = load i32, i32* %35
%37 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %33, i32 %36)
store i32 0, i32* %7
%38 = load %struct.hostent*, %struct.hostent** %6
%39 = getelementptr inbounds %struct.hostent, %struct.hostent* %38, i32 0, i32 2
%40 = load i8**, i8*** %39
store i8** %40, i8*** %8
br label %41
41: ; preds = %53, %30
%42 = load i8**, i8*** %8
%43 = icmp ne i8** %42, null
br i1 %43, label %44, label %51
44: ; preds = %41
%45 = load i8**, i8*** %8
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = icmp ne i8* %49, null
br label %51
51: ; preds = %44, %41
%52 = phi i1 [ false, %41 ], [ %50, %44 ]
br i1 %52, label %53, label %66
53: ; preds = %51
%54 = load i8**, i8*** %8
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %54, i64 %56
%58 = load i8*, i8** %57
%59 = bitcast i8* %58 to %struct.in_addr*
%60 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %59, i32 0, i32 0
%61 = load i32, i32* %60
%62 = call i8* @inet_ntoa(i32 %61)
%63 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %62)
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
br label %41
66: ; preds = %51
%67 = load i32, i32* @EXIT_SUCCESS
%68 = call i32 @exit(i32 %67)
unreachable
}

LLVM IR (-O2):
%struct.hostent = type { i8*, i32, i8** }
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s hostname\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"gethostbyname\00"
@.str.2 = [20 x i8] c"Name: %s; type: %d\0A\00"
@.str.3 = [6 x i8] c" %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call %struct.hostent* @gethostbyname(i8* %12)
%14 = icmp eq %struct.hostent* %13, null
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %10
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 0
%21 = load i8*, i8** %20
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 1
%23 = load i32, i32* %22
%24 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %21, i32 %23)
%25 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 2
%26 = load i8**, i8*** %25
%27 = icmp eq i8** %26, null
br i1 %27, label %42, label %28
28: ; preds = %19
%29 = load i8*, i8** %26
%30 = icmp eq i8* %29, null
br i1 %30, label %42, label %31
31: ; preds = %28, %31
%32 = phi i8* [ %40, %31 ], [ %29, %28 ]
%33 = phi i64 [ %38, %31 ], [ 0, %28 ]
%34 = bitcast i8* %32 to i32*
%35 = load i32, i32* %34
%36 = tail call i8* @inet_ntoa(i32 %35)
%37 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = add nuw i64 %33, 1
%39 = getelementptr inbounds i8*, i8** %26, i64 %38
%40 = load i8*, i8** %39
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %31
42: ; preds = %31, %28, %19
%43 = load i32, i32* @EXIT_SUCCESS
%44 = tail call i32 @exit(i32 %43)
unreachable
}