#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_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ error(char *);
int sendto(int, char *, size_t, int /*<<< orphan*/, struct sockaddr *, int);
void sendDNSquery(int *socksd, char *buffer, struct sockaddr_in serveradd) {
  int n;
  n = sendto(*socksd, buffer, (size_t)512, 0, (struct sockaddr *)&serveradd,
             sizeof serveradd);
  if (n < 0)
    error("ERROR writing to socket\n");
}


x86 assembly (clang, -O0):
<sendDNSquery>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edx,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
lea    -0x8(%rbp),%r8
mov    $0x200,%edx
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1030 <sendto@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    116c <sendDNSquery+0x4c>
lea    0xe99(%rip),%rdi
call   1040 <error@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendDNSquery>:
push   %rax
mov    %edx,(%rsp)
mov    (%rdi),%edi
mov    %rsp,%r8
mov    $0x200,%edx
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1030 <sendto@plt>
test   %eax,%eax
js     1141 <sendDNSquery+0x21>
pop    %rax
ret
lea    0xeb8(%rip),%rdi
call   1040 <error@plt>
pop    %rax
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [25 x i8] c"ERROR writing to socket\0A\00"
define void @sendDNSquery(i32* %0, i8* %1, i32 %2) {
%4 = alloca %struct.sockaddr_in
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i32 %2, i32* %8
store i32* %0, i32** %5
store i8* %1, i8** %6
%9 = load i32*, i32** %5
%10 = load i32, i32* %9
%11 = load i8*, i8** %6
%12 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%13 = call i32 @sendto(i32 %10, i8* %11, i64 512, i32 0, %struct.sockaddr* %12, i32 4)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = call i32 @error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %3
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [25 x i8] c"ERROR writing to socket\0A\00"
define void @sendDNSquery(i32* nocapture %0, i8* %1, i32 %2) {
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %2, i32* %5
%6 = load i32, i32* %0
%7 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%8 = call i32 @sendto(i32 %6, i8* %1, i64 512, i32 0, %struct.sockaddr* %7, i32 4)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = call i32 @error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %3
ret void
}