#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__ stringbeg(char *, char *);
unsigned short stringmatch(char *s, char a[][20], unsigned short n) {
  unsigned short i = 0;
  while (i < n) {
    if (stringbeg(s, a[i]))
      return i + 1;
    i++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<stringmatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dx,%ax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %ax,-0x1a(%rbp)
movw   $0x0,-0x1c(%rbp)
movzwl -0x1c(%rbp),%eax
movzwl -0x1a(%rbp),%ecx
cmp    %ecx,%eax
jge    1180 <stringmatch+0x70>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movzwl -0x1c(%rbp),%eax
imul   $0x14,%rax,%rax
add    %rax,%rsi
call   1030 <stringbeg@plt>
cmp    $0x0,%rax
je     116f <stringmatch+0x5f>
movzwl -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %ax,-0x2(%rbp)
jmp    1186 <stringmatch+0x76>
mov    -0x1c(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x1c(%rbp)
jmp    112d <stringmatch+0x1d>
movw   $0x0,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringmatch>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
je     114d <stringmatch+0x3d>
mov    %rsi,%rbx
mov    %rdi,%r15
movzwl %dx,%r12d
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <stringbeg@plt>
test   %rax,%rax
jne    1152 <stringmatch+0x42>
add    $0x1,%r14
add    $0x14,%rbx
cmp    %r14,%r12
jne    1130 <stringmatch+0x20>
xor    %r14d,%r14d
jmp    1156 <stringmatch+0x46>
add    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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