#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 INT_MAX;
int strlen(char *);
char *strstr(char const *, char *);
int strtol(char *, int /*<<< orphan*/ *, int);
int matchEventNum(const char *line) {
  char *line2 = strstr(line, "event") + strlen("event");
  int event = strtol(line2, NULL, 10);
  if (event >= INT_MAX || event < 0) {
    return -1;
  }
  return (int)event;
}


x86 assembly (clang, -O0):
<matchEventNum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x28(%rbp)
lea    0xea9(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e5d(%rip),%rcx
cmp    (%rcx),%eax
jge    119d <matchEventNum+0x6d>
cmpl   $0x0,-0x1c(%rbp)
jge    11a9 <matchEventNum+0x79>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <matchEventNum+0x7f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matchEventNum>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%r14
mov    %r14,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    0x2e81(%rip),%rcx
cmp    (%rcx),%eax
mov    $0xffffffff,%edx
mov    %eax,%ecx
cmovge %edx,%ecx
test   %eax,%eax
cmovs  %edx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"event\00"
@INT_MAX = global i32 0
define i32 @matchEventNum(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i8* @strstr(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = call i32 @strtol(i8* %11, i32* null, i32 10)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = load i32, i32* @INT_MAX
%15 = icmp sge i32 %13, %14
br i1 %15, label %19, label %16
16: ; preds = %1
%17 = load i32, i32* %5
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16, %1
store i32 -1, i32* %2
br label %22
20: ; preds = %16
%21 = load i32, i32* %5
store i32 %21, i32* %2
br label %22
22: ; preds = %20, %19
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [6 x i8] c"event\00"
@INT_MAX = global i32 0
define i32 @matchEventNum(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %2, i64 %4
%6 = tail call i32 @strtol(i8* nocapture %5, i32* null, i32 10)
%7 = load i32, i32* @INT_MAX
%8 = icmp sge i32 %6, %7
%9 = icmp slt i32 %6, 0
%10 = or i1 %9, %8
%11 = select i1 %10, i32 -1, i32 %6
ret i32 %11
}