#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 *, char *);
int tool_search_string(int n, char **array, char *str) {
  while (--n)
    if (strcmp(array[n], str) == 0)
      return 1;
  return 0;
}


x86 assembly (clang, -O0):
<tool_search_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     1165 <tool_search_string+0x55>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1160 <tool_search_string+0x50>
movl   $0x1,-0x4(%rbp)
jmp    116c <tool_search_string+0x5c>
jmp    1123 <tool_search_string+0x13>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tool_search_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r15
movslq %edi,%rax
lea    (%rsi,%rax,8),%r12
add    $0xfffffffffffffff8,%r12
mov    $0x1,%r13d
sub    %eax,%r13d
xor    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
cmp    %ebx,%r13d
je     1160 <tool_search_string+0x50>
mov    (%r12,%rbx,8),%rdi
mov    %r15,%rsi
call   1030 <strcmp@plt>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    1140 <tool_search_string+0x30>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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