#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 */
char *strchr(char *, char);
int strlen(char *);
int nsrl_extract_sha1(char *str, char **sha1, char **name, int ver) {
  char *ptr = NULL;
  if (((strlen((str)) > 40 + 4) && ((str)[0] == '"') &&
       ((str)[40 + 1] == '"') && ((str)[40 + 2] == ',') &&
       ((str)[40 + 3] == '"')) == 0) {
    return 1;
  }
  if (sha1 != NULL) {
    ptr = &str[1];
    ptr[40] = '\0';
    if (NULL != strchr(ptr, ',')) {
      return 1;
    }
    *sha1 = ptr;
  }
  if (name != NULL) {
    if (ver == 1) {
      ptr = &str[40 + 4];
      *name = ptr;
      if (NULL == (ptr = strchr(ptr, ','))) {
        return 1;
      }
      ptr[-1] = '\0';
    } else if (ver == 2) {
      ptr = &str[1 + 40 + 3 + 32 + 3 + 8 + 3];
      *name = ptr;
      if (NULL == (ptr = strchr(ptr, ','))) {
        return 1;
      }
      ptr[-1] = '\0';
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<nsrl_extract_sha1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x2c,%ecx
mov    %al,-0x31(%rbp)
jle    11aa <nsrl_extract_sha1+0x8a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x22,%ecx
mov    %al,-0x31(%rbp)
jne    11aa <nsrl_extract_sha1+0x8a>
mov    -0x10(%rbp),%rax
movsbl 0x29(%rax),%ecx
xor    %eax,%eax
cmp    $0x22,%ecx
mov    %al,-0x31(%rbp)
jne    11aa <nsrl_extract_sha1+0x8a>
mov    -0x10(%rbp),%rax
movsbl 0x2a(%rax),%ecx
xor    %eax,%eax
cmp    $0x2c,%ecx
mov    %al,-0x31(%rbp)
jne    11aa <nsrl_extract_sha1+0x8a>
mov    -0x10(%rbp),%rax
movsbl 0x2b(%rax),%eax
cmp    $0x22,%eax
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x0,%eax
jne    11c7 <nsrl_extract_sha1+0xa7>
movl   $0x1,-0x4(%rbp)
jmp    12e4 <nsrl_extract_sha1+0x1c4>
cmpq   $0x0,-0x18(%rbp)
je     1219 <nsrl_extract_sha1+0xf9>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,0x28(%rax)
mov    -0x30(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     120e <nsrl_extract_sha1+0xee>
movl   $0x1,-0x4(%rbp)
jmp    12e4 <nsrl_extract_sha1+0x1c4>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     12dd <nsrl_extract_sha1+0x1bd>
cmpl   $0x1,-0x24(%rbp)
jne    127e <nsrl_extract_sha1+0x15e>
mov    -0x10(%rbp),%rax
add    $0x2c,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,%rcx
mov    %rcx,-0x30(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    1271 <nsrl_extract_sha1+0x151>
movl   $0x1,-0x4(%rbp)
jmp    12e4 <nsrl_extract_sha1+0x1c4>
mov    -0x30(%rbp),%rax
movb   $0x0,-0x1(%rax)
jmp    12d8 <nsrl_extract_sha1+0x1b8>
cmpl   $0x2,-0x24(%rbp)
jne    12d3 <nsrl_extract_sha1+0x1b3>
mov    -0x10(%rbp),%rax
add    $0x5a,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,%rcx
mov    %rcx,-0x30(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    12cb <nsrl_extract_sha1+0x1ab>
movl   $0x1,-0x4(%rbp)
jmp    12e4 <nsrl_extract_sha1+0x1c4>
mov    -0x30(%rbp),%rax
movb   $0x0,-0x1(%rax)
jmp    12d8 <nsrl_extract_sha1+0x1b8>
jmp    12dd <nsrl_extract_sha1+0x1bd>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nsrl_extract_sha1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    $0x1,%r12d
cmp    $0x2d,%eax
jl     11b8 <nsrl_extract_sha1+0x98>
cmpb   $0x22,(%rbx)
jne    11b8 <nsrl_extract_sha1+0x98>
cmpb   $0x22,0x29(%rbx)
jne    11b8 <nsrl_extract_sha1+0x98>
cmpb   $0x2c,0x2a(%rbx)
jne    11b8 <nsrl_extract_sha1+0x98>
cmpb   $0x22,0x2b(%rbx)
jne    11b8 <nsrl_extract_sha1+0x98>
test   %rbp,%rbp
je     1181 <nsrl_extract_sha1+0x61>
lea    0x1(%rbx),%r13
movb   $0x0,0x29(%rbx)
mov    %r13,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11b8 <nsrl_extract_sha1+0x98>
mov    %r13,0x0(%rbp)
test   %r14,%r14
je     11b5 <nsrl_extract_sha1+0x95>
cmp    $0x2,%r15d
je     1198 <nsrl_extract_sha1+0x78>
cmp    $0x1,%r15d
jne    11b5 <nsrl_extract_sha1+0x95>
add    $0x2c,%rbx
jmp    119c <nsrl_extract_sha1+0x7c>
add    $0x5a,%rbx
mov    %rbx,(%r14)
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11b8 <nsrl_extract_sha1+0x98>
movb   $0x0,-0x1(%rax)
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @nsrl_extract_sha1(i8* %0, i8** %1, i8** %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %6
store i8** %1, i8*** %7
store i8** %2, i8*** %8
store i32 %3, i32* %9
store i8* null, i8** %10
%11 = load i8*, i8** %6
%12 = call i32 @strlen(i8* %11)
%13 = icmp sgt i32 %12, 44
br i1 %13, label %14, label %38
14: ; preds = %4
%15 = load i8*, i8** %6
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 34
br i1 %19, label %20, label %38
20: ; preds = %14
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 41
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 34
br i1 %25, label %26, label %38
26: ; preds = %20
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i64 42
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 44
br i1 %31, label %32, label %38
32: ; preds = %26
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 43
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 34
br label %38
38: ; preds = %32, %26, %20, %14, %4
%39 = phi i1 [ false, %26 ], [ false, %20 ], [ false, %14 ], [ false, %4 ], [ %37, %32 ]
%40 = zext i1 %39 to i32
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %38
store i32 1, i32* %5
br label %94
43: ; preds = %38
%44 = load i8**, i8*** %7
%45 = icmp ne i8** %44, null
br i1 %45, label %46, label %58
46: ; preds = %43
%47 = load i8*, i8** %6
%48 = getelementptr inbounds i8, i8* %47, i64 1
store i8* %48, i8** %10
%49 = load i8*, i8** %10
%50 = getelementptr inbounds i8, i8* %49, i64 40
store i8 0, i8* %50
%51 = load i8*, i8** %10
%52 = call i8* @strchr(i8* %51, i8 signext 44)
%53 = icmp ne i8* null, %52
br i1 %53, label %54, label %55
54: ; preds = %46
store i32 1, i32* %5
br label %94
55: ; preds = %46
%56 = load i8*, i8** %10
%57 = load i8**, i8*** %7
store i8* %56, i8** %57
br label %58
58: ; preds = %55, %43
%59 = load i8**, i8*** %8
%60 = icmp ne i8** %59, null
br i1 %60, label %61, label %93
61: ; preds = %58
%62 = load i32, i32* %9
%63 = icmp eq i32 %62, 1
br i1 %63, label %64, label %76
64: ; preds = %61
%65 = load i8*, i8** %6
%66 = getelementptr inbounds i8, i8* %65, i64 44
store i8* %66, i8** %10
%67 = load i8*, i8** %10
%68 = load i8**, i8*** %8
store i8* %67, i8** %68
%69 = load i8*, i8** %10
%70 = call i8* @strchr(i8* %69, i8 signext 44)
store i8* %70, i8** %10
%71 = icmp eq i8* null, %70
br i1 %71, label %72, label %73
72: ; preds = %64
store i32 1, i32* %5
br label %94
73: ; preds = %64
%74 = load i8*, i8** %10
%75 = getelementptr inbounds i8, i8* %74, i64 -1
store i8 0, i8* %75
br label %92
76: ; preds = %61
%77 = load i32, i32* %9
%78 = icmp eq i32 %77, 2
br i1 %78, label %79, label %91
79: ; preds = %76
%80 = load i8*, i8** %6
%81 = getelementptr inbounds i8, i8* %80, i64 90
store i8* %81, i8** %10
%82 = load i8*, i8** %10
%83 = load i8**, i8*** %8
store i8* %82, i8** %83
%84 = load i8*, i8** %10
%85 = call i8* @strchr(i8* %84, i8 signext 44)
store i8* %85, i8** %10
%86 = icmp eq i8* null, %85
br i1 %86, label %87, label %88
87: ; preds = %79
store i32 1, i32* %5
br label %94
88: ; preds = %79
%89 = load i8*, i8** %10
%90 = getelementptr inbounds i8, i8* %89, i64 -1
store i8 0, i8* %90
br label %91
91: ; preds = %88, %76
br label %92
92: ; preds = %91, %73
br label %93
93: ; preds = %92, %58
store i32 0, i32* %5
br label %94
94: ; preds = %93, %87, %72, %54, %42
%95 = load i32, i32* %5
ret i32 %95
}

LLVM IR (-O2):
define i32 @nsrl_extract_sha1(i8* %0, i8** writeonly %1, i8** writeonly %2, i32 %3) {
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, 44
br i1 %6, label %7, label %43
7: ; preds = %4
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 34
br i1 %9, label %10, label %43
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %0, i64 41
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 34
br i1 %13, label %14, label %43
14: ; preds = %10
%15 = getelementptr inbounds i8, i8* %0, i64 42
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 44
br i1 %17, label %18, label %43
18: ; preds = %14
%19 = getelementptr inbounds i8, i8* %0, i64 43
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 34
br i1 %21, label %22, label %43
22: ; preds = %18
%23 = icmp eq i8** %1, null
br i1 %23, label %29, label %24
24: ; preds = %22
%25 = getelementptr inbounds i8, i8* %0, i64 1
store i8 0, i8* %11
%26 = tail call i8* @strchr(i8* %25, i8 signext 44)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %43
28: ; preds = %24
store i8* %25, i8** %1
br label %29
29: ; preds = %28, %22
%30 = icmp eq i8** %2, null
br i1 %30, label %43, label %31
31: ; preds = %29
switch i32 %3, label %43 [
i32 1, label %32
i32 2, label %36
]
32: ; preds = %31
%33 = getelementptr inbounds i8, i8* %0, i64 44
store i8* %33, i8** %2
%34 = tail call i8* @strchr(i8* %33, i8 signext 44)
%35 = icmp eq i8* %34, null
br i1 %35, label %43, label %40
36: ; preds = %31
%37 = getelementptr inbounds i8, i8* %0, i64 90
store i8* %37, i8** %2
%38 = tail call i8* @strchr(i8* %37, i8 signext 44)
%39 = icmp eq i8* %38, null
br i1 %39, label %43, label %40
40: ; preds = %36, %32
%41 = phi i8* [ %34, %32 ], [ %38, %36 ]
%42 = getelementptr inbounds i8, i8* %41, i64 -1
store i8 0, i8* %42
br label %43
43: ; preds = %40, %4, %7, %10, %14, %29, %31, %36, %32, %24, %18
%44 = phi i32 [ 1, %18 ], [ 1, %24 ], [ 1, %32 ], [ 1, %36 ], [ 0, %31 ], [ 0, %29 ], [ 1, %14 ], [ 1, %10 ], [ 1, %7 ], [ 1, %4 ], [ 0, %40 ]
ret i32 %44
}