#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__ strcmp(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
char *strsep(char **, char *);
int get_format_index(const char *format_str, const char *label) {
  char fmt[1024];
  char delim[] = ":";
  char *cur, *tok;
  int idx, i;
  strcpy(fmt, format_str);
  idx = -1;
  i = 0;
  cur = fmt;
  while ((tok = strsep(&cur, delim)) != NULL) {
    if (strcmp(tok, label) == 0) {
      idx = i;
      break;
    }
    i++;
  }
  return idx;
}


x86 assembly (clang, -O0):
<get_format_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeb6(%rip),%ax
mov    %ax,-0x412(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0xffffffff,-0x42c(%rbp)
ff ff ff
movl   $0x0,-0x430(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x420(%rbp)
lea    -0x412(%rbp),%rsi
lea    -0x420(%rbp),%rdi
call   1050 <strsep@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
je     11e6 <get_format_index+0xb6>
mov    -0x428(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11d2 <get_format_index+0xa2>
mov    -0x430(%rbp),%eax
mov    %eax,-0x42c(%rbp)
jmp    11e6 <get_format_index+0xb6>
mov    -0x430(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x430(%rbp)
jmp    1183 <get_format_index+0x53>
mov    -0x42c(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_format_index>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
mov    %rsi,%rbx
mov    %rdi,%rsi
movw   $0x3a,0x6(%rsp)
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    %rbp,0x8(%rsp)
lea    0x8(%rsp),%rdi
lea    0x6(%rsp),%rsi
call   1050 <strsep@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     11b8 <get_format_index+0x88>
xor    %ebp,%ebp
lea    0x8(%rsp),%r15
lea    0x6(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11b5 <get_format_index+0x85>
add    $0x1,%ebp
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <strsep@plt>
test   %rax,%rax
jne    1190 <get_format_index+0x60>
jmp    11b8 <get_format_index+0x88>
mov    %ebp,%r14d
mov    %r14d,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.get_format_index.delim = [2 x i8] c":\00"
define i32 @get_format_index(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [1024 x i8]
%6 = alloca [2 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = bitcast [2 x i8]* %6 to i8*
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%13 = load i8*, i8** %3
%14 = call i32 @strcpy(i8* %12, i8* %13)
store i32 -1, i32* %9
store i32 0, i32* %10
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
store i8* %15, i8** %7
br label %16
16: ; preds = %27, %2
%17 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%18 = call i8* @strsep(i8** %7, i8* %17)
store i8* %18, i8** %8
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = load i8*, i8** %8
%22 = load i8*, i8** %4
%23 = call i64 @strcmp(i8* %21, i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = load i32, i32* %10
store i32 %26, i32* %9
br label %30
27: ; preds = %20
%28 = load i32, i32* %10
%29 = add nsw i32 %28, 1
store i32 %29, i32* %10
br label %16
30: ; preds = %25, %16
%31 = load i32, i32* %9
ret i32 %31
}

LLVM IR (-O2):
define i32 @get_format_index(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = alloca i16
%5 = alloca i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = bitcast i16* %4 to i8*
store i16 58, i16* %4
%8 = bitcast i8** %5 to i8*
%9 = call i32 @strcpy(i8* %6, i8* %0)
store i8* %6, i8** %5
%10 = call i8* @strsep(i8** %5, i8* %7)
%11 = icmp eq i8* %10, null
br i1 %11, label %21, label %12
12: ; preds = %2, %17
%13 = phi i8* [ %19, %17 ], [ %10, %2 ]
%14 = phi i32 [ %18, %17 ], [ 0, %2 ]
%15 = call i64 @strcmp(i8* %13, i8* %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = add nuw nsw i32 %14, 1
%19 = call i8* @strsep(i8** %5, i8* %7)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %12
21: ; preds = %17, %12, %2
%22 = phi i32 [ -1, %2 ], [ %14, %12 ], [ -1, %17 ]
ret i32 %22
}