#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 unsigned int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
unsigned int UINT8_MAX;
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *, char const *);
scalar_t__ strcmp(int /*<<< orphan*/, char const *);
int /*<<< orphan*/ vm_opcode_to_string(unsigned int);
uint8_t vm_string_to_opcode(const char *mnemonic) {
  unsigned i;
  for (i = 0; i < UINT8_MAX; i++) {
    if (strcmp(vm_opcode_to_string(i), mnemonic) == 0) {
      return i;
    }
  }
  errx(EXIT_FAILURE, "unrecognised mnemonic '%s' encountered", mnemonic);
}


x86 assembly (clang, -O0):
<vm_string_to_opcode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e8b(%rip),%rcx
cmp    (%rcx),%eax
jae    1190 <vm_string_to_opcode+0x60>
mov    -0x14(%rbp),%edi
call   1050 <vm_opcode_to_string@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    117d <vm_string_to_opcode+0x4d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a9 <vm_string_to_opcode+0x79>
jmp    1182 <vm_string_to_opcode+0x52>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1143 <vm_string_to_opcode+0x13>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe5c(%rip),%rsi
call   1030 <errx@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vm_string_to_opcode>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2e99(%rip),%r15
cmpl   $0x0,(%r15)
je     1170 <vm_string_to_opcode+0x40>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1050 <vm_opcode_to_string@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     118a <vm_string_to_opcode+0x5a>
add    $0x1,%ebx
cmp    (%r15),%ebx
jb     1150 <vm_string_to_opcode+0x20>
jmp    1172 <vm_string_to_opcode+0x42>
xor    %ebx,%ebx
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
mov    %r14,%rdx
call   1030 <errx@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@UINT8_MAX = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [39 x i8] c"unrecognised mnemonic '%s' encountered\00"
define i32 @vm_string_to_opcode(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
br label %5
5: ; preds = %18, %1
%6 = load i32, i32* %4
%7 = load i32, i32* @UINT8_MAX
%8 = icmp ult i32 %6, %7
br i1 %8, label %9, label %21
9: ; preds = %5
%10 = load i32, i32* %4
%11 = call i32 @vm_opcode_to_string(i32 %10)
%12 = load i8*, i8** %3
%13 = call i64 @strcmp(i32 %11, i8* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = load i32, i32* %4
store i32 %16, i32* %2
br label %25
17: ; preds = %9
br label %18
18: ; preds = %17
%19 = load i32, i32* %4
%20 = add i32 %19, 1
store i32 %20, i32* %4
br label %5
21: ; preds = %5
%22 = load i32, i32* @EXIT_FAILURE
%23 = load i8*, i8** %3
%24 = call i32 @errx(i32 %22, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %21, %15
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@UINT8_MAX = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [39 x i8] c"unrecognised mnemonic '%s' encountered\00"
define i32 @vm_string_to_opcode(i8* %0) {
%2 = load i32, i32* @UINT8_MAX
%3 = icmp eq i32 %2, 0
br i1 %3, label %13, label %4
4: ; preds = %1, %9
%5 = phi i32 [ %10, %9 ], [ 0, %1 ]
%6 = tail call i32 @vm_opcode_to_string(i32 %5)
%7 = tail call i64 @strcmp(i32 %6, i8* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %4
%10 = add nuw i32 %5, 1
%11 = load i32, i32* @UINT8_MAX
%12 = icmp ult i32 %10, %11
br i1 %12, label %4, label %13
13: ; preds = %9, %1
%14 = phi i32 [ 0, %1 ], [ %10, %9 ]
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @errx(i32 %15, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %17
17: ; preds = %4, %13
%18 = phi i32 [ %14, %13 ], [ %5, %4 ]
ret i32 %18
}