#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 atoi(char *);
scalar_t__ isdigit(char);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ vis5d_get_ctx_numvars(int, int *);
int /*<<< orphan*/ vis5d_get_ctx_var_name(int, int, char *);
int varnum(int index, char *s) {
  if (isdigit(s[0])) {
    return atoi(s);
  } else {
    int var, numvars;
    vis5d_get_ctx_numvars(index, &numvars);
    for (var = 0; var < numvars; var++) {
      char name[20];
      vis5d_get_ctx_var_name(index, var, name);
      if (strcmp(name, s) == 0) {
        return var;
      }
    }
    return -1;
  }
}


x86 assembly (clang, -O0):
<varnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1186 <varnum+0x36>
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    11f0 <varnum+0xa0>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1040 <vis5d_get_ctx_numvars@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11e9 <varnum+0x99>
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
lea    -0x30(%rbp),%rdx
call   1060 <vis5d_get_ctx_var_name@plt>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11d6 <varnum+0x86>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f0 <varnum+0xa0>
jmp    11db <varnum+0x8b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1199 <varnum+0x49>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<varnum>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
mov    %edi,%r15d
movsbl (%rsi),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1183 <varnum+0x33>
mov    %rbx,%rdi
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <atoi@plt>
lea    0xc(%rsp),%rsi
mov    %r15d,%edi
call   1040 <vis5d_get_ctx_numvars@plt>
mov    $0xffffffff,%r14d
cmpl   $0x0,0xc(%rsp)
jle    11db <varnum+0x8b>
xor    %ebp,%ebp
lea    0x10(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15d,%edi
mov    %ebp,%esi
mov    %r12,%rdx
call   1060 <vis5d_get_ctx_var_name@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11d8 <varnum+0x88>
add    $0x1,%ebp
cmp    0xc(%rsp),%ebp
jl     11b0 <varnum+0x60>
jmp    11db <varnum+0x8b>
mov    %ebp,%r14d
mov    %r14d,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @varnum(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [20 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = call i64 @isdigit(i8 signext %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %3
br label %40
17: ; preds = %2
%18 = load i32, i32* %4
%19 = call i32 @vis5d_get_ctx_numvars(i32 %18, i32* %7)
store i32 0, i32* %6
br label %20
20: ; preds = %36, %17
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %39
24: ; preds = %20
%25 = load i32, i32* %4
%26 = load i32, i32* %6
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%28 = call i32 @vis5d_get_ctx_var_name(i32 %25, i32 %26, i8* %27)
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%30 = load i8*, i8** %5
%31 = call i64 @strcmp(i8* %29, i8* %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %24
%34 = load i32, i32* %6
store i32 %34, i32* %3
br label %40
35: ; preds = %24
br label %36
36: ; preds = %35
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %20
39: ; preds = %20
store i32 -1, i32* %3
br label %40
40: ; preds = %39, %33, %14
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
define i32 @varnum(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca [20 x i8]
%5 = load i8, i8* %1
%6 = tail call i64 @isdigit(i8 signext %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @atoi(i8* %1)
br label %27
10: ; preds = %2
%11 = bitcast i32* %3 to i8*
%12 = call i32 @vis5d_get_ctx_numvars(i32 %0, i32* %3)
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %10, %21
%17 = phi i32 [ %22, %21 ], [ 0, %10 ]
%18 = call i32 @vis5d_get_ctx_var_name(i32 %0, i32 %17, i8* %13)
%19 = call i64 @strcmp(i8* %13, i8* %1)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %16
%22 = add nuw nsw i32 %17, 1
%23 = load i32, i32* %3
%24 = icmp slt i32 %22, %23
br i1 %24, label %16, label %25
25: ; preds = %16, %21, %10
%26 = phi i32 [ -1, %10 ], [ -1, %21 ], [ %17, %16 ]
br label %27
27: ; preds = %25, %8
%28 = phi i32 [ %9, %8 ], [ %26, %25 ]
ret i32 %28
}