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

/* Variables and functions */
int /*<<< orphan*/ PF_UNSPEC;
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int getaddrinfo(char const *, int /*<<< orphan*/ *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int orion_getDomainByAddr(struct addrinfo *, char *);
scalar_t__ strlen(char *);
int orion_getDomain(const char *ip, char *buffer) {
  struct addrinfo hints, *res0;
  int error;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = PF_UNSPEC;
  hints.ai_socktype = 0;
  error = getaddrinfo(ip, NULL, &hints, &res0);
  if (error) {
    if (res0)
      freeaddrinfo(res0);
    return error;
  }
  error = orion_getDomainByAddr(res0, buffer);
  freeaddrinfo(res0);
  if (error)
    return error;
  if (buffer && *buffer && strlen(buffer))
    return 0x00;
  else
    return 0x01;
}


x86 assembly (clang, -O0):
<orion_getDomain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1060 <getaddrinfo@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11c5 <orion_getDomain+0x75>
cmpq   $0x0,-0x30(%rbp)
je     11ba <orion_getDomain+0x6a>
mov    -0x30(%rbp),%rdi
call   1070 <freeaddrinfo@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1234 <orion_getDomain+0xe4>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <orion_getDomainByAddr@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <freeaddrinfo@plt>
cmpl   $0x0,-0x34(%rbp)
je     11f3 <orion_getDomain+0xa3>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1234 <orion_getDomain+0xe4>
cmpq   $0x0,-0x18(%rbp)
je     122d <orion_getDomain+0xdd>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     122d <orion_getDomain+0xdd>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
je     122d <orion_getDomain+0xdd>
movl   $0x0,-0x4(%rbp)
jmp    1234 <orion_getDomain+0xe4>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<orion_getDomain>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rcx
mov    %rbp,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1050 <getaddrinfo@plt>
mov    0x8(%rsp),%rdi
test   %eax,%eax
je     11a1 <orion_getDomain+0x61>
mov    %eax,%ebp
test   %rdi,%rdi
je     11cb <orion_getDomain+0x8b>
call   1060 <freeaddrinfo@plt>
jmp    11cb <orion_getDomain+0x8b>
mov    %r14,%rsi
call   1040 <orion_getDomainByAddr@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rdi
call   1060 <freeaddrinfo@plt>
test   %ebp,%ebp
jne    11cb <orion_getDomain+0x8b>
test   %r14,%r14
je     11c6 <orion_getDomain+0x86>
xor    %ebp,%ebp
cmpb   $0x0,(%r14)
jne    11cb <orion_getDomain+0x8b>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i64, i32 }
@PF_UNSPEC = global i32 0
define i32 @orion_getDomain(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.addrinfo
%7 = alloca %struct.addrinfo*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 16)
%10 = load i32, i32* @PF_UNSPEC
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 1
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 0
store i64 0, i64* %12
%13 = load i8*, i8** %4
%14 = call i32 @getaddrinfo(i8* %13, i32* null, %struct.addrinfo* %6, %struct.addrinfo** %7)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %2
%18 = load %struct.addrinfo*, %struct.addrinfo** %7
%19 = icmp ne %struct.addrinfo* %18, null
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load %struct.addrinfo*, %struct.addrinfo** %7
%22 = call i32 @freeaddrinfo(%struct.addrinfo* %21)
br label %23
23: ; preds = %20, %17
%24 = load i32, i32* %8
store i32 %24, i32* %3
br label %49
25: ; preds = %2
%26 = load %struct.addrinfo*, %struct.addrinfo** %7
%27 = load i8*, i8** %5
%28 = call i32 @orion_getDomainByAddr(%struct.addrinfo* %26, i8* %27)
store i32 %28, i32* %8
%29 = load %struct.addrinfo*, %struct.addrinfo** %7
%30 = call i32 @freeaddrinfo(%struct.addrinfo* %29)
%31 = load i32, i32* %8
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %25
%34 = load i32, i32* %8
store i32 %34, i32* %3
br label %49
35: ; preds = %25
%36 = load i8*, i8** %5
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %48
38: ; preds = %35
%39 = load i8*, i8** %5
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %38
%44 = load i8*, i8** %5
%45 = call i64 @strlen(i8* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %43
store i32 0, i32* %3
br label %49
48: ; preds = %43, %38, %35
store i32 1, i32* %3
br label %49
49: ; preds = %48, %47, %33, %23
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i32 }
@PF_UNSPEC = global i32 0
define i32 @orion_getDomain(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*
%7 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 16)
%8 = load i32, i32* @PF_UNSPEC
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 1
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 0
store i64 0, i64* %10
%11 = call i32 @getaddrinfo(i8* %0, i32* null, %struct.addrinfo* %3, %struct.addrinfo** %4)
%12 = icmp eq i32 %11, 0
%13 = load %struct.addrinfo*, %struct.addrinfo** %4
br i1 %12, label %18, label %14
14: ; preds = %2
%15 = icmp eq %struct.addrinfo* %13, null
br i1 %15, label %29, label %16
16: ; preds = %14
%17 = call i32 @freeaddrinfo(%struct.addrinfo* %13)
br label %29
18: ; preds = %2
%19 = call i32 @orion_getDomainByAddr(%struct.addrinfo* %13, i8* %1)
%20 = load %struct.addrinfo*, %struct.addrinfo** %4
%21 = call i32 @freeaddrinfo(%struct.addrinfo* %20)
%22 = icmp eq i32 %19, 0
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = icmp eq i8* %1, null
br i1 %24, label %28, label %25
25: ; preds = %23
%26 = load i8, i8* %1
%27 = icmp eq i8 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %25, %23
br label %29
29: ; preds = %25, %18, %14, %16, %28
%30 = phi i32 [ 1, %28 ], [ %11, %16 ], [ %11, %14 ], [ %19, %18 ], [ 0, %25 ]
ret i32 %30
}