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

/* Variables and functions */
int decode_domain_name(char *);
unsigned short ntohs(unsigned short);
int /*<<< orphan*/ strncpy(char *, char *, int);
int strnlen(char *, int);
int extract_request(char *buffer, char *host_name, unsigned short int *type,
                    unsigned short int *class) {
  int res;
  int enl;
  strncpy(host_name, buffer, 256);
  res = decode_domain_name(host_name);
  if (res == 1)
    return 1;
  enl = strnlen(buffer, 536);
  if (enl == 536)
    return 1;
  (*type) = ntohs(*(unsigned short int *)(buffer + enl + 1));
  (*class) = ntohs(*(unsigned short int *)(buffer + enl + 3));
  return 0;
}


x86 assembly (clang, -O0):
<extract_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
call   1050 <decode_domain_name@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jne    118c <extract_request+0x4c>
movl   $0x1,-0x4(%rbp)
jmp    11f5 <extract_request+0xb5>
mov    -0x10(%rbp),%rdi
mov    $0x218,%esi
call   1040 <strnlen@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x218,-0x30(%rbp)
jne    11b6 <extract_request+0x76>
movl   $0x1,-0x4(%rbp)
jmp    11f5 <extract_request+0xb5>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
movzwl 0x1(%rax,%rcx,1),%edi
call   1060 <ntohs@plt>
mov    %ax,%cx
mov    -0x20(%rbp),%rax
mov    %cx,(%rax)
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
movzwl 0x3(%rax,%rcx,1),%edi
call   1060 <ntohs@plt>
mov    %ax,%cx
mov    -0x28(%rbp),%rax
mov    %cx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_request>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    %rbp,%rdi
call   1050 <decode_domain_name@plt>
mov    $0x1,%ebp
cmp    $0x1,%eax
je     11aa <extract_request+0x6a>
mov    %rbx,%rdi
mov    $0x218,%esi
call   1040 <strnlen@plt>
cmp    $0x218,%eax
je     11aa <extract_request+0x6a>
movslq %eax,%rbp
movzwl 0x1(%rbx,%rbp,1),%edi
call   1060 <ntohs@plt>
mov    %ax,(%r15)
movzwl 0x3(%rbx,%rbp,1),%edi
call   1060 <ntohs@plt>
mov    %ax,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @extract_request(i8* %0, i8* %1, i16* %2, i16* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i16*
%9 = alloca i16*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i16* %2, i16** %8
store i16* %3, i16** %9
%12 = load i8*, i8** %7
%13 = load i8*, i8** %6
%14 = call i32 @strncpy(i8* %12, i8* %13, i32 256)
%15 = load i8*, i8** %7
%16 = call i32 @decode_domain_name(i8* %15)
store i32 %16, i32* %10
%17 = load i32, i32* %10
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %20
19: ; preds = %4
store i32 1, i32* %5
br label %45
20: ; preds = %4
%21 = load i8*, i8** %6
%22 = call i32 @strnlen(i8* %21, i32 536)
store i32 %22, i32* %11
%23 = load i32, i32* %11
%24 = icmp eq i32 %23, 536
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 1, i32* %5
br label %45
26: ; preds = %20
%27 = load i8*, i8** %6
%28 = load i32, i32* %11
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = bitcast i8* %31 to i16*
%33 = load i16, i16* %32
%34 = call zeroext i16 @ntohs(i16 zeroext %33)
%35 = load i16*, i16** %8
store i16 %34, i16* %35
%36 = load i8*, i8** %6
%37 = load i32, i32* %11
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = getelementptr inbounds i8, i8* %39, i64 3
%41 = bitcast i8* %40 to i16*
%42 = load i16, i16* %41
%43 = call zeroext i16 @ntohs(i16 zeroext %42)
%44 = load i16*, i16** %9
store i16 %43, i16* %44
store i32 0, i32* %5
br label %45
45: ; preds = %26, %25, %19
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
define i32 @extract_request(i8* %0, i8* %1, i16* nocapture writeonly %2, i16* nocapture writeonly %3) {
%5 = tail call i32 @strncpy(i8* %1, i8* %0, i32 256)
%6 = tail call i32 @decode_domain_name(i8* %1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %22, label %8
8: ; preds = %4
%9 = tail call i32 @strnlen(i8* %0, i32 536)
%10 = icmp eq i32 %9, 536
br i1 %10, label %22, label %11
11: ; preds = %8
%12 = sext i32 %9 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = bitcast i8* %14 to i16*
%16 = load i16, i16* %15
%17 = tail call zeroext i16 @ntohs(i16 zeroext %16)
store i16 %17, i16* %2
%18 = getelementptr inbounds i8, i8* %13, i64 3
%19 = bitcast i8* %18 to i16*
%20 = load i16, i16* %19
%21 = tail call zeroext i16 @ntohs(i16 zeroext %20)
store i16 %21, i16* %3
br label %22
22: ; preds = %8, %4, %11
%23 = phi i32 [ 0, %11 ], [ 1, %4 ], [ 1, %8 ]
ret i32 %23
}