#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 1;
  }
  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 1;
      }
    }
  }
  freeaddrinfo(res0);
  return 0;
}


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     11f4 <orion_getHostByName+0x94>
cmpq   $0x0,-0x48(%rbp)
je     11e8 <orion_getHostByName+0x88>
mov    -0x48(%rbp),%rdi
call   1080 <freeaddrinfo@plt>
movl   $0x1,-0x4(%rbp)
jmp    12da <orion_getHostByName+0x17a>
mov    -0x48(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12ca <orion_getHostByName+0x16a>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     12b4 <orion_getHostByName+0x154>
mov    -0x50(%rbp),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
je     12af <orion_getHostByName+0x14f>
mov    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
je     12af <orion_getHostByName+0x14f>
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     12a3 <orion_getHostByName+0x143>
mov    -0x48(%rbp),%rdi
call   1080 <freeaddrinfo@plt>
movl   $0x1,-0x4(%rbp)
jmp    12da <orion_getHostByName+0x17a>
jmp    12b4 <orion_getHostByName+0x154>
jmp    12b9 <orion_getHostByName+0x159>
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    11fc <orion_getHostByName+0x9c>
mov    -0x48(%rbp),%rdi
call   1080 <freeaddrinfo@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<orion_getHostByName>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,(%rsp)
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
movq   $0x0,0x18(%rsp)
lea    0xe56(%rip),%rsi
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    %r15,%rdx
call   1070 <getaddrinfo@plt>
mov    (%rsp),%rbx
test   %eax,%eax
je     11d0 <orion_getHostByName+0x70>
mov    $0x1,%r15d
test   %rbx,%rbx
je     1242 <orion_getHostByName+0xe2>
mov    %rbx,%rdi
jmp    123d <orion_getHostByName+0xdd>
xor    %r15d,%r15d
test   %rbx,%rbx
jne    11e9 <orion_getHostByName+0x89>
xor    %edi,%edi
jmp    123d <orion_getHostByName+0xdd>
nopl   0x0(%rax)
mov    0x8(%rbx),%rbx
test   %rbx,%rbx
je     1239 <orion_getHostByName+0xd9>
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,%r12
mov    %rax,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
je     11e0 <orion_getHostByName+0x80>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   1030 <strncpy@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
movb   $0x0,(%r14,%rax,1)
mov    (%rsp),%rdi
mov    $0x1,%r15d
test   %rdi,%rdi
jne    123d <orion_getHostByName+0xdd>
jmp    1242 <orion_getHostByName+0xe2>
mov    (%rsp),%rdi
call   1080 <freeaddrinfo@plt>
mov    %r15d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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 %27
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
store i32 1, i32* %3
br label %75
27: ; preds = %2
%28 = load %struct.addrinfo*, %struct.addrinfo** %8
store %struct.addrinfo* %28, %struct.addrinfo** %7
br label %29
29: ; preds = %68, %27
%30 = load %struct.addrinfo*, %struct.addrinfo** %7
%31 = icmp ne %struct.addrinfo* %30, null
br i1 %31, label %32, label %72
32: ; preds = %29
%33 = load %struct.addrinfo*, %struct.addrinfo** %7
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %33, i32 0, i32 0
%35 = load i64, i64* %34
%36 = inttoptr i64 %35 to %struct.sockaddr_in*
store %struct.sockaddr_in* %36, %struct.sockaddr_in** %9
%37 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%38 = icmp ne %struct.sockaddr_in* %37, null
br i1 %38, label %39, label %67
39: ; preds = %32
%40 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = call i8* @inet_ntoa(i32 %42)
store i8* %43, i8** %11
%44 = load i8*, i8** %11
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %66
46: ; preds = %39
%47 = load i8*, i8** %11
%48 = call i64 @strlen(i8* %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %66
50: ; preds = %46
%51 = load i8*, i8** %5
%52 = load i8*, i8** %11
%53 = load i8*, i8** %11
%54 = call i64 @strlen(i8* %53)
%55 = call i32 @strncpy(i8* %51, i8* %52, i64 %54)
%56 = load i8*, i8** %5
%57 = load i8*, i8** %11
%58 = call i64 @strlen(i8* %57)
%59 = getelementptr inbounds i8, i8* %56, i64 %58
store i8 0, i8* %59
%60 = load %struct.addrinfo*, %struct.addrinfo** %8
%61 = icmp ne %struct.addrinfo* %60, null
br i1 %61, label %62, label %65
62: ; preds = %50
%63 = load %struct.addrinfo*, %struct.addrinfo** %8
%64 = call i32 @freeaddrinfo(%struct.addrinfo* %63)
br label %65
65: ; preds = %62, %50
store i32 1, i32* %3
br label %75
66: ; preds = %46, %39
br label %67
67: ; preds = %66, %32
br label %68
68: ; preds = %67
%69 = load %struct.addrinfo*, %struct.addrinfo** %7
%70 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %69, i32 0, i32 1
%71 = load %struct.addrinfo*, %struct.addrinfo** %70
store %struct.addrinfo* %71, %struct.addrinfo** %7
br label %29
72: ; preds = %29
%73 = load %struct.addrinfo*, %struct.addrinfo** %8
%74 = call i32 @freeaddrinfo(%struct.addrinfo* %73)
store i32 0, i32* %3
br label %75
75: ; preds = %72, %65, %26
%76 = load i32, i32* %3
ret i32 %76
}

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 [ 0, %47 ], [ 1, %17 ], [ 1, %16 ], [ 1, %39 ], [ 1, %33 ]
ret i32 %51
}