#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;
  char **h_aliases;
  scalar_t__ h_addr;
};

/* Variables and functions */
struct hostent *gethostbyname(char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, char *, ...);
int main() {
  struct hostent *foo;
  foo = gethostbyname("zeit.fu-berlin.de");
  if (foo) {
    int i;
    printf("%s -> %s\n", foo->h_name,
           inet_ntoa(*(struct in_addr *)foo->h_addr));
    for (i = 0; foo->h_aliases[i]; ++i) {
      printf("  also known as %s\n", foo->h_aliases[i]);
    }
  } else
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d8 <main+0xa8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11d3 <main+0xa3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1190 <main+0x60>
jmp    11e4 <main+0xb4>
movl   $0x1,-0x4(%rbp)
jmp    11eb <main+0xbb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xec2(%rip),%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     11ad <main+0x7d>
mov    %rax,%r15
mov    (%rax),%r14
mov    0x10(%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
lea    0xeb2(%rip),%rdi
xor    %ebp,%ebp
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%r15),%rax
mov    (%rax),%rsi
test   %rsi,%rsi
je     11b2 <main+0x82>
mov    $0x8,%ebx
lea    0xe95(%rip),%r14
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%r15),%rax
mov    (%rax,%rbx,1),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1190 <main+0x60>
jmp    11b2 <main+0x82>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i8*, i8**, i64 }
%struct.in_addr = type { i32 }
@.str = [18 x i8] c"zeit.fu-berlin.de\00"
@.str.1 = [10 x i8] c"%s -> %s\0A\00"
@.str.2 = [20 x i8] c" also known as %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.hostent*
%3 = alloca i32
store i32 0, i32* %1
%4 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store %struct.hostent* %4, %struct.hostent** %2
%5 = load %struct.hostent*, %struct.hostent** %2
%6 = icmp ne %struct.hostent* %5, null
br i1 %6, label %7, label %41
7: ; preds = %0
%8 = load %struct.hostent*, %struct.hostent** %2
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i32 0, i32 0
%10 = load i8*, i8** %9
%11 = load %struct.hostent*, %struct.hostent** %2
%12 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i32 0, i32 2
%13 = load i64, i64* %12
%14 = inttoptr i64 %13 to %struct.in_addr*
%15 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i8* @inet_ntoa(i32 %16)
%18 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %10, i8* %17)
store i32 0, i32* %3
br label %19
19: ; preds = %37, %7
%20 = load %struct.hostent*, %struct.hostent** %2
%21 = getelementptr inbounds %struct.hostent, %struct.hostent* %20, i32 0, i32 1
%22 = load i8**, i8*** %21
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %40
28: ; preds = %19
%29 = load %struct.hostent*, %struct.hostent** %2
%30 = getelementptr inbounds %struct.hostent, %struct.hostent* %29, i32 0, i32 1
%31 = load i8**, i8*** %30
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %35)
br label %37
37: ; preds = %28
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %19
40: ; preds = %19
br label %42
41: ; preds = %0
store i32 1, i32* %1
br label %43
42: ; preds = %40
store i32 0, i32* %1
br label %43
43: ; preds = %42, %41
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
%struct.hostent = type { i8*, i8**, i64 }
%struct.in_addr = type { i32 }
@.str = [18 x i8] c"zeit.fu-berlin.de\00"
@.str.1 = [10 x i8] c"%s -> %s\0A\00"
@.str.2 = [20 x i8] c" also known as %s\0A\00"
define i32 @main() {
%1 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq %struct.hostent* %1, null
br i1 %2, label %26, label %3
3: ; preds = %0
%4 = getelementptr inbounds %struct.hostent, %struct.hostent* %1, i64 0, i32 0
%5 = load i8*, i8** %4
%6 = getelementptr inbounds %struct.hostent, %struct.hostent* %1, i64 0, i32 2
%7 = load i64, i64* %6
%8 = inttoptr i64 %7 to %struct.in_addr*
%9 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %8, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i8* @inet_ntoa(i32 %10)
%12 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %11)
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %1, i64 0, i32 1
%14 = load i8**, i8*** %13
%15 = load i8*, i8** %14
%16 = icmp eq i8* %15, null
br i1 %16, label %26, label %17
17: ; preds = %3, %17
%18 = phi i64 [ %21, %17 ], [ 0, %3 ]
%19 = phi i8* [ %24, %17 ], [ %15, %3 ]
%20 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = add nuw i64 %18, 1
%22 = load i8**, i8*** %13
%23 = getelementptr inbounds i8*, i8** %22, i64 %21
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %17
26: ; preds = %17, %3, %0
%27 = phi i32 [ 1, %0 ], [ 0, %3 ], [ 0, %17 ]
ret i32 %27
}