#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 {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  struct addrinfo *ai_next;
};

/* Variables and functions */
int /*<<< orphan*/ NI_MAXHOST;
int getnameinfo(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/,
                int /*<<< orphan*/);
scalar_t__ strlen(char *);
int orion_getDomainByAddr(struct addrinfo *addr, char *buffer) {
  struct addrinfo *res;
  int error = 0x00;
  for (res = addr; res; res = res->ai_next) {
    error = getnameinfo(res->ai_addr, res->ai_addrlen, buffer, NI_MAXHOST, NULL,
                        0, 0);
    if (error)
      continue;
    if (buffer && *buffer && strlen(buffer)) {
      error = 0x00;
      break;
    }
  }
  return error;
}


x86 assembly (clang, -O0):
<orion_getDomainByAddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11da <orion_getDomainByAddr+0xba>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
mov    0x2e7e(%rip),%rax
mov    (%rax),%ecx
xor    %eax,%eax
mov    %eax,%r8d
xor    %r9d,%r9d
movl   $0x0,(%rsp)
call   1040 <getnameinfo@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     118a <orion_getDomainByAddr+0x6a>
jmp    11c9 <orion_getDomainByAddr+0xa9>
cmpq   $0x0,-0x10(%rbp)
je     11c4 <orion_getDomainByAddr+0xa4>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c4 <orion_getDomainByAddr+0xa4>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
je     11c4 <orion_getDomainByAddr+0xa4>
movl   $0x0,-0x1c(%rbp)
jmp    11da <orion_getDomainByAddr+0xba>
jmp    11c9 <orion_getDomainByAddr+0xa9>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    113f <orion_getDomainByAddr+0x1f>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<orion_getDomainByAddr>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     1165 <orion_getDomainByAddr+0x55>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2eb5(%rip),%r15
jmp    1139 <orion_getDomainByAddr+0x29>
nopl   (%rax)
mov    0x8(%rbx),%rbx
test   %rbx,%rbx
je     1167 <orion_getDomainByAddr+0x57>
mov    (%rbx),%esi
mov    0x4(%rbx),%edi
mov    (%r15),%ecx
movl   $0x0,(%rsp)
mov    %r14,%rdx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <getnameinfo@plt>
test   %r14,%r14
je     1130 <orion_getDomainByAddr+0x20>
test   %eax,%eax
jne    1130 <orion_getDomainByAddr+0x20>
cmpb   $0x0,(%r14)
je     1130 <orion_getDomainByAddr+0x20>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, %struct.addrinfo* }
@NI_MAXHOST = global i32 0
define i32 @orion_getDomainByAddr(%struct.addrinfo* %0, i8* %1) {
%3 = icmp eq %struct.addrinfo* %0, null
br i1 %3, label %23, label %4
4: ; preds = %2
%5 = icmp ne i8* %1, null
br label %6
6: ; preds = %4, %19
%7 = phi %struct.addrinfo* [ %0, %4 ], [ %21, %19 ]
%8 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 1
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 0
%11 = load i32, i32* %10
%12 = load i32, i32* @NI_MAXHOST
%13 = tail call i32 @getnameinfo(i32 %9, i32 %11, i8* %1, i32 %12, i32* null, i32 0, i32 0)
%14 = icmp eq i32 %13, 0
%15 = and i1 %5, %14
br i1 %15, label %16, label %19
16: ; preds = %6
%17 = load i8, i8* %1
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16, %6
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 2
%21 = load %struct.addrinfo*, %struct.addrinfo** %20
%22 = icmp eq %struct.addrinfo* %21, null
br i1 %22, label %23, label %6
23: ; preds = %19, %16, %2
%24 = phi i32 [ 0, %2 ], [ 0, %16 ], [ %13, %19 ]
ret i32 %24
}