#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__ strncmp(char const *, char const *, int);
int d_getnumbyname(const char **arr, int arr_size, const char *str) {
  int i;
  for (i = 0; i < arr_size; i++) {
    if (strncmp(arr[i], str, 3) == 0) {
      return i + 1;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<d_getnumbyname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117b <d_getnumbyname+0x6b>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1168 <d_getnumbyname+0x58>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1182 <d_getnumbyname+0x72>
jmp    116d <d_getnumbyname+0x5d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112a <d_getnumbyname+0x1a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d_getnumbyname>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%r14d
test   %esi,%esi
jle    1157 <d_getnumbyname+0x47>
mov    %rdx,%r15
mov    %rdi,%r12
mov    %esi,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r12,%rbx,8),%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1151 <d_getnumbyname+0x41>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1130 <d_getnumbyname+0x20>
jmp    1157 <d_getnumbyname+0x47>
add    $0x1,%ebx
mov    %ebx,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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