#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*/ query_name;

/* Variables and functions */
int /*<<< orphan*/ decode_domain_name(char *);
int ntohs(unsigned short);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, void *, int);
void print_query(void *ptr) {
  char query_name[256];
  unsigned short int query_type;
  unsigned short int query_class;
  printf("Starting pointer: %d\n", (int)ptr);
  strncpy(query_name, ptr, sizeof(query_name));
  ptr += strlen(query_name) + 1;
  query_type = *((unsigned short int *)ptr);
  ptr += 2;
  query_class = *((unsigned short int *)ptr);
  decode_domain_name(query_name);
  printf("Host: %s - query type: %d class: %d\n", query_name, ntohs(query_type),
         ntohs(query_class));
}


x86 assembly (clang, -O0):
<print_query>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%esi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%ax
mov    %ax,-0x112(%rbp)
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%ax
mov    %ax,-0x114(%rbp)
lea    -0x110(%rbp),%rdi
call   1060 <decode_domain_name@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x120(%rbp)
movzwl -0x112(%rbp),%edi
call   1070 <ntohs@plt>
mov    %eax,-0x118(%rbp)
movzwl -0x114(%rbp),%edi
call   1070 <ntohs@plt>
mov    -0x120(%rbp),%rsi
mov    -0x118(%rbp),%edx
mov    %eax,%ecx
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_query>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbx
lea    0xe9b(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
movzwl 0x1(%rax,%rbx,1),%ebp
movzwl 0x3(%rax,%rbx,1),%ebx
mov    %r14,%rdi
call   1060 <decode_domain_name@plt>
mov    %ebp,%edi
call   1070 <ntohs@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1070 <ntohs@plt>
lea    0xe64(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Starting pointer: %d\0A\00"
@.str.1 = [37 x i8] c"Host: %s - query type: %d class: %d\0A\00"
define void @print_query(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
%4 = alloca i16
%5 = alloca i16
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = ptrtoint i8* %6 to i32
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = load i8*, i8** %2
%11 = call i32 @strncpy(i8* %9, i8* %10, i32 256)
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%13 = call i64 @strlen(i8* %12)
%14 = add nsw i64 %13, 1
%15 = load i8*, i8** %2
%16 = getelementptr i8, i8* %15, i64 %14
store i8* %16, i8** %2
%17 = load i8*, i8** %2
%18 = bitcast i8* %17 to i16*
%19 = load i16, i16* %18
store i16 %19, i16* %4
%20 = load i8*, i8** %2
%21 = getelementptr i8, i8* %20, i64 2
store i8* %21, i8** %2
%22 = load i8*, i8** %2
%23 = bitcast i8* %22 to i16*
%24 = load i16, i16* %23
store i16 %24, i16* %5
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%26 = call i32 @decode_domain_name(i8* %25)
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%28 = load i16, i16* %4
%29 = call i32 @ntohs(i16 zeroext %28)
%30 = load i16, i16* %5
%31 = call i32 @ntohs(i16 zeroext %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %27, i32 %29, i32 %31)
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"Starting pointer: %d\0A\00"
@.str.1 = [37 x i8] c"Host: %s - query type: %d class: %d\0A\00"
define void @print_query(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = ptrtoint i8* %0 to i64
%5 = trunc i64 %4 to i32
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32 @strncpy(i8* %3, i8* %0, i32 256)
%8 = call i64 @strlen(i8* %3)
%9 = add nsw i64 %8, 1
%10 = getelementptr i8, i8* %0, i64 %9
%11 = bitcast i8* %10 to i16*
%12 = load i16, i16* %11
%13 = getelementptr i8, i8* %10, i64 2
%14 = bitcast i8* %13 to i16*
%15 = load i16, i16* %14
%16 = call i32 @decode_domain_name(i8* %3)
%17 = call i32 @ntohs(i16 zeroext %12)
%18 = call i32 @ntohs(i16 zeroext %15)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %3, i32 %17, i32 %18)
ret void
}