#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 */
struct evdns_server_request {
  int nquestions;
  struct evdns_server_question **questions;
};
struct evdns_server_question {
  int type;
  char const *name;
};

/* Variables and functions */
int EVDNS_TYPE_A;
int EVDNS_TYPE_AAAA;
int EVDNS_TYPE_PTR;
int /*<<< orphan*/ strcasecmp(char const *, char const *);
const char *evdns_get_orig_address(const struct evdns_server_request *req,
                                   int rtype, const char *addr) {
  int i, type;
  switch (rtype) {
  case 4:
    type = EVDNS_TYPE_A;
    break;
  case 0:
    type = EVDNS_TYPE_PTR;
    break;
  case 6:
    type = EVDNS_TYPE_AAAA;
    break;
  default:;
    return addr;
  }
  for (i = 0; i < req->nquestions; ++i) {
    const struct evdns_server_question *q = req->questions[i];
    if (q->type == type && !strcasecmp(q->name, addr))
      return q->name;
  }
  return addr;
}


x86 assembly (clang, -O0):
<evdns_get_orig_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
test   %eax,%eax
je     1169 <evdns_get_orig_address+0x59>
jmp    1136 <evdns_get_orig_address+0x26>
mov    -0x34(%rbp),%eax
sub    $0x4,%eax
je     1158 <evdns_get_orig_address+0x48>
jmp    1147 <evdns_get_orig_address+0x37>
mov    -0x34(%rbp),%eax
sub    $0x6,%eax
je     117a <evdns_get_orig_address+0x6a>
jmp    118b <evdns_get_orig_address+0x7b>
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    1198 <evdns_get_orig_address+0x88>
mov    0x2e78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    1198 <evdns_get_orig_address+0x88>
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    1198 <evdns_get_orig_address+0x88>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1217 <evdns_get_orig_address+0x107>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    120f <evdns_get_orig_address+0xff>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
cmp    -0x28(%rbp),%eax
jne    11fc <evdns_get_orig_address+0xec>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    11fc <evdns_get_orig_address+0xec>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    1217 <evdns_get_orig_address+0x107>
jmp    1201 <evdns_get_orig_address+0xf1>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119f <evdns_get_orig_address+0x8f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evdns_get_orig_address>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
cmp    $0x6,%esi
je     1135 <evdns_get_orig_address+0x25>
cmp    $0x4,%esi
je     113e <evdns_get_orig_address+0x2e>
test   %esi,%esi
jne    1188 <evdns_get_orig_address+0x78>
mov    0x2eb5(%rip),%rax
jmp    1145 <evdns_get_orig_address+0x35>
mov    0x2e9c(%rip),%rax
jmp    1145 <evdns_get_orig_address+0x35>
mov    0x2e8b(%rip),%rax
mov    (%rdi),%r15d
test   %r15d,%r15d
jle    1188 <evdns_get_orig_address+0x78>
mov    (%rax),%r12d
mov    0x8(%rdi),%r13
xor    %ebp,%ebp
jmp    1169 <evdns_get_orig_address+0x59>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r15
je     1188 <evdns_get_orig_address+0x78>
mov    0x0(%r13,%rbp,8),%rax
cmp    %r12d,(%rax)
jne    1160 <evdns_get_orig_address+0x50>
mov    0x8(%rax),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
jne    1160 <evdns_get_orig_address+0x50>
jmp    118b <evdns_get_orig_address+0x7b>
mov    %r14,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.evdns_server_request = type { i32, %struct.evdns_server_question** }
%struct.evdns_server_question = type { i32, i8* }
@EVDNS_TYPE_A = global i32 0
@EVDNS_TYPE_PTR = global i32 0
@EVDNS_TYPE_AAAA = global i32 0
define i8* @evdns_get_orig_address(%struct.evdns_server_request* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca %struct.evdns_server_request*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.evdns_server_question*
store %struct.evdns_server_request* %0, %struct.evdns_server_request** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%11 = load i32, i32* %6
switch i32 %11, label %18 [
i32 4, label %12
i32 0, label %14
i32 6, label %16
]
12: ; preds = %3
%13 = load i32, i32* @EVDNS_TYPE_A
store i32 %13, i32* %9
br label %20
14: ; preds = %3
%15 = load i32, i32* @EVDNS_TYPE_PTR
store i32 %15, i32* %9
br label %20
16: ; preds = %3
%17 = load i32, i32* @EVDNS_TYPE_AAAA
store i32 %17, i32* %9
br label %20
18: ; preds = %3
%19 = load i8*, i8** %7
store i8* %19, i8** %4
br label %57
20: ; preds = %16, %14, %12
store i32 0, i32* %8
br label %21
21: ; preds = %52, %20
%22 = load i32, i32* %8
%23 = load %struct.evdns_server_request*, %struct.evdns_server_request** %5
%24 = getelementptr inbounds %struct.evdns_server_request, %struct.evdns_server_request* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = icmp slt i32 %22, %25
br i1 %26, label %27, label %55
27: ; preds = %21
%28 = load %struct.evdns_server_request*, %struct.evdns_server_request** %5
%29 = getelementptr inbounds %struct.evdns_server_request, %struct.evdns_server_request* %28, i32 0, i32 1
%30 = load %struct.evdns_server_question**, %struct.evdns_server_question*** %29
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds %struct.evdns_server_question*, %struct.evdns_server_question** %30, i64 %32
%34 = load %struct.evdns_server_question*, %struct.evdns_server_question** %33
store %struct.evdns_server_question* %34, %struct.evdns_server_question** %10
%35 = load %struct.evdns_server_question*, %struct.evdns_server_question** %10
%36 = getelementptr inbounds %struct.evdns_server_question, %struct.evdns_server_question* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = load i32, i32* %9
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %51
40: ; preds = %27
%41 = load %struct.evdns_server_question*, %struct.evdns_server_question** %10
%42 = getelementptr inbounds %struct.evdns_server_question, %struct.evdns_server_question* %41, i32 0, i32 1
%43 = load i8*, i8** %42
%44 = load i8*, i8** %7
%45 = call i32 @strcasecmp(i8* %43, i8* %44)
%46 = icmp ne i32 %45, 0
br i1 %46, label %51, label %47
47: ; preds = %40
%48 = load %struct.evdns_server_question*, %struct.evdns_server_question** %10
%49 = getelementptr inbounds %struct.evdns_server_question, %struct.evdns_server_question* %48, i32 0, i32 1
%50 = load i8*, i8** %49
store i8* %50, i8** %4
br label %57
51: ; preds = %40, %27
br label %52
52: ; preds = %51
%53 = load i32, i32* %8
%54 = add nsw i32 %53, 1
store i32 %54, i32* %8
br label %21
55: ; preds = %21
%56 = load i8*, i8** %7
store i8* %56, i8** %4
br label %57
57: ; preds = %55, %47, %18
%58 = load i8*, i8** %4
ret i8* %58
}

