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

/* Variables and functions */
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ gethostname(char *, int);
int /*<<< orphan*/ inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int getLocalIp(char *ip) {
  char hname[128];
  struct hostent *hent;
  int i;
  gethostname(hname, sizeof(hname));
  hent = gethostbyname(hname);
  printf("hostname: %s\naddress list: ", hent->h_name);
  for (i = 0; hent->h_addr_list[i]; i++) {
    strcpy(ip, inet_ntoa(*(struct in_addr *)(hent->h_addr_list[i])));
    return 1;
  }
}


x86 assembly (clang, -O0):
<getLocalIp>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
mov    $0x80,%esi
call   1070 <gethostname@plt>
lea    -0x90(%rbp),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rax
mov    (%rax),%rsi
lea    0xe6c(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x9c(%rbp)
mov    -0x98(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x9c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11fd <getLocalIp+0xad>
mov    -0x10(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x98(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x9c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    -0xa8(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLocalIp>:
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1070 <gethostname@plt>
mov    %rbx,%rdi
call   1060 <gethostbyname@plt>
mov    %rax,%rbx
mov    (%rax),%rsi
lea    0xe7e(%rip),%rdi
call   1050 <printf@plt>
mov    0x8(%rbx),%rax
mov    (%rax),%rax
test   %rax,%rax
je     11a4 <getLocalIp+0x54>
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    $0x1,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.hostent = type { i8*, i64* }
%struct.in_addr = type { i32 }
@.str = [28 x i8] c"hostname: %s\0Aaddress list: \00"
define i32 @getLocalIp(i8* %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = call i32 @gethostname(i8* %3, i32 128)
%5 = call %struct.hostent* @gethostbyname(i8* %3)
%6 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 0
%7 = load i8*, i8** %6
%8 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 1
%10 = load i64*, i64** %9
%11 = load i64, i64* %10
%12 = icmp eq i64 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %1
%14 = inttoptr i64 %11 to %struct.in_addr*
%15 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %14, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @inet_ntoa(i32 %16)
%18 = call i32 @strcpy(i8* %0, i32 %17)
br label %19
19: ; preds = %1, %13
ret i32 1
}