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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
unsigned short htons(unsigned short const);
int /*<<< orphan*/ memcpy(char *, unsigned short *, int);
scalar_t__ rfc1035NamePack(char *, size_t const, char const *);
int rfc1035QuestionPack(char *buf, const size_t sz, const char *name,
                        const unsigned short type,
                        const unsigned short _class) {
  unsigned int off = 0;
  unsigned short s;
  off += rfc1035NamePack(buf + off, sz - off, name);
  s = htons(type);
  memcpy(buf + off, &s, sizeof(s));
  off += sizeof(s);
  s = htons(_class);
  memcpy(buf + off, &s, sizeof(s));
  off += sizeof(s);
  assert(off <= sz);
  return off;
}


x86 assembly (clang, -O0):
<rfc1035QuestionPack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r8w,%ax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %cx,-0x1a(%rbp)
mov    %ax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%eax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%eax
sub    %rax,%rsi
mov    -0x18(%rbp),%rdx
call   1060 <rfc1035NamePack@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
movzwl -0x1a(%rbp),%edi
call   1030 <htons@plt>
mov    %ax,-0x22(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%eax
add    %rax,%rdi
lea    -0x22(%rbp),%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%eax
add    $0x2,%rax
mov    %eax,-0x20(%rbp)
movzwl -0x1c(%rbp),%edi
call   1030 <htons@plt>
mov    %ax,-0x22(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%eax
add    %rax,%rdi
lea    -0x22(%rbp),%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%eax
add    $0x2,%rax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rfc1035QuestionPack>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r12d
mov    %ecx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
call   1060 <rfc1035NamePack@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1030 <htons@plt>
mov    %ax,0x6(%rsp)
mov    %ebx,%edi
add    %r15,%rdi
lea    0x6(%rsp),%r13
mov    %r13,%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
lea    0x2(%rbx),%ebp
mov    %r12d,%edi
call   1030 <htons@plt>
mov    %ax,0x6(%rsp)
add    %r15,%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
add    $0x4,%ebx
xor    %edi,%edi
cmp    %r14,%rbx
setbe  %dil
call   1040 <assert@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @rfc1035QuestionPack(i8* %0, i64 %1, i8* %2, i16 zeroext %3, i16 zeroext %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i16
%10 = alloca i16
%11 = alloca i32
%12 = alloca i16
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i16 %3, i16* %9
store i16 %4, i16* %10
store i32 0, i32* %11
%13 = load i8*, i8** %6
%14 = load i32, i32* %11
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i64, i64* %7
%18 = load i32, i32* %11
%19 = zext i32 %18 to i64
%20 = sub i64 %17, %19
%21 = load i8*, i8** %8
%22 = call i64 @rfc1035NamePack(i8* %16, i64 %20, i8* %21)
%23 = load i32, i32* %11
%24 = zext i32 %23 to i64
%25 = add nsw i64 %24, %22
%26 = trunc i64 %25 to i32
store i32 %26, i32* %11
%27 = load i16, i16* %9
%28 = call zeroext i16 @htons(i16 zeroext %27)
store i16 %28, i16* %12
%29 = load i8*, i8** %6
%30 = load i32, i32* %11
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = call i32 @memcpy(i8* %32, i16* %12, i32 2)
%34 = load i32, i32* %11
%35 = zext i32 %34 to i64
%36 = add i64 %35, 2
%37 = trunc i64 %36 to i32
store i32 %37, i32* %11
%38 = load i16, i16* %10
%39 = call zeroext i16 @htons(i16 zeroext %38)
store i16 %39, i16* %12
%40 = load i8*, i8** %6
%41 = load i32, i32* %11
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = call i32 @memcpy(i8* %43, i16* %12, i32 2)
%45 = load i32, i32* %11
%46 = zext i32 %45 to i64
%47 = add i64 %46, 2
%48 = trunc i64 %47 to i32
store i32 %48, i32* %11
%49 = load i32, i32* %11
%50 = zext i32 %49 to i64
%51 = load i64, i64* %7
%52 = icmp ule i64 %50, %51
%53 = zext i1 %52 to i32
%54 = call i32 @assert(i32 %53)
%55 = load i32, i32* %11
ret i32 %55
}

LLVM IR (-O2):
define i32 @rfc1035QuestionPack(i8* %0, i64 %1, i8* %2, i16 zeroext %3, i16 zeroext %4) {
%6 = alloca i16
%7 = bitcast i16* %6 to i8*
%8 = tail call i64 @rfc1035NamePack(i8* %0, i64 %1, i8* %2)
%9 = tail call zeroext i16 @htons(i16 zeroext %3)
store i16 %9, i16* %6
%10 = and i64 %8, 4294967295
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = call i32 @memcpy(i8* %11, i16* %6, i32 2)
%13 = add i64 %8, 2
%14 = call zeroext i16 @htons(i16 zeroext %4)
store i16 %14, i16* %6
%15 = and i64 %13, 4294967295
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = call i32 @memcpy(i8* %16, i16* %6, i32 2)
%18 = trunc i64 %8 to i32
%19 = add i32 %18, 4
%20 = zext i32 %19 to i64
%21 = icmp ule i64 %20, %1
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
ret i32 %19
}