#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 /*<<< orphan*/ sprintf(char *, char *, char const *);
int sscanf(char const *, char *, int *);
char *strstr(char const *, char const *);
int str2enum(const char *str, const char *comment, int *val) {
  const char *p;
  char s[32];
  for (p = comment;; p++) {
    if (!(p = strstr(p, str)))
      break;
    if (*(p - 1) != ':')
      continue;
    for (p -= 2; '0' <= *p && *p <= '9'; p--)
      ;
    return sscanf(p + 1, "%d", val) == 1;
  }
  sprintf(s, "%30.30s:", str);
  if ((p = strstr(comment, s))) {
    return sscanf(p, "%d", val) == 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<str2enum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    116c <str2enum+0x3c>
jmp    1219 <str2enum+0xe9>
mov    -0x28(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x3a,%eax
je     1182 <str2enum+0x52>
jmp    1208 <str2enum+0xd8>
mov    -0x28(%rbp),%rax
add    $0xfffffffffffffffe,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%edx
xor    %eax,%eax
mov    $0x30,%ecx
cmp    %edx,%ecx
mov    %al,-0x51(%rbp)
jg     11b7 <str2enum+0x87>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    11c7 <str2enum+0x97>
jmp    11dd <str2enum+0xad>
jmp    11cc <str2enum+0x9c>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    118e <str2enum+0x5e>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rdx
lea    0xe10(%rip),%rsi
call   1030 <sscanf@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1276 <str2enum+0x146>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    114c <str2enum+0x1c>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xddb(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     126f <str2enum+0x13f>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xda9(%rip),%rsi
call   1030 <sscanf@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1276 <str2enum+0x146>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2enum>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,%rdi
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1182 <str2enum+0x52>
cmpb   $0x3a,-0x1(%rax)
je     1170 <str2enum+0x40>
add    $0x1,%rax
mov    %rax,%rdi
jmp    1150 <str2enum+0x20>
nopl   0x0(%rax)
movzbl -0x2(%rax),%ecx
add    $0xd0,%cl
add    $0xffffffffffffffff,%rax
cmp    $0xa,%cl
jb     1170 <str2enum+0x40>
jmp    11a7 <str2enum+0x77>
lea    0xe7a(%rip),%rsi
mov    %rsp,%r12
mov    %r12,%rdi
mov    %rbx,%rdx
call   1040 <sprintf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     11c5 <str2enum+0x95>
lea    0xe52(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1030 <sscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
sete   %al
jmp    11c7 <str2enum+0x97>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%30.30s:\00"
define i32 @str2enum(i8* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca [32 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%10 = load i8*, i8** %6
store i8* %10, i8** %8
br label %11
11: ; preds = %50, %3
%12 = load i8*, i8** %8
%13 = load i8*, i8** %5
%14 = call i8* @strstr(i8* %12, i8* %13)
store i8* %14, i8** %8
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %11
br label %53
17: ; preds = %11
%18 = load i8*, i8** %8
%19 = getelementptr inbounds i8, i8* %18, i64 -1
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 58
br i1 %22, label %23, label %24
23: ; preds = %17
br label %50
24: ; preds = %17
%25 = load i8*, i8** %8
%26 = getelementptr inbounds i8, i8* %25, i64 -2
store i8* %26, i8** %8
br label %27
27: ; preds = %40, %24
%28 = load i8*, i8** %8
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp sle i32 48, %30
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i8*, i8** %8
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp sle i32 %35, 57
br label %37
37: ; preds = %32, %27
%38 = phi i1 [ false, %27 ], [ %36, %32 ]
br i1 %38, label %39, label %43
39: ; preds = %37
br label %40
40: ; preds = %39
%41 = load i8*, i8** %8
%42 = getelementptr inbounds i8, i8* %41, i32 -1
store i8* %42, i8** %8
br label %27
43: ; preds = %37
%44 = load i8*, i8** %8
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = load i32*, i32** %7
%47 = call i32 @sscanf(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %46)
%48 = icmp eq i32 %47, 1
%49 = zext i1 %48 to i32
store i32 %49, i32* %4
br label %68
50: ; preds = %23
%51 = load i8*, i8** %8
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %8
br label %11
53: ; preds = %16
%54 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%55 = load i8*, i8** %5
%56 = call i32 @sprintf(i8* %54, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %55)
%57 = load i8*, i8** %6
%58 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%59 = call i8* @strstr(i8* %57, i8* %58)
store i8* %59, i8** %8
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %67
61: ; preds = %53
%62 = load i8*, i8** %8
%63 = load i32*, i32** %7
%64 = call i32 @sscanf(i8* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %63)
%65 = icmp eq i32 %64, 1
%66 = zext i1 %65 to i32
store i32 %66, i32* %4
br label %68
67: ; preds = %53
store i32 0, i32* %4
br label %68
68: ; preds = %67, %61, %43
%69 = load i32, i32* %4
ret i32 %69
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%30.30s:\00"
define i32 @str2enum(i8* %0, i8* %1, i32* %2) {
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%6 = tail call i8* @strstr(i8* dereferenceable(1) %1, i8* dereferenceable(1) %0)
%7 = icmp eq i8* %6, null
br i1 %7, label %27, label %8
8: ; preds = %3, %23
%9 = phi i8* [ %25, %23 ], [ %6, %3 ]
%10 = getelementptr inbounds i8, i8* %9, i64 -1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 58
br i1 %12, label %13, label %23
13: ; preds = %8
%14 = getelementptr inbounds i8, i8* %9, i64 -2
br label %15
15: ; preds = %15, %13
%16 = phi i8* [ %14, %13 ], [ %20, %15 ]
%17 = load i8, i8* %16
%18 = add i8 %17, -48
%19 = icmp ult i8 %18, 10
%20 = getelementptr inbounds i8, i8* %16, i64 -1
br i1 %19, label %15, label %21
21: ; preds = %15
%22 = getelementptr inbounds i8, i8* %16, i64 1
br label %31
23: ; preds = %8
%24 = getelementptr inbounds i8, i8* %9, i64 1
%25 = tail call i8* @strstr(i8* dereferenceable(1) %24, i8* dereferenceable(1) %0)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %8
27: ; preds = %23, %3
%28 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%29 = call i8* @strstr(i8* dereferenceable(1) %1, i8* %5)
%30 = icmp eq i8* %29, null
br i1 %30, label %36, label %31
31: ; preds = %27, %21
%32 = phi i8* [ %22, %21 ], [ %29, %27 ]
%33 = tail call i32 @sscanf(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%34 = icmp eq i32 %33, 1
%35 = zext i1 %34 to i32
br label %36
36: ; preds = %31, %27
%37 = phi i32 [ 0, %27 ], [ %35, %31 ]
ret i32 %37
}