#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_storage {
  scalar_t__ ss_family;
};
struct sockaddr {
  int dummy;
};
struct iptrie {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
scalar_t__ AF_UNIX;
struct iptrie *amp_asn_fetch_results_direct(int, struct iptrie *);
struct iptrie *amp_asn_fetch_results_local(int, struct iptrie *);
scalar_t__ getsockname(int, struct sockaddr *, int *);
struct iptrie *amp_asn_fetch_results(int fd, struct iptrie *results) {
  struct sockaddr_storage addr;
  socklen_t socklen;
  socklen = sizeof(struct sockaddr_storage);
  if (getsockname(fd, (struct sockaddr *)&addr, &socklen) < 0) {
    return results;
  }
  if (addr.ss_family == AF_UNIX) {
    return amp_asn_fetch_results_local(fd, results);
  }
  return amp_asn_fetch_results_direct(fd, results);
}


x86 assembly (clang, -O0):
<amp_asn_fetch_results>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x8,-0x24(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1040 <getsockname@plt>
cmp    $0x0,%rax
jge    116d <amp_asn_fetch_results+0x3d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a6 <amp_asn_fetch_results+0x76>
mov    -0x20(%rbp),%rax
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%rax
jne    1196 <amp_asn_fetch_results+0x66>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1050 <amp_asn_fetch_results_local@plt>
mov    %rax,-0x8(%rbp)
jmp    11a6 <amp_asn_fetch_results+0x76>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <amp_asn_fetch_results_direct@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<amp_asn_fetch_results>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x8,0xc(%rsp)
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1040 <getsockname@plt>
test   %rax,%rax
js     1181 <amp_asn_fetch_results+0x51>
mov    0x10(%rsp),%rax
mov    0x2e85(%rip),%rcx
cmp    (%rcx),%rax
jne    1174 <amp_asn_fetch_results+0x44>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <amp_asn_fetch_results_local@plt>
jmp    117e <amp_asn_fetch_results+0x4e>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <amp_asn_fetch_results_direct@plt>
mov    %rax,%rbx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.iptrie = type { i32 }
%struct.sockaddr_storage = type { i64 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i64 0
define %struct.iptrie* @amp_asn_fetch_results(i32 %0, %struct.iptrie* %1) {
%3 = alloca %struct.iptrie*
%4 = alloca i32
%5 = alloca %struct.iptrie*
%6 = alloca %struct.sockaddr_storage
%7 = alloca i32
store i32 %0, i32* %4
store %struct.iptrie* %1, %struct.iptrie** %5
store i32 8, i32* %7
%8 = load i32, i32* %4
%9 = bitcast %struct.sockaddr_storage* %6 to %struct.sockaddr*
%10 = call i64 @getsockname(i32 %8, %struct.sockaddr* %9, i32* %7)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load %struct.iptrie*, %struct.iptrie** %5
store %struct.iptrie* %13, %struct.iptrie** %3
br label %27
14: ; preds = %2
%15 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %6, i32 0, i32 0
%16 = load i64, i64* %15
%17 = load i64, i64* @AF_UNIX
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i32, i32* %4
%21 = load %struct.iptrie*, %struct.iptrie** %5
%22 = call %struct.iptrie* @amp_asn_fetch_results_local(i32 %20, %struct.iptrie* %21)
store %struct.iptrie* %22, %struct.iptrie** %3
br label %27
23: ; preds = %14
%24 = load i32, i32* %4
%25 = load %struct.iptrie*, %struct.iptrie** %5
%26 = call %struct.iptrie* @amp_asn_fetch_results_direct(i32 %24, %struct.iptrie* %25)
store %struct.iptrie* %26, %struct.iptrie** %3
br label %27
27: ; preds = %23, %19, %12
%28 = load %struct.iptrie*, %struct.iptrie** %3
ret %struct.iptrie* %28
}

LLVM IR (-O2):
%struct.iptrie = type { i32 }
%struct.sockaddr_storage = type { i64 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i64 0
define %struct.iptrie* @amp_asn_fetch_results(i32 %0, %struct.iptrie* %1) {
%3 = alloca %struct.sockaddr_storage
%4 = alloca i32
%5 = bitcast %struct.sockaddr_storage* %3 to i8*
%6 = bitcast i32* %4 to i8*
store i32 8, i32* %4
%7 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
%8 = call i64 @getsockname(i32 %0, %struct.sockaddr* %7, i32* %4)
%9 = icmp slt i64 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %2
%11 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %3, i64 0, i32 0
%12 = load i64, i64* %11
%13 = load i64, i64* @AF_UNIX
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call %struct.iptrie* @amp_asn_fetch_results_local(i32 %0, %struct.iptrie* %1)
br label %19
17: ; preds = %10
%18 = call %struct.iptrie* @amp_asn_fetch_results_direct(i32 %0, %struct.iptrie* %1)
br label %19
19: ; preds = %2, %17, %15
%20 = phi %struct.iptrie* [ %16, %15 ], [ %18, %17 ], [ %1, %2 ]
ret %struct.iptrie* %20
}