#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 */
typedef int /*<<< orphan*/ uint32_t;
struct hostent {
  scalar_t__ h_addrtype;
  unsigned char **h_addr_list;
};

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ ntohl(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned char, unsigned char, unsigned char,
                          unsigned char);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  struct hostent *host;
  uint32_t ip;
  unsigned char *ptr, *addr;
  int i = 0;
  if (argc < 2) {
    fprintf(stderr, "too few arguments\n");
    exit(1);
  }
  host = gethostbyname(argv[1]);
  if (host == NULL) {
    fprintf(stderr, "gethostbyname() failure\n");
    exit(1);
  } else if (host->h_addrtype != AF_INET) {
    fprintf(stderr, "h_addrtype is not AF_INET\n");
    exit(1);
  }
  while ((ptr = host->h_addr_list[i++]) != NULL) {
    ip = ntohl(*((uint32_t *)ptr));
    addr = (char *)&ip;
    printf("%d. %d. %d. %d\n", addr[3], addr[2], addr[1], addr[0]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1196 <main+0x46>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d1 <main+0x81>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e09(%rip),%rcx
cmp    (%rcx),%rax
je     1207 <main+0xb7>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    120c <main+0xbc>
jmp    1211 <main+0xc1>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x34(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1288 <main+0x138>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1070 <ntohl@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x1c(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x3(%rax),%sil
mov    -0x30(%rbp),%rax
mov    0x2(%rax),%dl
mov    -0x30(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x30(%rbp),%rax
lea    0xdd7(%rip),%rdi
movzbl %sil,%esi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl (%rax),%r8d
call   1030 <printf@plt>
jmp    1211 <main+0xc1>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x1,%edi
jle    11e1 <main+0x91>
mov    0x8(%rsi),%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     11f3 <main+0xa3>
mov    %rax,%r15
mov    (%rax),%rax
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%rax
jne    1205 <main+0xb5>
mov    0x8(%r15),%rax
mov    (%rax),%rax
test   %rax,%rax
je     11d9 <main+0x89>
mov    $0x8,%ebx
lea    0xea9(%rip),%r14
xchg   %ax,%ax
mov    (%rax),%edi
call   1070 <ntohl@plt>
mov    %eax,%esi
shr    $0x10,%esi
mov    %eax,%edx
shr    $0x18,%edx
movzbl %ah,%ecx
movzbl %al,%r8d
movzbl %sil,%eax
mov    %r14,%rdi
mov    %edx,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    0x8(%r15),%rax
mov    (%rax,%rbx,1),%rax
add    $0x8,%rbx
test   %rax,%rax
jne    11a0 <main+0x50>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
jmp    1215 <main+0xc5>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
jmp    1215 <main+0xc5>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i64, i8** }
@stderr = global i32 0
@.str = [19 x i8] c"too few arguments\0A\00"
@.str.1 = [25 x i8] c"gethostbyname() failure\0A\00"
@AF_INET = global i64 0
@.str.2 = [27 x i8] c"h_addrtype is not AF_INET\0A\00"
@.str.3 = [16 x i8] c"%d. %d. %d. %d\0A\00"
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*
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call %struct.hostent* @gethostbyname(i8* %20)
store %struct.hostent* %21, %struct.hostent** %6
%22 = load %struct.hostent*, %struct.hostent** %6
%23 = icmp eq %struct.hostent* %22, null
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %17
%29 = load %struct.hostent*, %struct.hostent** %6
%30 = getelementptr inbounds %struct.hostent, %struct.hostent* %29, i32 0, i32 0
%31 = load i64, i64* %30
%32 = load i64, i64* @AF_INET
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %28
br label %39
39: ; preds = %38
br label %40
40: ; preds = %50, %39
%41 = load %struct.hostent*, %struct.hostent** %6
%42 = getelementptr inbounds %struct.hostent, %struct.hostent* %41, i32 0, i32 1
%43 = load i8**, i8*** %42
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
%46 = sext i32 %44 to i64
%47 = getelementptr inbounds i8*, i8** %43, i64 %46
%48 = load i8*, i8** %47
store i8* %48, i8** %8
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %69
50: ; preds = %40
%51 = load i8*, i8** %8
%52 = bitcast i8* %51 to i32*
%53 = load i32, i32* %52
%54 = call i32 @ntohl(i32 %53)
store i32 %54, i32* %7
%55 = bitcast i32* %7 to i8*
store i8* %55, i8** %9
%56 = load i8*, i8** %9
%57 = getelementptr inbounds i8, i8* %56, i64 3
%58 = load i8, i8* %57
%59 = load i8*, i8** %9
%60 = getelementptr inbounds i8, i8* %59, i64 2
%61 = load i8, i8* %60
%62 = load i8*, i8** %9
%63 = getelementptr inbounds i8, i8* %62, i64 1
%64 = load i8, i8* %63
%65 = load i8*, i8** %9
%66 = getelementptr inbounds i8, i8* %65, i64 0
%67 = load i8, i8* %66
%68 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %58, i8 zeroext %61, i8 zeroext %64, i8 zeroext %67)
br label %40
69: ; preds = %40
ret i32 0
}

LLVM IR (-O2):
%struct.hostent = type { i64, i8** }
@stderr = global i32 0
@.str = [19 x i8] c"too few arguments\0A\00"
@.str.1 = [25 x i8] c"gethostbyname() failure\0A\00"
@AF_INET = global i64 0
@.str.2 = [27 x i8] c"h_addrtype is not AF_INET\0A\00"
@.str.3 = [16 x i8] c"%d. %d. %d. %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call %struct.hostent* @gethostbyname(i8* %10)
%12 = icmp eq %struct.hostent* %11, null
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %8
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i64 0, i32 0
%19 = load i64, i64* %18
%20 = load i64, i64* @AF_INET
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i64 0, i32 1
%24 = load i8**, i8*** %23
%25 = load i8*, i8** %24
%26 = icmp eq i8* %25, null
br i1 %26, label %50, label %31
27: ; preds = %17
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %22, %31
%32 = phi i64 [ %34, %31 ], [ 0, %22 ]
%33 = phi i8* [ %48, %31 ], [ %25, %22 ]
%34 = add nuw i64 %32, 1
%35 = bitcast i8* %33 to i32*
%36 = load i32, i32* %35
%37 = tail call i32 @ntohl(i32 %36)
%38 = trunc i32 %37 to i8
%39 = lshr i32 %37, 8
%40 = trunc i32 %39 to i8
%41 = lshr i32 %37, 16
%42 = trunc i32 %41 to i8
%43 = lshr i32 %37, 24
%44 = trunc i32 %43 to i8
%45 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %44, i8 zeroext %42, i8 zeroext %40, i8 zeroext %38)
%46 = load i8**, i8*** %23
%47 = getelementptr inbounds i8*, i8** %46, i64 %34
%48 = load i8*, i8** %47
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %31
50: ; preds = %31, %22
ret i32 0
}