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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int INET_ADDRSTRLEN;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                             int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <domain-name>\n", argv[0]);
    exit(1);
  }
  struct hostent *he;
  he = gethostbyname(argv[1]);
  if (!he) {
    fputs("Error, could not resolve.\n", stderr);
    exit(1);
  }
  char str[INET_ADDRSTRLEN];
  inet_ntop(AF_INET, he->h_addr, str, INET_ADDRSTRLEN);
  printf("%s\n", str);
  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)
cmpl   $0x2,-0x8(%rbp)
je     11a6 <main+0x46>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e1 <main+0x81>
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
lea    0xe47(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x30(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x28(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    0x2dad(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
mov    -0x30(%rbp),%rsi
lea    0xdff(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11c1 <main+0x61>
mov    0x8(%rsi),%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     11e3 <main+0x83>
mov    0x2e50(%rip),%rcx
mov    (%rcx),%ecx
mov    %rsp,%rbx
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
sub    %rdx,%rbx
mov    %rbx,%rsp
mov    0x2e4b(%rip),%rdx
mov    (%rdx),%edi
mov    (%rax),%esi
mov    %rbx,%rdx
call   1030 <inet_ntop@plt>
lea    0xe84(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe2c(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
lea    0xe26(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"Usage: %s <domain-name>\0A\00"
@.str.1 = [27 x i8] c"Error, could not resolve.\0A\00"
@INET_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@.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 %struct.hostent*
%7 = alloca i8*
%8 = alloca i64
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 %18
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 ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call %struct.hostent* @gethostbyname(i8* %21)
store %struct.hostent* %22, %struct.hostent** %6
%23 = load %struct.hostent*, %struct.hostent** %6
%24 = icmp ne %struct.hostent* %23, null
br i1 %24, label %29, label %25
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %18
%30 = load i32, i32* @INET_ADDRSTRLEN
%31 = zext i32 %30 to i64
%32 = call i8* @llvm.stacksave()
store i8* %32, i8** %7
%33 = alloca i8, i64 %31
store i64 %31, i64* %8
%34 = load i32, i32* @AF_INET
%35 = load %struct.hostent*, %struct.hostent** %6
%36 = getelementptr inbounds %struct.hostent, %struct.hostent* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = load i32, i32* @INET_ADDRSTRLEN
%39 = call i32 @inet_ntop(i32 %34, i32 %37, i8* %33, i32 %38)
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %33)
store i32 0, i32* %3
%41 = load i8*, i8** %7
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"Usage: %s <domain-name>\0A\00"
@.str.1 = [27 x i8] c"Error, could not resolve.\0A\00"
@INET_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@.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 %9, 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 ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call %struct.hostent* @gethostbyname(i8* %11)
%13 = icmp eq %struct.hostent* %12, null
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = tail call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %9
%19 = load i32, i32* @INET_ADDRSTRLEN
%20 = zext i32 %19 to i64
%21 = alloca i8, i64 %20
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i64 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @inet_ntop(i32 %22, i32 %24, i8* %21, i32 %19)
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %21)
ret i32 0
}