#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 watched_key {
  int dummy;
};
struct rlite {
  int dummy;
};

/* Variables and functions */
int rl_key_sha_check_version(struct rlite *, struct watched_key *);
int rl_check_watched_keys(struct rlite *db, int watched_count,
                          struct watched_key **keys) {
  int i, retval = 0;
  for (i = 0; i < watched_count; i++) {
    retval = rl_key_sha_check_version(db, keys[i]);
    if (0 != retval)
      goto cleanup;
    ;
  }
cleanup:
  return retval;
}


x86 assembly (clang, -O0):
<rl_check_watched_keys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1178 <rl_check_watched_keys+0x68>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <rl_key_sha_check_version@plt>
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%eax
je     1165 <rl_check_watched_keys+0x55>
jmp    117d <rl_check_watched_keys+0x6d>
jmp    116a <rl_check_watched_keys+0x5a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1131 <rl_check_watched_keys+0x21>
jmp    117d <rl_check_watched_keys+0x6d>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rl_check_watched_keys>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1149 <rl_check_watched_keys+0x39>
mov    %rdx,%r14
mov    %rdi,%r15
mov    %esi,%r12d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rsi
mov    %r15,%rdi
call   1030 <rl_key_sha_check_version@plt>
test   %eax,%eax
jne    114b <rl_check_watched_keys+0x3b>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <rl_check_watched_keys+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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