#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 /*<<< orphan*/ s_addr;
};
struct hostent {
  char *h_name;
  scalar_t__ h_addr_list;
};

/* Variables and functions */
struct hostent *gethostbyname(char *);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void local_gethostbyname(char *hostname) {
  struct hostent *h;
  struct in_addr **i;
  int not_first_time;
  if (!(h = gethostbyname(hostname))) {
    printf("%s: unknown\n", hostname);
  } else {
    printf("%s: ", h->h_name);
    not_first_time = 0;
    i = (struct in_addr **)h->h_addr_list;
    while (*i) {
      if (not_first_time)
        printf(",");
      printf("%s", inet_ntoa((*i)->s_addr));
      i++;
      not_first_time = 1;
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<local_gethostbyname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    116a <local_gethostbyname+0x3a>
mov    -0x8(%rbp),%rsi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11fd <local_gethostbyname+0xcd>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     11ef <local_gethostbyname+0xbf>
cmpl   $0x0,-0x1c(%rbp)
je     11b8 <local_gethostbyname+0x88>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
jmp    1192 <local_gethostbyname+0x62>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<local_gethostbyname>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     11dd <local_gethostbyname+0x9d>
mov    %rax,%rbx
mov    (%rax),%rsi
lea    0xeab(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%rbx
mov    (%rbx),%rax
test   %rax,%rax
je     11cc <local_gethostbyname+0x8c>
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
lea    0xe8f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmpq   $0x0,0x8(%rbx)
je     11cc <local_gethostbyname+0x8c>
add    $0x10,%rbx
lea    0xe73(%rip),%r14
nop
mov    $0x2c,%edi
call   1030 <putchar@plt>
mov    -0x8(%rbx),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmpq   $0x0,(%rbx)
lea    0x8(%rbx),%rbx
jne    11a0 <local_gethostbyname+0x60>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putchar@plt>
lea    0xe1c(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <printf@plt>

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

LLVM IR (-O2):
%struct.hostent = type { i8*, i64 }
%struct.in_addr = type { i32 }
@.str = [13 x i8] c"%s: unknown\0A\00"
@.str.1 = [5 x i8] c"%s: \00"
@.str.3 = [3 x i8] c"%s\00"
define void @local_gethostbyname(i8* %0) {
%2 = tail call %struct.hostent* @gethostbyname(i8* %0)
%3 = icmp eq %struct.hostent* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %36
6: ; preds = %1
%7 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 0
%8 = load i8*, i8** %7
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 1
%11 = load i64, i64* %10
%12 = inttoptr i64 %11 to %struct.in_addr**
%13 = load %struct.in_addr*, %struct.in_addr** %12
%14 = icmp eq %struct.in_addr* %13, null
br i1 %14, label %34, label %15
15: ; preds = %6
%16 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %13, i64 0, i32 0
%17 = load i32, i32* %16
%18 = tail call i8* @inet_ntoa(i32 %17)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %12, i64 1
%21 = load %struct.in_addr*, %struct.in_addr** %20
%22 = icmp eq %struct.in_addr* %21, null
br i1 %22, label %34, label %23
23: ; preds = %15, %23
%24 = phi %struct.in_addr** [ %31, %23 ], [ %20, %15 ]
%25 = tail call i32 @putchar(i32 44)
%26 = load %struct.in_addr*, %struct.in_addr** %24
%27 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %26, i64 0, i32 0
%28 = load i32, i32* %27
%29 = tail call i8* @inet_ntoa(i32 %28)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %24, i64 1
%32 = load %struct.in_addr*, %struct.in_addr** %31
%33 = icmp eq %struct.in_addr* %32, null
br i1 %33, label %34, label %23
34: ; preds = %23, %15, %6
%35 = tail call i32 @putchar(i32 10)
br label %36
36: ; preds = %34, %4
ret void
}