#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__ calloc(size_t, int);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
int strlen(char const *);
char *strstr(char const *, char *);
void extract_inchi_substring(char **buf, const char *str, size_t slen) {
  size_t i;
  char *p, pp;
  *buf = NULL;
  if (str == NULL)
    return;
  if (strlen(str) < 1)
    return;
  p = strstr(str, "InChI=");
  if (NULL == p)
    return;
  for (i = 0; i < slen; i++) {
    pp = p[i];
    if (pp >= 'A' && pp <= 'Z')
      continue;
    if (pp >= 'a' && pp <= 'z')
      continue;
    if (pp >= '0' && pp <= '9')
      continue;
    switch (pp) {
    case '(':
    case ')':
    case '*':
    case '+':
    case ',':
    case '-':
    case '.':
    case '/':
    case ';':
    case '=':
    case '?':
    case '@':
      continue;
    default:
      break;
    }
    break;
  }
  *buf = (char *)calloc(i + 1, sizeof(char));
  memcpy(*buf, p, i);
  (*buf)[i] = '\0';
  return;
}


x86 assembly (clang, -O0):
<extract_inchi_substring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
jne    116f <extract_inchi_substring+0x2f>
jmp    12d9 <extract_inchi_substring+0x199>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jge    1186 <extract_inchi_substring+0x46>
jmp    12d9 <extract_inchi_substring+0x199>
mov    -0x10(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    11ab <extract_inchi_substring+0x6b>
jmp    12d9 <extract_inchi_substring+0x199>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    129a <extract_inchi_substring+0x15a>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
cmp    $0x41,%eax
jl     11ee <extract_inchi_substring+0xae>
movsbl -0x29(%rbp),%eax
cmp    $0x5a,%eax
jg     11ee <extract_inchi_substring+0xae>
jmp    1289 <extract_inchi_substring+0x149>
movsbl -0x29(%rbp),%eax
cmp    $0x61,%eax
jl     120d <extract_inchi_substring+0xcd>
movsbl -0x29(%rbp),%eax
cmp    $0x7a,%eax
jg     120d <extract_inchi_substring+0xcd>
jmp    1289 <extract_inchi_substring+0x149>
movsbl -0x29(%rbp),%eax
cmp    $0x30,%eax
jl     122c <extract_inchi_substring+0xec>
movsbl -0x29(%rbp),%eax
cmp    $0x39,%eax
jg     122c <extract_inchi_substring+0xec>
jmp    1289 <extract_inchi_substring+0x149>
movsbl -0x29(%rbp),%eax
mov    %eax,-0x30(%rbp)
add    $0xffffffd8,%eax
sub    $0x8,%eax
jb     127a <extract_inchi_substring+0x13a>
jmp    1244 <extract_inchi_substring+0x104>
mov    -0x30(%rbp),%eax
sub    $0x3b,%eax
je     127a <extract_inchi_substring+0x13a>
jmp    1255 <extract_inchi_substring+0x115>
mov    -0x30(%rbp),%eax
sub    $0x3d,%eax
je     127a <extract_inchi_substring+0x13a>
jmp    1266 <extract_inchi_substring+0x126>
mov    -0x30(%rbp),%eax
add    $0xffffffc1,%eax
sub    $0x1,%eax
ja     127f <extract_inchi_substring+0x13f>
jmp    127a <extract_inchi_substring+0x13a>
jmp    1289 <extract_inchi_substring+0x149>
jmp    1284 <extract_inchi_substring+0x144>
jmp    129a <extract_inchi_substring+0x15a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11b3 <extract_inchi_substring+0x73>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_inchi_substring>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movq   $0x0,(%rdi)
test   %rsi,%rsi
je     1203 <extract_inchi_substring+0xc3>
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1203 <extract_inchi_substring+0xc3>
lea    0xe88(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
je     1203 <extract_inchi_substring+0xc3>
mov    %rax,%r15
xor    %ebx,%ebx
test   %r12,%r12
je     11dd <extract_inchi_substring+0x9d>
mov    $0x35,%eax
jmp    11a9 <extract_inchi_substring+0x69>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r12
je     11da <extract_inchi_substring+0x9a>
movsbl (%r15,%rbx,1),%ecx
mov    %ecx,%edx
and    $0xdf,%dl
add    $0xbf,%dl
cmp    $0x1a,%dl
jb     11a0 <extract_inchi_substring+0x60>
lea    -0x30(%rcx),%edx
cmp    $0xa,%dl
jb     11a0 <extract_inchi_substring+0x60>
lea    -0x28(%rcx),%edx
cmp    $0x8,%edx
jb     11a0 <extract_inchi_substring+0x60>
add    $0xffffffc5,%ecx
cmp    $0x5,%ecx
ja     11dd <extract_inchi_substring+0x9d>
bt     %ecx,%eax
jb     11a0 <extract_inchi_substring+0x60>
jmp    11dd <extract_inchi_substring+0x9d>
mov    %r12,%rbx
lea    0x1(%rbx),%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
mov    (%r14),%rax
movb   $0x0,(%rax,%rbx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"InChI=\00"
define void @extract_inchi_substring(i8** %0, i8* %1, i64 %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%10 = load i8**, i8*** %4
store i8* null, i8** %10
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %3
br label %85
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
%17 = icmp slt i32 %16, 1
br i1 %17, label %18, label %19
18: ; preds = %14
br label %85
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = call i8* @strstr(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = icmp eq i8* null, %22
br i1 %23, label %24, label %25
24: ; preds = %19
br label %85
25: ; preds = %19
store i64 0, i64* %7
br label %26
26: ; preds = %67, %25
%27 = load i64, i64* %7
%28 = load i64, i64* %6
%29 = icmp ult i64 %27, %28
br i1 %29, label %30, label %70
30: ; preds = %26
%31 = load i8*, i8** %8
%32 = load i64, i64* %7
%33 = getelementptr inbounds i8, i8* %31, i64 %32
%34 = load i8, i8* %33
store i8 %34, i8* %9
%35 = load i8, i8* %9
%36 = sext i8 %35 to i32
%37 = icmp sge i32 %36, 65
br i1 %37, label %38, label %43
38: ; preds = %30
%39 = load i8, i8* %9
%40 = sext i8 %39 to i32
%41 = icmp sle i32 %40, 90
br i1 %41, label %42, label %43
42: ; preds = %38
br label %67
43: ; preds = %38, %30
%44 = load i8, i8* %9
%45 = sext i8 %44 to i32
%46 = icmp sge i32 %45, 97
br i1 %46, label %47, label %52
47: ; preds = %43
%48 = load i8, i8* %9
%49 = sext i8 %48 to i32
%50 = icmp sle i32 %49, 122
br i1 %50, label %51, label %52
51: ; preds = %47
br label %67
52: ; preds = %47, %43
%53 = load i8, i8* %9
%54 = sext i8 %53 to i32
%55 = icmp sge i32 %54, 48
br i1 %55, label %56, label %61
56: ; preds = %52
%57 = load i8, i8* %9
%58 = sext i8 %57 to i32
%59 = icmp sle i32 %58, 57
br i1 %59, label %60, label %61
60: ; preds = %56
br label %67
61: ; preds = %56, %52
%62 = load i8, i8* %9
%63 = sext i8 %62 to i32
switch i32 %63, label %65 [
i32 40, label %64
i32 41, label %64
i32 42, label %64
i32 43, label %64
i32 44, label %64
i32 45, label %64
i32 46, label %64
i32 47, label %64
i32 59, label %64
i32 61, label %64
i32 63, label %64
i32 64, label %64
]
64: ; preds = %61, %61, %61, %61, %61, %61, %61, %61, %61, %61, %61, %61
br label %67
65: ; preds = %61
br label %66
66: ; preds = %65
br label %70
67: ; preds = %64, %60, %51, %42
%68 = load i64, i64* %7
%69 = add i64 %68, 1
store i64 %69, i64* %7
br label %26
70: ; preds = %66, %26
%71 = load i64, i64* %7
%72 = add i64 %71, 1
%73 = call i64 @calloc(i64 %72, i32 1)
%74 = inttoptr i64 %73 to i8*
%75 = load i8**, i8*** %4
store i8* %74, i8** %75
%76 = load i8**, i8*** %4
%77 = load i8*, i8** %76
%78 = load i8*, i8** %8
%79 = load i64, i64* %7
%80 = call i32 @memcpy(i8* %77, i8* %78, i64 %79)
%81 = load i8**, i8*** %4
%82 = load i8*, i8** %81
%83 = load i64, i64* %7
%84 = getelementptr inbounds i8, i8* %82, i64 %83
store i8 0, i8* %84
br label %85
85: ; preds = %70, %24, %18, %13
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"InChI=\00"
define void @extract_inchi_substring(i8** nocapture %0, i8* %1, i64 %2) {
store i8* null, i8** %0
%4 = icmp eq i8* %1, null
br i1 %4, label %36, label %5
5: ; preds = %3
%6 = tail call i32 @strlen(i8* %1)
%7 = icmp slt i32 %6, 1
br i1 %7, label %36, label %8
8: ; preds = %5
%9 = tail call i8* @strstr(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %36, label %11
11: ; preds = %8
%12 = icmp eq i64 %2, 0
br i1 %12, label %28, label %13
13: ; preds = %11, %25
%14 = phi i64 [ %26, %25 ], [ 0, %11 ]
%15 = getelementptr inbounds i8, i8* %9, i64 %14
%16 = load i8, i8* %15
%17 = and i8 %16, -33
%18 = add i8 %17, -65
%19 = icmp ult i8 %18, 26
%20 = add i8 %16, -48
%21 = icmp ult i8 %20, 10
%22 = select i1 %19, i1 true, i1 %21
br i1 %22, label %25, label %23
23: ; preds = %13
%24 = sext i8 %16 to i32
switch i32 %24, label %28 [
i32 40, label %25
i32 41, label %25
i32 42, label %25
i32 43, label %25
i32 44, label %25
i32 45, label %25
i32 46, label %25
i32 47, label %25
i32 59, label %25
i32 61, label %25
i32 63, label %25
i32 64, label %25
]
25: ; preds = %23, %23, %23, %23, %23, %23, %23, %23, %23, %23, %23, %23, %13
%26 = add nuw i64 %14, 1
%27 = icmp eq i64 %26, %2
br i1 %27, label %28, label %13
28: ; preds = %25, %23, %11
%29 = phi i64 [ 0, %11 ], [ %14, %23 ], [ %2, %25 ]
%30 = add i64 %29, 1
%31 = tail call i64 @calloc(i64 %30, i32 1)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %0
%33 = tail call i32 @memcpy(i8* %32, i8* %9, i64 %29)
%34 = load i8*, i8** %0
%35 = getelementptr inbounds i8, i8* %34, i64 %29
store i8 0, i8* %35
br label %36
36: ; preds = %8, %5, %3, %28
ret void
}