#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 */
int keyring_search();
int keydb_search2(int *hdfound, int *hdcurrent, int *a) {
  int rc = -1;
  while (rc == -1) {
    if (*a == 1)
      rc = keyring_search();
    if (rc == -1)
      *hdcurrent++;
    if (!rc)
      *hdfound = *hdcurrent;
  }
  return rc;
}


x86 assembly (clang, -O0):
<keydb_search2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    117d <keydb_search2+0x6d>
mov    -0x18(%rbp),%rax
cmpl   $0x1,(%rax)
jne    114c <keydb_search2+0x3c>
mov    $0x0,%al
call   1030 <keyring_search@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1162 <keydb_search2+0x52>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1178 <keydb_search2+0x68>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    112b <keydb_search2+0x1b>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<keydb_search2>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
jmp    1124 <keydb_search2+0x14>
add    $0x4,%rbx
cmpl   $0x1,(%r15)
jne    1120 <keydb_search2+0x10>
xor    %eax,%eax
call   1030 <keyring_search@plt>
cmp    $0xffffffff,%eax
je     1120 <keydb_search2+0x10>
test   %eax,%eax
jne    113f <keydb_search2+0x2f>
mov    (%rbx),%ecx
mov    %ecx,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @keydb_search2(i32* nocapture writeonly %0, i32* nocapture %1, i32* nocapture %2) {
br label %4
4: ; preds = %12, %3
%5 = phi i32* [ %1, %3 ], [ %13, %12 ]
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = tail call i32 (...) @keyring_search()
switch i32 %9, label %14 [
i32 -1, label %12
i32 0, label %10
]
10: ; preds = %8
%11 = load i32, i32* %5
store i32 %11, i32* %0
br label %14
12: ; preds = %4, %8
%13 = getelementptr inbounds i32, i32* %5, i64 1
br label %4
14: ; preds = %8, %10
ret i32 %9
}