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

/* Variables and functions */
struct hostent *gethostbyname(char *);
int gethostname(char *, int);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ memcpy(struct in_addr *, scalar_t__, int);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  char ac[80];
  struct hostent *phe = NULL;
  int i = 0;
  struct in_addr addr;
  if (gethostname(ac, sizeof(ac)) == -1) {
    return -1;
  }
  if ((phe = gethostbyname(ac)) == NULL) {
    return -1;
  }
  for (i = 0; phe->h_addr_list[i]; i++) {
    memcpy(&addr, phe->h_addr_list[i], sizeof(struct in_addr));
    printf("%s\n", inet_ntoa(addr));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x50,%esi
call   1070 <gethostname@plt>
cmp    $0xffffffff,%eax
jne    1198 <main+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <main+0xd1>
lea    -0x60(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x68(%rbp)
cmp    $0x0,%rax
jne    11bb <main+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <main+0xd1>
movl   $0x0,-0x6c(%rbp)
mov    -0x68(%rbp),%rax
mov    (%rax),%rax
movslq -0x6c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     121a <main+0xca>
mov    -0x68(%rbp),%rax
mov    (%rax),%rax
movslq -0x6c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    -0x70(%rbp),%rdi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    -0x70(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xdf9(%rip),%rdi
call   1040 <printf@plt>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    11c2 <main+0x72>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x60,%rsp
lea    0x10(%rsp),%rdi
mov    $0x50,%esi
call   1070 <gethostname@plt>
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%eax
je     11e1 <main+0x91>
lea    0x10(%rsp),%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     11e1 <main+0x91>
mov    %rax,%rbx
mov    (%rax),%rax
mov    (%rax),%rsi
xor    %r14d,%r14d
test   %rsi,%rsi
je     11e1 <main+0x91>
mov    $0x8,%ebp
lea    0x8(%rsp),%r15
lea    0xe59(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    0x8(%rsp),%edi
call   1030 <inet_ntoa@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    (%rbx),%rax
mov    (%rax,%rbp,1),%rsi
add    $0x8,%rbp
test   %rsi,%rsi
jne    11b0 <main+0x60>
mov    %r14d,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i64* }
%struct.in_addr = type { i32 }
@.str = [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 [80 x i8]
%7 = alloca %struct.hostent*
%8 = alloca i32
%9 = alloca %struct.in_addr
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.hostent* null, %struct.hostent** %7
store i32 0, i32* %8
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%11 = call i32 @gethostname(i8* %10, i32 80)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %46
14: ; preds = %2
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%16 = call %struct.hostent* @gethostbyname(i8* %15)
store %struct.hostent* %16, %struct.hostent** %7
%17 = icmp eq %struct.hostent* %16, null
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 -1, i32* %3
br label %46
19: ; preds = %14
store i32 0, i32* %8
br label %20
20: ; preds = %42, %19
%21 = load %struct.hostent*, %struct.hostent** %7
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i32 0, i32 0
%23 = load i64*, i64** %22
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i64, i64* %23, i64 %25
%27 = load i64, i64* %26
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %45
29: ; preds = %20
%30 = load %struct.hostent*, %struct.hostent** %7
%31 = getelementptr inbounds %struct.hostent, %struct.hostent* %30, i32 0, i32 0
%32 = load i64*, i64** %31
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i64, i64* %32, i64 %34
%36 = load i64, i64* %35
%37 = call i32 @memcpy(%struct.in_addr* %9, i64 %36, i32 4)
%38 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %9, i32 0, i32 0
%39 = load i32, i32* %38
%40 = call i8* @inet_ntoa(i32 %39)
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %29
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %20
45: ; preds = %20
store i32 0, i32* %3
br label %46
46: ; preds = %45, %18, %13
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i64* }
@.str = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [80 x i8]
%4 = alloca %struct.in_addr
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.in_addr* %4 to i8*
%7 = call i32 @gethostname(i8* %5, i32 80)
%8 = icmp eq i32 %7, -1
br i1 %8, label %31, label %9
9: ; preds = %2
%10 = call %struct.hostent* @gethostbyname(i8* %5)
%11 = icmp eq %struct.hostent* %10, null
br i1 %11, label %31, label %12
12: ; preds = %9
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %10, i64 0, i32 0
%14 = load i64*, i64** %13
%15 = load i64, i64* %14
%16 = icmp eq i64 %15, 0
br i1 %16, label %31, label %17
17: ; preds = %12
%18 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i64 0, i32 0
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ 0, %17 ], [ %26, %19 ]
%21 = phi i64 [ %15, %17 ], [ %29, %19 ]
%22 = call i32 @memcpy(%struct.in_addr* %4, i64 %21, i32 4)
%23 = load i32, i32* %18
%24 = call i8* @inet_ntoa(i32 %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = add nuw i64 %20, 1
%27 = load i64*, i64** %13
%28 = getelementptr inbounds i64, i64* %27, i64 %26
%29 = load i64, i64* %28
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %19
31: ; preds = %19, %12, %9, %2
%32 = phi i32 [ -1, %2 ], [ -1, %9 ], [ 0, %12 ], [ 0, %19 ]
ret i32 %32
}