#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct addrinfo {
  scalar_t__ ai_addr;
  struct addrinfo *ai_next;
  scalar_t__ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ PF_UNSPEC;
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int getaddrinfo(char const *, char *, struct addrinfo *, struct addrinfo **);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
int orion_getHostByName(const char *name, char *buffer) {
  struct addrinfo hints, *res, *res0 = NULL;
  struct sockaddr_in *target = NULL;
  int error;
  char *tmp = NULL;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = PF_UNSPEC;
  hints.ai_socktype = 0;
  error = getaddrinfo(name, "http", &hints, &res0);
  if (error) {
    if (res0)
      freeaddrinfo(res0);
    return error;
  }
  for (res = res0; res; res = res->ai_next) {
    target = (struct sockaddr_in *)res->ai_addr;
    if (target) {
      tmp = inet_ntoa(target->sin_addr);
      if (tmp && strlen(tmp)) {
        strncpy(buffer, tmp, strlen(tmp));
        buffer[strlen(tmp)] = '\0';
        if (res0)
          freeaddrinfo(res0);
        return 0x00;
      }
    }
  }
  freeaddrinfo(res0);
  return 0x06;
}


x86 assembly (clang, -O0):
<orion_getHostByName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x60(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe46(%rip),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   1070 <getaddrinfo@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     11f3 <orion_getHostByName+0x93>
cmpq   $0x0,-0x48(%rbp)
je     11e8 <orion_getHostByName+0x88>
mov    -0x48(%rbp),%rdi
call   1080 <freeaddrinfo@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12d9 <orion_getHostByName+0x179>
mov    -0x48(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12c9 <orion_getHostByName+0x169>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     12b3 <orion_getHostByName+0x153>
mov    -0x50(%rbp),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
je     12ae <orion_getHostByName+0x14e>
mov    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
je     12ae <orion_getHostByName+0x14e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x78(%rbp),%rdi
mov    -0x70(%rbp),%rsi
mov    %rax,%rdx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
cmpq   $0x0,-0x48(%rbp)
je     12a2 <orion_getHostByName+0x142>
mov    -0x48(%rbp),%rdi
call   1080 <freeaddrinfo@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d9 <orion_getHostByName+0x179>
jmp    12b3 <orion_getHostByName+0x153>
jmp    12b8 <orion_getHostByName+0x158>
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    11fb <orion_getHostByName+0x9b>
mov    -0x48(%rbp),%rdi
call   1080 <freeaddrinfo@plt>
movl   $0x6,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<orion_getHostByName>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
movq   $0x0,0x20(%rsp)
lea    0xe58(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1070 <getaddrinfo@plt>
mov    0x8(%rsp),%rbx
test   %eax,%eax
je     11d6 <orion_getHostByName+0x76>
mov    %eax,%ebp
test   %rbx,%rbx
je     124a <orion_getHostByName+0xea>
mov    %rbx,%rdi
call   1080 <freeaddrinfo@plt>
jmp    124a <orion_getHostByName+0xea>
test   %rbx,%rbx
jne    11e9 <orion_getHostByName+0x89>
xor    %edi,%edi
jmp    1240 <orion_getHostByName+0xe0>
nop
mov    0x8(%rbx),%rbx
test   %rbx,%rbx
je     123b <orion_getHostByName+0xdb>
mov    (%rbx),%rax
test   %rax,%rax
je     11e0 <orion_getHostByName+0x80>
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
test   %rax,%rax
je     11e0 <orion_getHostByName+0x80>
mov    %rax,%rbp
mov    %rax,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
je     11e0 <orion_getHostByName+0x80>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1030 <strncpy@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
movb   $0x0,(%r14,%rax,1)
mov    0x8(%rsp),%rdi
xor    %ebp,%ebp
test   %rdi,%rdi
je     124a <orion_getHostByName+0xea>
call   1080 <freeaddrinfo@plt>
jmp    124a <orion_getHostByName+0xea>
mov    0x8(%rsp),%rdi
call   1080 <freeaddrinfo@plt>
mov    $0x6,%ebp
mov    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i64, %struct.addrinfo*, i64, i32 }
%struct.sockaddr_in = type { i32 }
@PF_UNSPEC = global i32 0
@.str = [5 x i8] c"http\00"
define i32 @orion_getHostByName(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.addrinfo
%7 = alloca %struct.addrinfo*
%8 = alloca %struct.addrinfo*
%9 = alloca %struct.sockaddr_in*
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store %struct.addrinfo* null, %struct.addrinfo** %8
store %struct.sockaddr_in* null, %struct.sockaddr_in** %9
store i8* null, i8** %11
%12 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 32)
%13 = load i32, i32* @PF_UNSPEC
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 2
store i64 0, i64* %15
%16 = load i8*, i8** %4
%17 = call i32 @getaddrinfo(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %6, %struct.addrinfo** %8)
store i32 %17, i32* %10
%18 = load i32, i32* %10
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %2
%21 = load %struct.addrinfo*, %struct.addrinfo** %8
%22 = icmp ne %struct.addrinfo* %21, null
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load %struct.addrinfo*, %struct.addrinfo** %8
%25 = call i32 @freeaddrinfo(%struct.addrinfo* %24)
br label %26
26: ; preds = %23, %20
%27 = load i32, i32* %10
store i32 %27, i32* %3
br label %76
28: ; preds = %2
%29 = load %struct.addrinfo*, %struct.addrinfo** %8
store %struct.addrinfo* %29, %struct.addrinfo** %7
br label %30
30: ; preds = %69, %28
%31 = load %struct.addrinfo*, %struct.addrinfo** %7
%32 = icmp ne %struct.addrinfo* %31, null
br i1 %32, label %33, label %73
33: ; preds = %30
%34 = load %struct.addrinfo*, %struct.addrinfo** %7
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i32 0, i32 0
%36 = load i64, i64* %35
%37 = inttoptr i64 %36 to %struct.sockaddr_in*
store %struct.sockaddr_in* %37, %struct.sockaddr_in** %9
%38 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%39 = icmp ne %struct.sockaddr_in* %38, null
br i1 %39, label %40, label %68
40: ; preds = %33
%41 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %41, i32 0, i32 0
%43 = load i32, i32* %42
%44 = call i8* @inet_ntoa(i32 %43)
store i8* %44, i8** %11
%45 = load i8*, i8** %11
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %67
47: ; preds = %40
%48 = load i8*, i8** %11
%49 = call i64 @strlen(i8* %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %67
51: ; preds = %47
%52 = load i8*, i8** %5
%53 = load i8*, i8** %11
%54 = load i8*, i8** %11
%55 = call i64 @strlen(i8* %54)
%56 = call i32 @strncpy(i8* %52, i8* %53, i64 %55)
%57 = load i8*, i8** %5
%58 = load i8*, i8** %11
%59 = call i64 @strlen(i8* %58)
%60 = getelementptr inbounds i8, i8* %57, i64 %59
store i8 0, i8* %60
%61 = load %struct.addrinfo*, %struct.addrinfo** %8
%62 = icmp ne %struct.addrinfo* %61, null
br i1 %62, label %63, label %66
63: ; preds = %51
%64 = load %struct.addrinfo*, %struct.addrinfo** %8
%65 = call i32 @freeaddrinfo(%struct.addrinfo* %64)
br label %66
66: ; preds = %63, %51
store i32 0, i32* %3
br label %76
67: ; preds = %47, %40
br label %68
68: ; preds = %67, %33
br label %69
69: ; preds = %68
%70 = load %struct.addrinfo*, %struct.addrinfo** %7
%71 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %70, i32 0, i32 1
%72 = load %struct.addrinfo*, %struct.addrinfo** %71
store %struct.addrinfo* %72, %struct.addrinfo** %7
br label %30
73: ; preds = %30
%74 = load %struct.addrinfo*, %struct.addrinfo** %8
%75 = call i32 @freeaddrinfo(%struct.addrinfo* %74)
store i32 6, i32* %3
br label %76
76: ; preds = %73, %66, %26
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, %struct.addrinfo*, i64, i32 }
%struct.sockaddr_in = type { i32 }
@PF_UNSPEC = global i32 0
@.str = [5 x i8] c"http\00"
define i32 @orion_getHostByName(i8* %0, i8* %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = bitcast %struct.addrinfo* %3 to i8*
%6 = bitcast %struct.addrinfo** %4 to i8*
store %struct.addrinfo* null, %struct.addrinfo** %4
%7 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 32)
%8 = load i32, i32* @PF_UNSPEC
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i64 0, i64* %10
%11 = call i32 @getaddrinfo(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %3, %struct.addrinfo** %4)
%12 = icmp eq i32 %11, 0
%13 = load %struct.addrinfo*, %struct.addrinfo** %4
%14 = icmp eq %struct.addrinfo* %13, null
br i1 %12, label %15, label %16
15: ; preds = %2
br i1 %14, label %47, label %19
16: ; preds = %2
br i1 %14, label %50, label %17
17: ; preds = %16
%18 = call i32 @freeaddrinfo(%struct.addrinfo* %13)
br label %50
19: ; preds = %15, %41
%20 = phi %struct.addrinfo* [ %43, %41 ], [ %13, %15 ]
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %20, i64 0, i32 0
%22 = load i64, i64* %21
%23 = icmp eq i64 %22, 0
br i1 %23, label %41, label %24
24: ; preds = %19
%25 = inttoptr i64 %22 to %struct.sockaddr_in*
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %25, i64 0, i32 0
%27 = load i32, i32* %26
%28 = call i8* @inet_ntoa(i32 %27)
%29 = icmp eq i8* %28, null
br i1 %29, label %41, label %30
30: ; preds = %24
%31 = call i64 @strlen(i8* %28)
%32 = icmp eq i64 %31, 0
br i1 %32, label %41, label %33
33: ; preds = %30
%34 = call i32 @strncpy(i8* %1, i8* %28, i64 %31)
%35 = call i64 @strlen(i8* %28)
%36 = getelementptr inbounds i8, i8* %1, i64 %35
store i8 0, i8* %36
%37 = load %struct.addrinfo*, %struct.addrinfo** %4
%38 = icmp eq %struct.addrinfo* %37, null
br i1 %38, label %50, label %39
39: ; preds = %33
%40 = call i32 @freeaddrinfo(%struct.addrinfo* %37)
br label %50
41: ; preds = %19, %30, %24
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %20, i64 0, i32 1
%43 = load %struct.addrinfo*, %struct.addrinfo** %42
%44 = icmp eq %struct.addrinfo* %43, null
br i1 %44, label %45, label %19
45: ; preds = %41
%46 = load %struct.addrinfo*, %struct.addrinfo** %4
br label %47
47: ; preds = %45, %15
%48 = phi %struct.addrinfo* [ %46, %45 ], [ null, %15 ]
%49 = call i32 @freeaddrinfo(%struct.addrinfo* %48)
br label %50
50: ; preds = %33, %39, %16, %17, %47
%51 = phi i32 [ 6, %47 ], [ %11, %17 ], [ %11, %16 ], [ 0, %39 ], [ 0, %33 ]
ret i32 %51
}