#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*/ uint16_t;
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int sa_family;
};
struct in_addr {
  int dummy;
};
struct in6_addr {
  int dummy;
};

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int /*<<< orphan*/ Log(int, char *, ...);
int /*<<< orphan*/ MSG_NOSIGNAL;
int /*<<< orphan*/ errno;
scalar_t__ send(int, void *, int, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int amp_asn_add_query_local(int fd, struct sockaddr *address) {
  void *addr;
  int length;
  Log(7, "Sending ASN query to local socket");
  switch (address->sa_family) {
  case AF_INET:
    addr = &((struct sockaddr_in *)address)->sin_addr;
    length = sizeof(struct in_addr);
    break;
  case AF_INET6:
    addr = &((struct sockaddr_in6 *)address)->sin6_addr;
    length = sizeof(struct in6_addr);
    break;
  default:
    Log(4, "Unknown address family");
    return -1;
  };
  Log(7, "Sending ASN address family");
  if (send(fd, (void *)&address->sa_family, sizeof(uint16_t), MSG_NOSIGNAL) <
      0) {
    Log(4, "Failed to send asn address family: %s", strerror(errno));
    return -1;
  }
  Log(7, "Sending ASN address");
  if (send(fd, addr, length, MSG_NOSIGNAL) < 0) {
    Log(4, "Failed to send asn address: %s", strerror(errno));
    return -1;
  }
  Log(7, "Sent ASN address and family ok");
  return 0;
}


x86 assembly (clang, -O0):
<amp_asn_add_query_local>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeba(%rip),%rsi
xor    %eax,%eax
mov    $0x7,%edi
call   1040 <Log@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
sub    $0x80,%eax
je     1192 <amp_asn_add_query_local+0x62>
jmp    116b <amp_asn_add_query_local+0x3b>
mov    -0x20(%rbp),%eax
sub    $0x81,%eax
jne    11a6 <amp_asn_add_query_local+0x76>
jmp    117e <amp_asn_add_query_local+0x4e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x4,-0x1c(%rbp)
jmp    11c5 <amp_asn_add_query_local+0x95>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x4,-0x1c(%rbp)
jmp    11c5 <amp_asn_add_query_local+0x95>
mov    $0x4,%edi
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1040 <Log@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a9 <amp_asn_add_query_local+0x179>
mov    $0x7,%edi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1040 <Log@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2df2(%rip),%rax
mov    (%rax),%ecx
mov    $0x4,%edx
call   1030 <send@plt>
cmp    $0x0,%rax
jge    122b <amp_asn_add_query_local+0xfb>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%edx
mov    $0x4,%edi
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1040 <Log@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a9 <amp_asn_add_query_local+0x179>
mov    $0x7,%edi
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1040 <Log@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    0x2d89(%rip),%rax
mov    (%rax),%ecx
call   1030 <send@plt>
cmp    $0x0,%rax
jge    128f <amp_asn_add_query_local+0x15f>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%edx
mov    $0x4,%edi
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1040 <Log@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a9 <amp_asn_add_query_local+0x179>
mov    $0x7,%edi
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1040 <Log@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<amp_asn_add_query_local>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0xebc(%rip),%rsi
mov    $0x7,%edi
xor    %eax,%eax
call   1040 <Log@plt>
mov    (%rbx),%eax
and    $0xfffffffe,%eax
cmp    $0x80,%eax
jne    11d0 <amp_asn_add_query_local+0xa0>
lea    0xed6(%rip),%rsi
mov    $0x7,%edi
xor    %eax,%eax
call   1040 <Log@plt>
mov    0x2e62(%rip),%r15
mov    (%r15),%ecx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <send@plt>
test   %rax,%rax
js     11e5 <amp_asn_add_query_local+0xb5>
lea    0xee5(%rip),%rsi
xor    %ebp,%ebp
mov    $0x7,%edi
xor    %eax,%eax
call   1040 <Log@plt>
mov    (%r15),%ecx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <send@plt>
test   %rax,%rax
js     11fc <amp_asn_add_query_local+0xcc>
lea    0xeeb(%rip),%rsi
mov    $0x7,%edi
xor    %eax,%eax
call   1040 <Log@plt>
jmp    1224 <amp_asn_add_query_local+0xf4>
lea    0xe4b(%rip),%rsi
mov    $0x4,%edi
xor    %eax,%eax
call   1040 <Log@plt>
jmp    121f <amp_asn_add_query_local+0xef>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe5a(%rip),%rsi
jmp    1211 <amp_asn_add_query_local+0xe1>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe7d(%rip),%rsi
mov    $0x4,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <Log@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@.str = [34 x i8] c"Sending ASN query to local socket\00"
@.str.1 = [23 x i8] c"Unknown address family\00"
@.str.2 = [27 x i8] c"Sending ASN address family\00"
@MSG_NOSIGNAL = global i32 0
@.str.3 = [38 x i8] c"Failed to send asn address family: %s\00"
@errno = global i32 0
@.str.4 = [20 x i8] c"Sending ASN address\00"
@.str.5 = [31 x i8] c"Failed to send asn address: %s\00"
@.str.6 = [31 x i8] c"Sent ASN address and family ok\00"
define i32 @amp_asn_add_query_local(i32 %0, %struct.sockaddr* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr*
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store %struct.sockaddr* %1, %struct.sockaddr** %5
%8 = call i32 (i32, i8*, ...) @Log(i32 7, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%9 = load %struct.sockaddr*, %struct.sockaddr** %5
%10 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %9, i32 0, i32 0
%11 = load i32, i32* %10
switch i32 %11, label %22 [
i32 129, label %12
i32 128, label %17
]
12: ; preds = %2
%13 = load %struct.sockaddr*, %struct.sockaddr** %5
%14 = bitcast %struct.sockaddr* %13 to %struct.sockaddr_in*
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 0
%16 = bitcast i32* %15 to i8*
store i8* %16, i8** %6
store i32 4, i32* %7
br label %24
17: ; preds = %2
%18 = load %struct.sockaddr*, %struct.sockaddr** %5
%19 = bitcast %struct.sockaddr* %18 to %struct.sockaddr_in6*
%20 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %19, i32 0, i32 0
%21 = bitcast i32* %20 to i8*
store i8* %21, i8** %6
store i32 4, i32* %7
br label %24
22: ; preds = %2
%23 = call i32 (i32, i8*, ...) @Log(i32 4, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %51
24: ; preds = %17, %12
%25 = call i32 (i32, i8*, ...) @Log(i32 7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* %4
%27 = load %struct.sockaddr*, %struct.sockaddr** %5
%28 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %27, i32 0, i32 0
%29 = bitcast i32* %28 to i8*
%30 = load i32, i32* @MSG_NOSIGNAL
%31 = call i64 @send(i32 %26, i8* %29, i32 4, i32 %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %24
%34 = load i32, i32* @errno
%35 = call i32 @strerror(i32 %34)
%36 = call i32 (i32, i8*, ...) @Log(i32 4, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %35)
store i32 -1, i32* %3
br label %51
37: ; preds = %24
%38 = call i32 (i32, i8*, ...) @Log(i32 7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%39 = load i32, i32* %4
%40 = load i8*, i8** %6
%41 = load i32, i32* %7
%42 = load i32, i32* @MSG_NOSIGNAL
%43 = call i64 @send(i32 %39, i8* %40, i32 %41, i32 %42)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %37
%46 = load i32, i32* @errno
%47 = call i32 @strerror(i32 %46)
%48 = call i32 (i32, i8*, ...) @Log(i32 4, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %47)
store i32 -1, i32* %3
br label %51
49: ; preds = %37
%50 = call i32 (i32, i8*, ...) @Log(i32 7, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %3
br label %51
51: ; preds = %49, %45, %33, %22
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [34 x i8] c"Sending ASN query to local socket\00"
@.str.1 = [23 x i8] c"Unknown address family\00"
@.str.2 = [27 x i8] c"Sending ASN address family\00"
@MSG_NOSIGNAL = global i32 0
@.str.3 = [38 x i8] c"Failed to send asn address family: %s\00"
@errno = global i32 0
@.str.4 = [20 x i8] c"Sending ASN address\00"
@.str.5 = [31 x i8] c"Failed to send asn address: %s\00"
@.str.6 = [31 x i8] c"Sent ASN address and family ok\00"
define i32 @amp_asn_add_query_local(i32 %0, %struct.sockaddr* %1) {
%3 = tail call i32 (i32, i8*, ...) @Log(i32 7, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
%5 = load i32, i32* %4
%6 = and i32 %5, -2
%7 = icmp eq i32 %6, 128
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 (i32, i8*, ...) @Log(i32 4, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %31
10: ; preds = %2
%11 = tail call i32 (i32, i8*, ...) @Log(i32 7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%12 = bitcast %struct.sockaddr* %1 to i8*
%13 = load i32, i32* @MSG_NOSIGNAL
%14 = tail call i64 @send(i32 %0, i8* %12, i32 4, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = load i32, i32* @errno
%18 = tail call i32 @strerror(i32 %17)
%19 = tail call i32 (i32, i8*, ...) @Log(i32 4, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %18)
br label %31
20: ; preds = %10
%21 = tail call i32 (i32, i8*, ...) @Log(i32 7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%22 = load i32, i32* @MSG_NOSIGNAL
%23 = tail call i64 @send(i32 %0, i8* %12, i32 4, i32 %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32, i32* @errno
%27 = tail call i32 @strerror(i32 %26)
%28 = tail call i32 (i32, i8*, ...) @Log(i32 4, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %27)
br label %31
29: ; preds = %20
%30 = tail call i32 (i32, i8*, ...) @Log(i32 7, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
br label %31
31: ; preds = %29, %25, %16, %8
%32 = phi i32 [ -1, %8 ], [ -1, %16 ], [ -1, %25 ], [ 0, %29 ]
ret i32 %32
}