LLVM IR (-O2):
%struct.evdns_server_request = type { i32, %struct.evdns_server_question** }
%struct.evdns_server_question = type { i32, i8* }
@EVDNS_TYPE_A = global i32 0
@EVDNS_TYPE_PTR = global i32 0
@EVDNS_TYPE_AAAA = global i32 0
define i8* @evdns_get_orig_address(%struct.evdns_server_request* nocapture %0, i32 %1, i8* %2) {
switch i32 %1, label %31 [
i32 4, label %6
i32 0, label %4
i32 6, label %5
]
4: ; preds = %3
br label %6
5: ; preds = %3
br label %6
6: ; preds = %3, %5, %4
%7 = phi i32* [ @EVDNS_TYPE_AAAA, %5 ], [ @EVDNS_TYPE_PTR, %4 ], [ @EVDNS_TYPE_A, %3 ]
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.evdns_server_request, %struct.evdns_server_request* %0, i64 0, i32 0
%10 = load i32, i32* %9
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %31
12: ; preds = %6
%13 = getelementptr inbounds %struct.evdns_server_request, %struct.evdns_server_request* %0, i64 0, i32 1
%14 = load %struct.evdns_server_question**, %struct.evdns_server_question*** %13
%15 = zext i32 %10 to i64
br label %16
16: ; preds = %12, %28
%17 = phi i64 [ 0, %12 ], [ %29, %28 ]
%18 = getelementptr inbounds %struct.evdns_server_question*, %struct.evdns_server_question** %14, i64 %17
%19 = load %struct.evdns_server_question*, %struct.evdns_server_question** %18
%20 = getelementptr inbounds %struct.evdns_server_question, %struct.evdns_server_question* %19, i64 0, i32 0
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, %8
br i1 %22, label %23, label %28
23: ; preds = %16
%24 = getelementptr inbounds %struct.evdns_server_question, %struct.evdns_server_question* %19, i64 0, i32 1
%25 = load i8*, i8** %24
%26 = tail call i32 @strcasecmp(i8* %25, i8* %2)
%27 = icmp eq i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %16, %23
%29 = add nuw nsw i64 %17, 1
%30 = icmp eq i64 %29, %15
br i1 %30, label %31, label %16
31: ; preds = %28, %23, %6, %3
%32 = phi i8* [ %2, %3 ], [ %2, %6 ], [ %2, %28 ], [ %25, %23 ]
ret i8* %32
}