#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_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int sa_family;
};

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ Log(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ inet_ntop(int const, int /*<<< orphan*/ *, char *, int);
scalar_t__ send(int, char *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
size_t strlen(char *);
int amp_asn_add_query_direct(int fd, struct sockaddr *address) {
  char addrstr[INET6_ADDRSTRLEN];
  switch (address->sa_family) {
  case AF_INET:
    inet_ntop(AF_INET, &((struct sockaddr_in *)address)->sin_addr, addrstr,
              INET6_ADDRSTRLEN);
    break;
  case AF_INET6:
    inet_ntop(AF_INET6, &((struct sockaddr_in6 *)address)->sin6_addr, addrstr,
              INET6_ADDRSTRLEN);
    break;
  default:
    return -1;
  };
  addrstr[strlen(addrstr) + 1] = '\0';
  addrstr[strlen(addrstr)] = '\n';
  if (send(fd, addrstr, strlen(addrstr), 0) < 0) {
    Log(4, "Error writing to whois socket: %s\n", strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<amp_asn_add_query_direct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
sub    $0x80,%eax
je     11d7 <amp_asn_add_query_direct+0x87>
jmp    11a4 <amp_asn_add_query_direct+0x54>
mov    -0x28(%rbp),%eax
sub    $0x81,%eax
jne    11f7 <amp_asn_add_query_direct+0xa7>
jmp    11b7 <amp_asn_add_query_direct+0x67>
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rsi
mov    0x2e22(%rip),%rax
mov    (%rax),%ecx
mov    $0x81,%edi
call   1030 <inet_ntop@plt>
jmp    120a <amp_asn_add_query_direct+0xba>
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rsi
mov    0x2e02(%rip),%rax
mov    (%rax),%ecx
mov    $0x80,%edi
call   1030 <inet_ntop@plt>
jmp    120a <amp_asn_add_query_direct+0xba>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    1291 <amp_asn_add_query_direct+0x141>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
movb   $0x0,0x1(%rdi,%rax,1)
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
movb   $0xa,(%rdi,%rax,1)
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0x0,%rax
jge    1283 <amp_asn_add_query_direct+0x133>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%edx
mov    $0x4,%edi
lea    0xd95(%rip),%rsi
call   1060 <Log@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    1291 <amp_asn_add_query_direct+0x141>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<amp_asn_add_query_direct>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    0x2e84(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbx
lea    0xf(%rcx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    (%rsi),%edi
mov    $0xffffffff,%r15d
cmp    $0x81,%edi
je     1194 <amp_asn_add_query_direct+0x44>
cmp    $0x80,%edi
jne    11fc <amp_asn_add_query_direct+0xac>
mov    $0x80,%edi
mov    %rbx,%rdx
call   1030 <inet_ntop@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movb   $0x0,0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
movb   $0xa,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
xor    %r15d,%r15d
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1050 <send@plt>
test   %rax,%rax
jns    11fc <amp_asn_add_query_direct+0xac>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe16(%rip),%rsi
mov    $0x4,%edi
mov    %eax,%edx
call   1060 <Log@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
lea    -0x18(%rbp),%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 }
@INET6_ADDRSTRLEN = global i32 0
@.str = [35 x i8] c"Error writing to whois socket: %s\0A\00"
@errno = global i32 0
define i32 @amp_asn_add_query_direct(i32 %0, %struct.sockaddr* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %4
store %struct.sockaddr* %1, %struct.sockaddr** %5
%9 = load i32, i32* @INET6_ADDRSTRLEN
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load %struct.sockaddr*, %struct.sockaddr** %5
%14 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %13, i32 0, i32 0
%15 = load i32, i32* %14
switch i32 %15, label %28 [
i32 129, label %16
i32 128, label %22
]
16: ; preds = %2
%17 = load %struct.sockaddr*, %struct.sockaddr** %5
%18 = bitcast %struct.sockaddr* %17 to %struct.sockaddr_in*
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 0
%20 = load i32, i32* @INET6_ADDRSTRLEN
%21 = call i32 @inet_ntop(i32 129, i32* %19, i8* %12, i32 %20)
br label %29
22: ; preds = %2
%23 = load %struct.sockaddr*, %struct.sockaddr** %5
%24 = bitcast %struct.sockaddr* %23 to %struct.sockaddr_in6*
%25 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %24, i32 0, i32 0
%26 = load i32, i32* @INET6_ADDRSTRLEN
%27 = call i32 @inet_ntop(i32 128, i32* %25, i8* %12, i32 %26)
br label %29
28: ; preds = %2
store i32 -1, i32* %3
store i32 1, i32* %8
br label %44
29: ; preds = %22, %16
%30 = call i64 @strlen(i8* %12)
%31 = add i64 %30, 1
%32 = getelementptr inbounds i8, i8* %12, i64 %31
store i8 0, i8* %32
%33 = call i64 @strlen(i8* %12)
%34 = getelementptr inbounds i8, i8* %12, i64 %33
store i8 10, i8* %34
%35 = load i32, i32* %4
%36 = call i64 @strlen(i8* %12)
%37 = call i64 @send(i32 %35, i8* %12, i64 %36, i32 0)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %29
%40 = load i32, i32* @errno
%41 = call i32 @strerror(i32 %40)
%42 = call i32 @Log(i32 4, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %41)
store i32 -1, i32* %3
store i32 1, i32* %8
br label %44
43: ; preds = %29
store i32 0, i32* %3
store i32 1, i32* %8
br label %44
44: ; preds = %43, %39, %28
%45 = load i8*, i8** %6
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@.str = [35 x i8] c"Error writing to whois socket: %s\0A\00"
@errno = global i32 0
define i32 @amp_asn_add_query_direct(i32 %0, %struct.sockaddr* %1) {
%3 = load i32, i32* @INET6_ADDRSTRLEN
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
%7 = load i32, i32* %6
switch i32 %7, label %24 [
i32 129, label %9
i32 128, label %8
]
8: ; preds = %2
br label %9
9: ; preds = %2, %8
%10 = phi i32 [ 128, %8 ], [ %7, %2 ]
%11 = call i32 @inet_ntop(i32 %10, i32* %6, i8* %5, i32 %3)
%12 = call i64 @strlen(i8* %5)
%13 = add i64 %12, 1
%14 = getelementptr inbounds i8, i8* %5, i64 %13
store i8 0, i8* %14
%15 = call i64 @strlen(i8* %5)
%16 = getelementptr inbounds i8, i8* %5, i64 %15
store i8 10, i8* %16
%17 = call i64 @strlen(i8* %5)
%18 = call i64 @send(i32 %0, i8* %5, i64 %17, i32 0)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %9
%21 = load i32, i32* @errno
%22 = call i32 @strerror(i32 %21)
%23 = call i32 @Log(i32 4, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %9, %2, %20
%25 = phi i32 [ -1, %20 ], [ -1, %2 ], [ 0, %9 ]
ret i32 %25
}