#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;
typedef size_t off_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
unsigned short htons(unsigned short);
int /*<<< orphan*/ memcpy(char *, unsigned short *, int);
scalar_t__ rfc1035NamePack(char *, size_t, char const *);
off_t rfc1035QuestionPack(char *buf, size_t sz, const char *name,
                          unsigned short type, unsigned short class) {
  off_t 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)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
sub    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <rfc1035NamePack@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
movzwl -0x1a(%rbp),%edi
call   1030 <htons@plt>
mov    %ax,-0x2a(%rbp)
mov    -0x8(%rbp),%rdi
add    -0x28(%rbp),%rdi
lea    -0x2a(%rbp),%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
movzwl -0x1c(%rbp),%edi
call   1030 <htons@plt>
mov    %ax,-0x2a(%rbp)
mov    -0x8(%rbp),%rdi
add    -0x28(%rbp),%rdi
lea    -0x2a(%rbp),%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define i64 @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 i64
%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 i64 0, i64* %11
%13 = load i8*, i8** %6
%14 = load i64, i64* %11
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = load i64, i64* %7
%17 = load i64, i64* %11
%18 = sub i64 %16, %17
%19 = load i8*, i8** %8
%20 = call i64 @rfc1035NamePack(i8* %15, i64 %18, i8* %19)
%21 = load i64, i64* %11
%22 = add i64 %21, %20
store i64 %22, i64* %11
%23 = load i16, i16* %9
%24 = call zeroext i16 @htons(i16 zeroext %23)
store i16 %24, i16* %12
%25 = load i8*, i8** %6
%26 = load i64, i64* %11
%27 = getelementptr inbounds i8, i8* %25, i64 %26
%28 = call i32 @memcpy(i8* %27, i16* %12, i32 2)
%29 = load i64, i64* %11
%30 = add i64 %29, 2
store i64 %30, i64* %11
%31 = load i16, i16* %10
%32 = call zeroext i16 @htons(i16 zeroext %31)
store i16 %32, i16* %12
%33 = load i8*, i8** %6
%34 = load i64, i64* %11
%35 = getelementptr inbounds i8, i8* %33, i64 %34
%36 = call i32 @memcpy(i8* %35, i16* %12, i32 2)
%37 = load i64, i64* %11
%38 = add i64 %37, 2
store i64 %38, i64* %11
%39 = load i64, i64* %11
%40 = load i64, i64* %7
%41 = icmp ule i64 %39, %40
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load i64, i64* %11
ret i64 %44
}

LLVM IR (-O2):
define i64 @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 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = call i32 @memcpy(i8* %10, i16* %6, i32 2)
%12 = add i64 %8, 2
%13 = call zeroext i16 @htons(i16 zeroext %4)
store i16 %13, i16* %6
%14 = getelementptr inbounds i8, i8* %0, i64 %12
%15 = call i32 @memcpy(i8* %14, i16* %6, i32 2)
%16 = add i64 %8, 4
%17 = icmp ule i64 %16, %1
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
ret i64 %16
}