#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*/ sscanf(char *, char *, unsigned int *);
int strcspn(char *, char *);
char *strstr(char *, char *);
int read_a_int_value(char *buf, char *key, unsigned int *ret, int type) {
  int k;
  char *tmp;
  if ((tmp = strstr(buf, key)) != NULL) {
    if (type == 0) {
      tmp = buf;
    }
    k = strcspn(tmp, "0123456789");
    sscanf(tmp + k, "%d", ret);
    return 1;
  } else
    return 0;
}


x86 assembly (clang, -O0):
<read_a_int_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11ae <read_a_int_value+0x7e>
cmpl   $0x0,-0x24(%rbp)
jne    1174 <read_a_int_value+0x44>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1030 <strcspn@plt>
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rdx
lea    0xe6e(%rip),%rsi
call   1040 <sscanf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11b5 <read_a_int_value+0x85>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_a_int_value>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rdi,%rbp
call   1050 <strstr@plt>
test   %rax,%rax
je     117f <read_a_int_value+0x4f>
mov    %rax,%rbx
test   %r15d,%r15d
cmove  %rbp,%rbx
lea    0xea5(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcspn@plt>
movslq %eax,%rdi
add    %rbx,%rdi
lea    0xe9b(%rip),%rsi
mov    %r14,%rdx
call   1040 <sscanf@plt>
mov    $0x1,%eax
jmp    1181 <read_a_int_value+0x51>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"0123456789\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @read_a_int_value(i8* %0, i8* nocapture %1, i32* %2, i32 %3) {
%5 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %14, label %7
7: ; preds = %4
%8 = icmp eq i32 %3, 0
%9 = select i1 %8, i8* %0, i8* %5
%10 = tail call i32 @strcspn(i8* %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = tail call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %14
14: ; preds = %4, %7
%15 = phi i32 [ 1, %7 ], [ 0, %4 ]
ret i32 %15
}