#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef scalar_t__ uint16_t;
struct sockaddr_storage {
  int dummy;
};
struct sockaddr_in6 {
  int dummy;
};
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
struct iptrie {
  int dummy;
};
typedef int /*<<< orphan*/ prefix;
typedef int /*<<< orphan*/ int64_t;
typedef int /*<<< orphan*/ family;
typedef int /*<<< orphan*/ asn;

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
int /*<<< orphan*/ Log(int, char *);
int /*<<< orphan*/ iptrie_add(struct iptrie *, struct sockaddr *,
                              int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ recv(int, void *, size_t, int /*<<< orphan*/);
struct iptrie *amp_asn_fetch_results_local(int fd, struct iptrie *result) {
  Log(7, "Waiting for address list");
  while (1) {
    int64_t asn;
    uint16_t family;
    uint8_t prefix;
    size_t addrlen;
    struct sockaddr_storage addr;
    if (recv(fd, (void *)&asn, sizeof(asn), 0) <= 0) {
      break;
    }
    if (recv(fd, (void *)&prefix, sizeof(prefix), 0) <= 0) {
      break;
    }
    if (recv(fd, (void *)&family, sizeof(family), 0) <= 0) {
      break;
    }
    if (family == AF_INET) {
      addrlen = sizeof(struct sockaddr_in);
    } else if (family == AF_INET6) {
      addrlen = sizeof(struct sockaddr_in6);
    } else {
      break;
    }
    if (recv(fd, (void *)&addr, addrlen, 0) <= 0) {
      break;
    }
    iptrie_add(result, (struct sockaddr *)&addr, prefix, asn);
  }
  return result;
}


x86 assembly (clang, -O0):
<amp_asn_fetch_results_local>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x7,%edi
lea    0xeb5(%rip),%rsi
call   1050 <Log@plt>
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
jg     1172 <amp_asn_fetch_results_local+0x42>
jmp    123b <amp_asn_fetch_results_local+0x10b>
mov    -0x4(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
jg     1194 <amp_asn_fetch_results_local+0x64>
jmp    123b <amp_asn_fetch_results_local+0x10b>
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
jg     11b6 <amp_asn_fetch_results_local+0x86>
jmp    123b <amp_asn_fetch_results_local+0x10b>
mov    -0x20(%rbp),%rax
mov    0x2e27(%rip),%rcx
cmp    (%rcx),%rax
jne    11d7 <amp_asn_fetch_results_local+0xa7>
movq   $0x4,-0x30(%rbp)
jmp    1202 <amp_asn_fetch_results_local+0xd2>
mov    -0x20(%rbp),%rax
mov    0x2dfe(%rip),%rcx
cmp    (%rcx),%rax
jne    11f8 <amp_asn_fetch_results_local+0xc8>
movq   $0x4,-0x30(%rbp)
jmp    11fd <amp_asn_fetch_results_local+0xcd>
jmp    123b <amp_asn_fetch_results_local+0x10b>
jmp    1202 <amp_asn_fetch_results_local+0xd2>
mov    -0x4(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
jg     1223 <amp_asn_fetch_results_local+0xf3>
jmp    123b <amp_asn_fetch_results_local+0x10b>
mov    -0x10(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1040 <iptrie_add@plt>
jmp    1150 <amp_asn_fetch_results_local+0x20>
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<amp_asn_fetch_results_local>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xeb6(%rip),%rsi
mov    $0x7,%edi
call   1050 <Log@plt>
mov    %rsp,%rsi
mov    $0x4,%edx
mov    %ebp,%edi
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jle    1215 <amp_asn_fetch_results_local+0xe5>
lea    0x4(%rsp),%r14
lea    0x10(%rsp),%r15
mov    0x2e69(%rip),%r13
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x4,%edx
mov    %ebp,%edi
mov    %r14,%rsi
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jle    1215 <amp_asn_fetch_results_local+0xe5>
mov    $0x8,%edx
mov    %ebp,%edi
mov    %r15,%rsi
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jle    1215 <amp_asn_fetch_results_local+0xe5>
mov    0x10(%rsp),%rax
cmp    0x0(%r13),%rax
je     11d3 <amp_asn_fetch_results_local+0xa3>
mov    0x2e12(%rip),%rcx
cmp    (%rcx),%rax
jne    1215 <amp_asn_fetch_results_local+0xe5>
mov    $0x4,%edx
mov    %ebp,%edi
mov    %r12,%rsi
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jle    1215 <amp_asn_fetch_results_local+0xe5>
mov    0x4(%rsp),%edx
mov    (%rsp),%ecx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <iptrie_add@plt>
mov    $0x4,%edx
mov    %ebp,%edi
mov    %rsp,%rsi
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jg     1190 <amp_asn_fetch_results_local+0x60>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.iptrie = type { i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [25 x i8] c"Waiting for address list\00"
@AF_INET = global i64 0
@AF_INET6 = global i64 0
define %struct.iptrie* @amp_asn_fetch_results_local(i32 %0, %struct.iptrie* %1) {
%3 = alloca i32
%4 = alloca %struct.iptrie*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca i64
%9 = alloca %struct.sockaddr_storage
store i32 %0, i32* %3
store %struct.iptrie* %1, %struct.iptrie** %4
%10 = call i32 @Log(i32 7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %2, %48
%12 = load i32, i32* %3
%13 = bitcast i32* %5 to i8*
%14 = call i64 @recv(i32 %12, i8* %13, i64 4, i32 0)
%15 = icmp sle i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11
br label %54
17: ; preds = %11
%18 = load i32, i32* %3
%19 = bitcast i32* %7 to i8*
%20 = call i64 @recv(i32 %18, i8* %19, i64 4, i32 0)
%21 = icmp sle i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17
br label %54
23: ; preds = %17
%24 = load i32, i32* %3
%25 = bitcast i64* %6 to i8*
%26 = call i64 @recv(i32 %24, i8* %25, i64 8, i32 0)
%27 = icmp sle i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
br label %54
29: ; preds = %23
%30 = load i64, i64* %6
%31 = load i64, i64* @AF_INET
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %29
store i64 4, i64* %8
br label %41
34: ; preds = %29
%35 = load i64, i64* %6
%36 = load i64, i64* @AF_INET6
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %39
38: ; preds = %34
store i64 4, i64* %8
br label %40
39: ; preds = %34
br label %54
40: ; preds = %38
br label %41
41: ; preds = %40, %33
%42 = load i32, i32* %3
%43 = bitcast %struct.sockaddr_storage* %9 to i8*
%44 = load i64, i64* %8
%45 = call i64 @recv(i32 %42, i8* %43, i64 %44, i32 0)
%46 = icmp sle i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %41
br label %54
48: ; preds = %41
%49 = load %struct.iptrie*, %struct.iptrie** %4
%50 = bitcast %struct.sockaddr_storage* %9 to %struct.sockaddr*
%51 = load i32, i32* %7
%52 = load i32, i32* %5
%53 = call i32 @iptrie_add(%struct.iptrie* %49, %struct.sockaddr* %50, i32 %51, i32 %52)
br label %11
54: ; preds = %47, %39, %28, %22, %16
%55 = load %struct.iptrie*, %struct.iptrie** %4
ret %struct.iptrie* %55
}

LLVM IR (-O2):
%struct.iptrie = type { i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [25 x i8] c"Waiting for address list\00"
@AF_INET = global i64 0
@AF_INET6 = global i64 0
define %struct.iptrie* @amp_asn_fetch_results_local(i32 %0, %struct.iptrie* returned %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
%6 = alloca %struct.sockaddr_storage
%7 = tail call i32 @Log(i32 7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = bitcast i32* %3 to i8*
%9 = bitcast i64* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast %struct.sockaddr_storage* %6 to i8*
%12 = call i64 @recv(i32 %0, i8* %8, i64 4, i32 0)
%13 = icmp slt i64 %12, 1
br i1 %13, label %38, label %14
14: ; preds = %2
%15 = bitcast %struct.sockaddr_storage* %6 to %struct.sockaddr*
br label %16
16: ; preds = %14, %32
%17 = call i64 @recv(i32 %0, i8* %10, i64 4, i32 0)
%18 = icmp slt i64 %17, 1
br i1 %18, label %38, label %19
19: ; preds = %16
%20 = call i64 @recv(i32 %0, i8* %9, i64 8, i32 0)
%21 = icmp slt i64 %20, 1
br i1 %21, label %38, label %22
22: ; preds = %19
%23 = load i64, i64* %4
%24 = load i64, i64* @AF_INET
%25 = icmp eq i64 %23, %24
%26 = load i64, i64* @AF_INET6
%27 = icmp eq i64 %23, %26
%28 = select i1 %25, i1 true, i1 %27
br i1 %28, label %29, label %38
29: ; preds = %22
%30 = call i64 @recv(i32 %0, i8* %11, i64 4, i32 0)
%31 = icmp slt i64 %30, 1
br i1 %31, label %38, label %32
32: ; preds = %29
%33 = load i32, i32* %5
%34 = load i32, i32* %3
%35 = call i32 @iptrie_add(%struct.iptrie* %1, %struct.sockaddr* %15, i32 %33, i32 %34)
%36 = call i64 @recv(i32 %0, i8* %8, i64 4, i32 0)
%37 = icmp slt i64 %36, 1
br i1 %37, label %38, label %16
38: ; preds = %22, %29, %19, %16, %32, %2
ret %struct.iptrie* %1
}