#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 */
struct keyval {
  int dummy;
};

/* Variables and functions */
char *keyvals_get_val(struct keyval const *, char const *);
int str_to_int(char const *, long *);
int comments_get_int(const struct keyval *comments, const char *key) {
  const char *val;
  long int ival;
  val = keyvals_get_val(comments, key);
  if (val == NULL)
    return -1;
  while (*val && !(*val >= '0' && *val <= '9'))
    val++;
  if (str_to_int(val, &ival) == -1)
    return -1;
  return ival;
}


x86 assembly (clang, -O0):
<comments_get_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <keyvals_get_val@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1158 <comments_get_int+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e9 <comments_get_int+0xc9>
jmp    115d <comments_get_int+0x3d>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     119f <comments_get_int+0x7f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x2a(%rbp)
jl     1197 <comments_get_int+0x77>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
xor    $0xff,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11af <comments_get_int+0x8f>
jmp    11c0 <comments_get_int+0xa0>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115d <comments_get_int+0x3d>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <str_to_int@plt>
cmp    $0xffffffff,%eax
jne    11e2 <comments_get_int+0xc2>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e9 <comments_get_int+0xc9>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<comments_get_int>:
push   %rbx
sub    $0x10,%rsp
call   1040 <keyvals_get_val@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     116a <comments_get_int+0x4a>
add    $0xffffffffffffffff,%rax
nopl   0x0(%rax,%rax,1)
movzbl 0x1(%rax),%ecx
add    $0x1,%rax
test   %cl,%cl
je     1154 <comments_get_int+0x34>
add    $0xd0,%cl
cmp    $0x9,%cl
ja     1140 <comments_get_int+0x20>
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1030 <str_to_int@plt>
cmp    $0xffffffff,%eax
je     116a <comments_get_int+0x4a>
mov    0x8(%rsp),%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.keyval = type { i32 }
define i32 @comments_get_int(%struct.keyval* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.keyval*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store %struct.keyval* %0, %struct.keyval** %4
store i8* %1, i8** %5
%8 = load %struct.keyval*, %struct.keyval** %4
%9 = load i8*, i8** %5
%10 = call i8* @keyvals_get_val(%struct.keyval* %8, i8* %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %46
14: ; preds = %2
br label %15
15: ; preds = %35, %14
%16 = load i8*, i8** %6
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %15
%21 = load i8*, i8** %6
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp sge i32 %23, 48
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i8*, i8** %6
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp sle i32 %28, 57
br label %30
30: ; preds = %25, %20
%31 = phi i1 [ false, %20 ], [ %29, %25 ]
%32 = xor i1 %31, true
br label %33
33: ; preds = %30, %15
%34 = phi i1 [ false, %15 ], [ %32, %30 ]
br i1 %34, label %35, label %38
35: ; preds = %33
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %6
br label %15
38: ; preds = %33
%39 = load i8*, i8** %6
%40 = call i32 @str_to_int(i8* %39, i64* %7)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %43
42: ; preds = %38
store i32 -1, i32* %3
br label %46
43: ; preds = %38
%44 = load i64, i64* %7
%45 = trunc i64 %44 to i32
store i32 %45, i32* %3
br label %46
46: ; preds = %43, %42, %13
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
%struct.keyval = type { i32 }
define i32 @comments_get_int(%struct.keyval* %0, i8* %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = tail call i8* @keyvals_get_val(%struct.keyval* %0, i8* %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %21, label %7
7: ; preds = %2, %7
%8 = phi i8* [ %14, %7 ], [ %5, %2 ]
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
%11 = add i8 %9, -48
%12 = icmp ult i8 %11, 10
%13 = or i1 %10, %12
%14 = getelementptr inbounds i8, i8* %8, i64 1
br i1 %13, label %15, label %7
15: ; preds = %7
%16 = call i32 @str_to_int(i8* %8, i64* %3)
%17 = icmp eq i32 %16, -1
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i64, i64* %3
%20 = trunc i64 %19 to i32
br label %21
21: ; preds = %15, %2, %18
%22 = phi i32 [ %20, %18 ], [ -1, %2 ], [ -1, %15 ]
ret i32 %22
}