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

/* Variables and functions */
int dnsgetstr(unsigned char *, int, int, char *, int);
int dnsrrstr(unsigned char *, int, unsigned int, unsigned int, unsigned int,
             unsigned int, char *, int);
int /*<<< orphan*/ printf(char *, char *, ...);
void dnsrec(unsigned char *buf, int blen, int rind, int nameoff,
            unsigned int rtype, unsigned int rclass, unsigned int rttl,
            unsigned int rsize, unsigned int recoff, void *edata) {
  char *aty[] = {
      "Query",
      "Answer",
      "Authority",
      "Additional",
  };
  char sbuf[256];
  int rc;
  rc = dnsgetstr(buf, blen, nameoff, sbuf, sizeof(sbuf));
  printf("%s", rc < 0 ? "ERROR" : sbuf);
  rc = dnsrrstr(buf, blen, rtype, rclass, rsize, recoff, sbuf, sizeof(sbuf));
  printf(" - %s %s\n", aty[rind], rc ? "ERROR" : sbuf);
}


x86 assembly (clang, -O0):
<dnsrec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
mov    0x2c9c(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2c99(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2c96(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c93(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    -0x140(%rbp),%rcx
mov    $0x100,%r8d
call   1040 <dnsgetstr@plt>
mov    %eax,-0x144(%rbp)
cmpl   $0x0,-0x144(%rbp)
jge    11cb <dnsrec+0x9b>
lea    0xe66(%rip),%rax
mov    %rax,-0x150(%rbp)
jmp    11d9 <dnsrec+0xa9>
lea    -0x140(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    -0x150(%rbp),%rsi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    0x18(%rbp),%r8d
mov    0x20(%rbp),%r9d
lea    -0x140(%rbp),%rax
mov    %rax,(%rsp)
movl   $0x100,0x8(%rsp)
call   1050 <dnsrrstr@plt>
mov    %eax,-0x144(%rbp)
movslq -0x10(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rax
mov    %rax,-0x158(%rbp)
cmpl   $0x0,-0x144(%rbp)
je     1251 <dnsrec+0x121>
lea    0xde0(%rip),%rax
mov    %rax,-0x160(%rbp)
jmp    125f <dnsrec+0x12f>
lea    -0x140(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x158(%rbp),%rsi
mov    -0x160(%rbp),%rdx
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dnsrec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %r9d,%r15d
mov    %r8d,%r12d
mov    %edx,0xc(%rsp)
mov    %esi,%r13d
mov    %rdi,%r14
lea    0x10(%rsp),%rbx
mov    %ecx,%edx
mov    %rbx,%rcx
mov    $0x100,%r8d
call   1040 <dnsgetstr@plt>
test   %eax,%eax
lea    0xeb6(%rip),%rbp
mov    %rbx,%rsi
cmovs  %rbp,%rsi
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %r13d,%esi
mov    %r12d,%edx
mov    %r15d,%ecx
mov    0x158(%rsp),%r8d
mov    0x160(%rsp),%r9d
push   $0x100
push   %rbx
call   1050 <dnsrrstr@plt>
add    $0x10,%rsp
movslq 0xc(%rsp),%rcx
lea    0xe7d(%rip),%rdx
movslq (%rdx,%rcx,4),%rsi
add    %rdx,%rsi
test   %eax,%eax
cmove  %rbx,%rbp
lea    0xe5c(%rip),%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"Query\00"
@.str.1 = [7 x i8] c"Answer\00"
@.str.2 = [10 x i8] c"Authority\00"
@.str.3 = [11 x i8] c"Additional\00"
@__const.dnsrec.aty = [4 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i32 0, i32 0)]
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [6 x i8] c"ERROR\00"
@.str.6 = [10 x i8] c" - %s %s\0A\00"
define void @dnsrec(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8, i8* %9) {
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i8*
%21 = alloca [4 x i8*]
%22 = alloca [256 x i8]
%23 = alloca i32
store i8* %0, i8** %11
store i32 %1, i32* %12
store i32 %2, i32* %13
store i32 %3, i32* %14
store i32 %4, i32* %15
store i32 %5, i32* %16
store i32 %6, i32* %17
store i32 %7, i32* %18
store i32 %8, i32* %19
store i8* %9, i8** %20
%24 = bitcast [4 x i8*]* %21 to i8*
%25 = load i8*, i8** %11
%26 = load i32, i32* %12
%27 = load i32, i32* %14
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %22, i64 0, i64 0
%29 = call i32 @dnsgetstr(i8* %25, i32 %26, i32 %27, i8* %28, i32 256)
store i32 %29, i32* %23
%30 = load i32, i32* %23
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %10
br label %35
33: ; preds = %10
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %22, i64 0, i64 0
br label %35
35: ; preds = %33, %32
%36 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), %32 ], [ %34, %33 ]
%37 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %36)
%38 = load i8*, i8** %11
%39 = load i32, i32* %12
%40 = load i32, i32* %15
%41 = load i32, i32* %16
%42 = load i32, i32* %18
%43 = load i32, i32* %19
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %22, i64 0, i64 0
%45 = call i32 @dnsrrstr(i8* %38, i32 %39, i32 %40, i32 %41, i32 %42, i32 %43, i8* %44, i32 256)
store i32 %45, i32* %23
%46 = load i32, i32* %13
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [4 x i8*], [4 x i8*]* %21, i64 0, i64 %47
%49 = load i8*, i8** %48
%50 = load i32, i32* %23
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %35
br label %55
53: ; preds = %35
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %22, i64 0, i64 0
br label %55
55: ; preds = %53, %52
%56 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), %52 ], [ %54, %53 ]
%57 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %49, i8* %56)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"Query\00"
@.str.1 = [7 x i8] c"Answer\00"
@.str.2 = [10 x i8] c"Authority\00"
@.str.3 = [11 x i8] c"Additional\00"
@reltable.dnsrec = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str to i64), i64 ptrtoint ([4 x i32]* @reltable.dnsrec to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.dnsrec to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.dnsrec to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.dnsrec to i64)) to i32)]
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [6 x i8] c"ERROR\00"
@.str.6 = [10 x i8] c" - %s %s\0A\00"
define void @dnsrec(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8, i8* nocapture readnone %9) {
%11 = alloca [256 x i8]
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%13 = call i32 @dnsgetstr(i8* %0, i32 %1, i32 %3, i8* %12, i32 256)
%14 = icmp slt i32 %13, 0
%15 = select i1 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %12
%16 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %15)
%17 = call i32 @dnsrrstr(i8* %0, i32 %1, i32 %4, i32 %5, i32 %7, i32 %8, i8* %12, i32 256)
%18 = sext i32 %2 to i64
%19 = shl i64 %18, 2
%20 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.dnsrec to i8*), i64 %19)
%21 = icmp eq i32 %17, 0
%22 = select i1 %21, i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0)
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %20, i8* %22)
ret void
}