#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 atoi(char const *);
int strlen(char const *);
scalar_t__ strncmp(char const *, char *, int);
int fetch_srid(const char *line) {
  int len = strlen(line);
  int i;
  int cnt = 0;
  for (i = len - 1; i > 1; i--) {
    if (line[i] == ']')
      cnt++;
    if (cnt == 3) {
      if (strncmp(line + i, "],AUTHORITY[\"EPSG\",\"", 20) == 0)
        return atoi(line + i + 20);
      return -1;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<fetch_srid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jle    11eb <fetch_srid+0xbb>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5d,%eax
jne    1180 <fetch_srid+0x50>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jne    11d8 <fetch_srid+0xa8>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
lea    0xe64(%rip),%rsi
mov    $0x14,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11cc <fetch_srid+0x9c>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
add    $0x14,%rdi
call   1050 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    11f2 <fetch_srid+0xc2>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f2 <fetch_srid+0xc2>
jmp    11dd <fetch_srid+0xad>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1158 <fetch_srid+0x28>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fetch_srid>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%ecx
add    $0xffffffff,%eax
lea    (%rax,%r14,1),%rbx
add    $0x15,%rbx
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
cmp    $0x3,%ecx
jl     1189 <fetch_srid+0x59>
xor    %edx,%edx
cmpb   $0x5d,-0x1(%r14,%rcx,1)
sete   %dl
add    %edx,%eax
add    $0xffffffffffffffff,%rbx
add    $0xffffffffffffffff,%rcx
cmp    $0x3,%eax
jne    1150 <fetch_srid+0x20>
lea    -0x14(%rbx),%rdi
lea    0xe86(%rip),%rsi
mov    $0x14,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1196 <fetch_srid+0x66>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <atoi@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"],AUTHORITY[\22EPSG\22,\22\00"
define i32 @fetch_srid(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %4
store i32 0, i32* %6
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 1
store i32 %10, i32* %5
br label %11
11: ; preds = %44, %1
%12 = load i32, i32* %5
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %47
14: ; preds = %11
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 93
br i1 %21, label %22, label %25
22: ; preds = %14
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %25
25: ; preds = %22, %14
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, 3
br i1 %27, label %28, label %43
28: ; preds = %25
%29 = load i8*, i8** %3
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = call i64 @strncmp(i8* %32, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 20)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %28
%36 = load i8*, i8** %3
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = getelementptr inbounds i8, i8* %39, i64 20
%41 = call i32 @atoi(i8* %40)
store i32 %41, i32* %2
br label %48
42: ; preds = %28
store i32 -1, i32* %2
br label %48
43: ; preds = %25
br label %44
44: ; preds = %43
%45 = load i32, i32* %5
%46 = add nsw i32 %45, -1
store i32 %46, i32* %5
br label %11
47: ; preds = %11
store i32 -1, i32* %2
br label %48
48: ; preds = %47, %42, %35
%49 = load i32, i32* %2
ret i32 %49
}

LLVM IR (-O2):
@.str = [21 x i8] c"],AUTHORITY[\22EPSG\22,\22\00"
define i32 @fetch_srid(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = zext i32 %2 to i64
br label %4
4: ; preds = %10, %1
%5 = phi i64 [ %7, %10 ], [ %3, %1 ]
%6 = phi i32 [ %15, %10 ], [ 0, %1 ]
%7 = add nsw i64 %5, -1
%8 = trunc i64 %5 to i32
%9 = icmp sgt i32 %8, 2
br i1 %9, label %10, label %25
10: ; preds = %4
%11 = getelementptr inbounds i8, i8* %0, i64 %7
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 93
%14 = zext i1 %13 to i32
%15 = add nuw nsw i32 %6, %14
%16 = icmp eq i32 %15, 3
br i1 %16, label %17, label %4
17: ; preds = %10
%18 = and i64 %7, 4294967295
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = tail call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 20)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = getelementptr inbounds i8, i8* %19, i64 20
%24 = tail call i32 @atoi(i8* %23)
br label %25
25: ; preds = %4, %17, %22
%26 = phi i32 [ %24, %22 ], [ -1, %17 ], [ -1, %4 ]
ret i32 %26
}