#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 */
scalar_t__ strcmp(char const *, char const *);
const char *athena_find_tech(const char *which, const char **has_tech,
                             unsigned num_has_tech) {
  if (!num_has_tech)
    return NULL;
  else if (strcmp(*has_tech, which) == 0) {
    return *has_tech;
  } else
    return athena_find_tech(which, has_tech + 1, num_has_tech - 1);
}


x86 assembly (clang, -O0):
<athena_find_tech>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    114a <athena_find_tech+0x2a>
movq   $0x0,-0x8(%rbp)
jmp    118f <athena_find_tech+0x6f>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1174 <athena_find_tech+0x54>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    118f <athena_find_tech+0x6f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x8,%rsi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
call   1040 <athena_find_tech@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<athena_find_tech>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %edx,%edx
je     114c <athena_find_tech+0x3c>
mov    %rsi,%r15
mov    %rdi,%r13
mov    %edx,%r12d
xor    %r14d,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rdi
mov    %r13,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1151 <athena_find_tech+0x41>
add    $0x1,%rbx
cmp    %ebx,%r12d
jne    1130 <athena_find_tech+0x20>
jmp    1155 <athena_find_tech+0x45>
xor    %r14d,%r14d
jmp    1155 <athena_find_tech+0x45>
mov    (%r15,%rbx,8),%r14
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @athena_find_tech(i8* %0, i8** %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %3
store i8* null, i8** %4
br label %27
11: ; preds = %3
%12 = load i8**, i8*** %6
%13 = load i8*, i8** %12
%14 = load i8*, i8** %5
%15 = call i64 @strcmp(i8* %13, i8* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i8**, i8*** %6
%19 = load i8*, i8** %18
store i8* %19, i8** %4
br label %27
20: ; preds = %11
%21 = load i8*, i8** %5
%22 = load i8**, i8*** %6
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i32, i32* %7
%25 = sub i32 %24, 1
%26 = call i8* @athena_find_tech(i8* %21, i8** %23, i32 %25)
store i8* %26, i8** %4
br label %27
27: ; preds = %20, %17, %10
%28 = load i8*, i8** %4
ret i8* %28
}

LLVM IR (-O2):
define i8* @athena_find_tech(i8* %0, i8** nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %17, label %5
5: ; preds = %3, %13
%6 = phi i32 [ %15, %13 ], [ %2, %3 ]
%7 = phi i8** [ %14, %13 ], [ %1, %3 ]
%8 = load i8*, i8** %7
%9 = tail call i64 @strcmp(i8* %8, i8* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = load i8*, i8** %7
br label %17
13: ; preds = %5
%14 = getelementptr inbounds i8*, i8** %7, i64 1
%15 = add i32 %6, -1
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %5
17: ; preds = %13, %3, %11
%18 = phi i8* [ %12, %11 ], [ null, %3 ], [ null, %13 ]
ret i8* %18
}