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

/* Variables and functions */
scalar_t__ is_usable_library(char const *, int /*<<< orphan*/);
int find_xlib_by_arch(const char *possible_locations[], int locations_length,
                      uint16_t desired_architecture) {
  int i;
  for (i = 0; i < locations_length; i++) {
    const char *possible_location = possible_locations[i];
    if (is_usable_library(possible_location, desired_architecture)) {
      return i;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<find_xlib_by_arch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1179 <find_xlib_by_arch+0x69>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <is_usable_library@plt>
cmp    $0x0,%rax
je     1166 <find_xlib_by_arch+0x56>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1180 <find_xlib_by_arch+0x70>
jmp    116b <find_xlib_by_arch+0x5b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1129 <find_xlib_by_arch+0x19>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_xlib_by_arch>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%r14d
test   %esi,%esi
jle    114f <find_xlib_by_arch+0x3f>
mov    %edx,%r15d
mov    %rdi,%r12
mov    %esi,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    (%r12,%rbp,8),%rdi
mov    %r15d,%esi
call   1030 <is_usable_library@plt>
test   %rax,%rax
jne    114c <find_xlib_by_arch+0x3c>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1130 <find_xlib_by_arch+0x20>
jmp    114f <find_xlib_by_arch+0x3f>
mov    %ebp,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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