#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__ strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, scalar_t__);
int strspn(char *, char *);
int GetMode(char *line) {
  int offset = 0;
  if ((strlen(line) == strlen("modeX")) &&
      !strncmp(&line[offset], "mode", strlen("mode"))) {
    offset += strlen("mode");
    if (strspn(&line[offset], "0123456789") == 1) {
      return (int)(0 + line[offset] - '0');
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<GetMode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
lea    0xea9(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jne    11fb <GetMode+0xcb>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
lea    0xe84(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rdx
lea    0xe71(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11fb <GetMode+0xcb>
lea    0xe5c(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
lea    0xe3d(%rip),%rsi
call   1050 <strspn@plt>
cmp    $0x1,%eax
jne    11f6 <GetMode+0xc6>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0x0,%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    1202 <GetMode+0xd2>
jmp    11fb <GetMode+0xcb>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetMode>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    $0xffffffff,%ebp
cmp    $0x5,%rax
jne    117c <GetMode+0x4c>
lea    0xeb3(%rip),%rsi
mov    $0x4,%edx
mov    %rbx,%rdi
call   1030 <strncmp@plt>
test   %eax,%eax
jne    117c <GetMode+0x4c>
add    $0x4,%rbx
lea    0xe9c(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strspn@plt>
cmp    $0x1,%eax
jne    117c <GetMode+0x4c>
movsbl (%rbx),%ebp
add    $0xffffffd0,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"modeX\00"
@.str.1 = [5 x i8] c"mode\00"
@.str.2 = [11 x i8] c"0123456789\00"
define i32 @GetMode(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%5 = load i8*, i8** %3
%6 = call i64 @strlen(i8* %5)
%7 = call i64 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %39
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = call i64 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @strncmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %39, label %17
17: ; preds = %9
%18 = call i64 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = add nsw i64 %20, %18
%22 = trunc i64 %21 to i32
store i32 %22, i32* %4
%23 = load i8*, i8** %3
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = call i32 @strspn(i8* %26, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %38
29: ; preds = %17
%30 = load i8*, i8** %3
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = add nsw i32 0, %35
%37 = sub nsw i32 %36, 48
store i32 %37, i32* %2
br label %40
38: ; preds = %17
br label %39
39: ; preds = %38, %9, %1
store i32 -1, i32* %2
br label %40
40: ; preds = %39, %29
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"mode\00"
@.str.2 = [11 x i8] c"0123456789\00"
define i32 @GetMode(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp eq i64 %2, 5
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = tail call i32 @strncmp(i8* dereferenceable(1) %0, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %0, i64 4
%9 = tail call i32 @strspn(i8* %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = load i8, i8* %8
%13 = sext i8 %12 to i32
%14 = add nsw i32 %13, -48
br label %15
15: ; preds = %1, %4, %7, %11
%16 = phi i32 [ %14, %11 ], [ -1, %7 ], [ -1, %4 ], [ -1, %1 ]
ret i32 %16
}