#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 *, float *);
char *strchr(char *, char);
char *strndup(char *, size_t);
int extract_perc(char *input, float *result) {
  char *bpos;
  char *epos;
  char *subs;
  size_t ipos;
  bpos = strchr(input, '\x5b');
  epos = strchr(input, '\x25');
  if (bpos != NULL && epos != NULL && epos > bpos) {
    ipos = (size_t)(epos - bpos);
    subs = strndup(bpos + 1, ipos - 1);
    sscanf(subs, "%f", result);
    return 0;
  } else {
    return -1;
  }
}


x86 assembly (clang, -O0):
<extract_perc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x5b,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x25,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d0 <extract_perc+0xa0>
cmpq   $0x0,-0x28(%rbp)
je     11d0 <extract_perc+0xa0>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    11d0 <extract_perc+0xa0>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    -0x38(%rbp),%rsi
sub    $0x1,%rsi
call   1040 <strndup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe41(%rip),%rsi
call   1050 <sscanf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d7 <extract_perc+0xa7>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_perc>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x5b,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x25,%esi
call   1030 <strchr@plt>
mov    $0xffffffff,%ecx
test   %rbx,%rbx
je     118f <extract_perc+0x5f>
test   %rax,%rax
je     118f <extract_perc+0x5f>
cmp    %rbx,%rax
jbe    118f <extract_perc+0x5f>
lea    0x1(%rbx),%rdi
not    %rbx
add    %rbx,%rax
mov    %rax,%rsi
call   1040 <strndup@plt>
lea    0xe7e(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1050 <sscanf@plt>
xor    %ecx,%ecx
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%f\00"
define i32 @extract_perc(i8* %0, float* %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 91)
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 37)
%5 = icmp ne i8* %3, null
%6 = icmp ne i8* %4, null
%7 = select i1 %5, i1 %6, i1 false
%8 = icmp ugt i8* %4, %3
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = ptrtoint i8* %4 to i64
%12 = ptrtoint i8* %3 to i64
%13 = getelementptr inbounds i8, i8* %3, i64 1
%14 = xor i64 %12, -1
%15 = add i64 %11, %14
%16 = tail call i8* @strndup(i8* %13, i64 %15)
%17 = tail call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float* %1)
br label %18
18: ; preds = %2, %10
%19 = phi i32 [ 0, %10 ], [ -1, %2 ]
ret i32 %19
}