#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 sscanf(char *, char *, int *);
int /*<<< orphan*/ *strchr(char *, char);
int dvbcfg_parse_int(char **text, char *tokens) {
  char *start = *text;
  char *stop = *text;
  int value;
  while (*stop != '\0') {
    if (strchr(tokens, *stop) != NULL) {
      *stop = '\0';
      stop++;
      break;
    }
    stop++;
  }
  if (sscanf(start, "%i", &value) == 1) {
    *text = stop;
    return value;
  }
  *text = NULL;
  return -1;
}


x86 assembly (clang, -O0):
<dvbcfg_parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1199 <dvbcfg_parse_int+0x79>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
movsbl (%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     1188 <dvbcfg_parse_int+0x68>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1199 <dvbcfg_parse_int+0x79>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1146 <dvbcfg_parse_int+0x26>
mov    -0x20(%rbp),%rdi
lea    0xe5c(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    11cc <dvbcfg_parse_int+0xac>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11de <dvbcfg_parse_int+0xbe>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dvbcfg_parse_int>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%r15
mov    (%r15),%al
mov    %r15,%rbx
test   %al,%al
je     1165 <dvbcfg_parse_int+0x45>
mov    %rsi,%r12
lea    0x1(%r15),%rbx
nop
movsbl %al,%esi
mov    %r12,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1161 <dvbcfg_parse_int+0x41>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1140 <dvbcfg_parse_int+0x20>
add    $0xffffffffffffffff,%rbx
jmp    1165 <dvbcfg_parse_int+0x45>
movb   $0x0,-0x1(%rbx)
lea    0xe94(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %r15,%rdi
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    1187 <dvbcfg_parse_int+0x67>
mov    %rbx,(%r14)
mov    0x4(%rsp),%eax
jmp    1193 <dvbcfg_parse_int+0x73>
movq   $0x0,(%r14)
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
define i32 @dvbcfg_parse_int(i8** nocapture %0, i8* %1) {
%3 = alloca i32
%4 = load i8*, i8** %0
%5 = bitcast i32* %3 to i8*
%6 = load i8, i8* %4
%7 = icmp eq i8 %6, 0
br i1 %7, label %19, label %8
8: ; preds = %2, %15
%9 = phi i8 [ %17, %15 ], [ %6, %2 ]
%10 = phi i8* [ %16, %15 ], [ %4, %2 ]
%11 = tail call i32* @strchr(i8* %1, i8 signext %9)
%12 = icmp eq i32* %11, null
br i1 %12, label %15, label %13
13: ; preds = %8
store i8 0, i8* %10
%14 = getelementptr inbounds i8, i8* %10, i64 1
br label %19
15: ; preds = %8
%16 = getelementptr inbounds i8, i8* %10, i64 1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %8
19: ; preds = %15, %2, %13
%20 = phi i8* [ %14, %13 ], [ %4, %2 ], [ %16, %15 ]
%21 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %25
23: ; preds = %19
store i8* %20, i8** %0
%24 = load i32, i32* %3
br label %26
25: ; preds = %19
store i8* null, i8** %0
br label %26
26: ; preds = %25, %23
%27 = phi i32 [ %24, %23 ], [ -1, %25 ]
ret i32 %27
}