#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 sockaddr_in {
  struct in_addr sin_addr;
};
struct hostent {
  scalar_t__ h_addr;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
struct hostent *gethostbyname(char *);
scalar_t__ inet_aton(char *, struct in_addr *);
int /*<<< orphan*/ printf(char *, char *);
int getAddress(char *address, struct sockaddr_in *sockAddr) {
  if (inet_aton(address, &(sockAddr->sin_addr)) == 0) {
    struct hostent *host;
    host = gethostbyname(address);
    if (host == NULL) {
      printf("Unknown address %s!\n", address);
      return EXIT_FAILURE;
    }
    sockAddr->sin_addr = *(struct in_addr *)host->h_addr;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<getAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <inet_aton@plt>
cmp    $0x0,%rax
jne    119f <getAddress+0x6f>
mov    -0x10(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1190 <getAddress+0x60>
mov    -0x10(%rbp),%rsi
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <getAddress+0x7b>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rcx
mov    (%rcx),%ecx
mov    %ecx,(%rax)
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getAddress>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <inet_aton@plt>
mov    0x2e91(%rip),%r15
test   %rax,%rax
jne    1179 <getAddress+0x49>
mov    %rbx,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1163 <getAddress+0x33>
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,(%r14)
jmp    1179 <getAddress+0x49>
lea    0xe96(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x2e67(%rip),%r15
mov    (%r15),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.in_addr }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
@.str = [21 x i8] c"Unknown address %s!\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @getAddress(i8* %0, %struct.sockaddr_in* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.sockaddr_in*
%6 = alloca %struct.hostent*
store i8* %0, i8** %4
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %5
%7 = load i8*, i8** %4
%8 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%10 = call i64 @inet_aton(i8* %7, %struct.in_addr* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %30
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call %struct.hostent* @gethostbyname(i8* %13)
store %struct.hostent* %14, %struct.hostent** %6
%15 = load %struct.hostent*, %struct.hostent** %6
%16 = icmp eq %struct.hostent* %15, null
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
store i32 %20, i32* %3
br label %32
21: ; preds = %12
%22 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %22, i32 0, i32 0
%24 = load %struct.hostent*, %struct.hostent** %6
%25 = getelementptr inbounds %struct.hostent, %struct.hostent* %24, i32 0, i32 0
%26 = load i64, i64* %25
%27 = inttoptr i64 %26 to %struct.in_addr*
%28 = bitcast %struct.in_addr* %23 to i8*
%29 = bitcast %struct.in_addr* %27 to i8*
br label %30
30: ; preds = %21, %2
%31 = load i32, i32* @EXIT_SUCCESS
store i32 %31, i32* %3
br label %32
32: ; preds = %30, %17
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.in_addr }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
@.str = [21 x i8] c"Unknown address %s!\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @getAddress(i8* %0, %struct.sockaddr_in* %1) {
%3 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%4 = tail call i64 @inet_aton(i8* %0, %struct.in_addr* %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %17
6: ; preds = %2
%7 = tail call %struct.hostent* @gethostbyname(i8* %0)
%8 = icmp eq %struct.hostent* %7, null
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 0
%11 = load i64, i64* %10
%12 = inttoptr i64 %11 to i32*
%13 = getelementptr %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
%14 = load i32, i32* %12
store i32 %14, i32* %13
br label %17
15: ; preds = %6
%16 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %17
17: ; preds = %2, %9, %15
%18 = phi i32* [ @EXIT_FAILURE, %15 ], [ @EXIT_SUCCESS, %9 ], [ @EXIT_SUCCESS, %2 ]
%19 = load i32, i32* %18
ret i32 %19
}