#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 */
scalar_t__ isdigit(char const);
const char *knh_vprintf_parseindex(const char *p, int *index) {
  const char *ptr = p + 1;
  if (ptr[0] == '{' && isdigit(ptr[1]) && ptr[2] == '}') {
    *index = ptr[1] - '0';
    ptr += 3;
    return ptr;
  }
  return p;
}


x86 assembly (clang, -O0):
<knh_vprintf_parseindex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7b,%eax
jne    118e <knh_vprintf_parseindex+0x7e>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     118e <knh_vprintf_parseindex+0x7e>
mov    -0x20(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x7d,%eax
jne    118e <knh_vprintf_parseindex+0x7e>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%ecx
sub    $0x30,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1196 <knh_vprintf_parseindex+0x86>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<knh_vprintf_parseindex>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
cmpb   $0x7b,0x1(%rdi)
jne    1142 <knh_vprintf_parseindex+0x32>
mov    %rsi,%r14
movsbl 0x2(%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1142 <knh_vprintf_parseindex+0x32>
cmpb   $0x7d,0x3(%rbx)
jne    1142 <knh_vprintf_parseindex+0x32>
movsbl 0x2(%rbx),%eax
add    $0xffffffd0,%eax
mov    %eax,(%r14)
add    $0x4,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @knh_vprintf_parseindex(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
%7 = load i8*, i8** %4
%8 = getelementptr inbounds i8, i8* %7, i64 1
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 123
br i1 %13, label %14, label %36
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %16
%18 = call i64 @isdigit(i8 signext %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %36
20: ; preds = %14
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 2
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 125
br i1 %25, label %26, label %36
26: ; preds = %20
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = sub nsw i32 %30, 48
%32 = load i32*, i32** %5
store i32 %31, i32* %32
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 3
store i8* %34, i8** %6
%35 = load i8*, i8** %6
store i8* %35, i8** %3
br label %38
36: ; preds = %20, %14, %2
%37 = load i8*, i8** %4
store i8* %37, i8** %3
br label %38
38: ; preds = %36, %26
%39 = load i8*, i8** %3
ret i8* %39
}

LLVM IR (-O2):
define i8* @knh_vprintf_parseindex(i8* %0, i32* nocapture writeonly %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 1
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 123
br i1 %5, label %6, label %20
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %0, i64 2
%8 = load i8, i8* %7
%9 = tail call i64 @isdigit(i8 signext %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %6
%12 = getelementptr inbounds i8, i8* %0, i64 3
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 125
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i8, i8* %7
%17 = sext i8 %16 to i32
%18 = add nsw i32 %17, -48
store i32 %18, i32* %1
%19 = getelementptr inbounds i8, i8* %0, i64 4
br label %20
20: ; preds = %2, %6, %11, %15
%21 = phi i8* [ %19, %15 ], [ %0, %11 ], [ %0, %6 ], [ %0, %2 ]
ret i8* %21
}