#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 *);
char *strstr(char *, char *);
void extract_inchi_substring(char **buf, char *str, size_t slen) {
  size_t i;
  char *p;
  *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++) {
    switch (p[i]) {
    case ' ':
    case '\t':
    case '\r':
    case '\n':
    case '\0':
      break;
    default:
      continue;
    }
    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    1272 <extract_inchi_substring+0x132>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jge    1186 <extract_inchi_substring+0x46>
jmp    1272 <extract_inchi_substring+0x132>
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    1272 <extract_inchi_substring+0x132>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1233 <extract_inchi_substring+0xf3>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x2c(%rbp)
test   %eax,%eax
je     1213 <extract_inchi_substring+0xd3>
jmp    11dd <extract_inchi_substring+0x9d>
mov    -0x2c(%rbp),%eax
add    $0xfffffff7,%eax
sub    $0x2,%eax
jb     1213 <extract_inchi_substring+0xd3>
jmp    11f1 <extract_inchi_substring+0xb1>
mov    -0x2c(%rbp),%eax
sub    $0xd,%eax
je     1213 <extract_inchi_substring+0xd3>
jmp    1202 <extract_inchi_substring+0xc2>
mov    -0x2c(%rbp),%eax
sub    $0x20,%eax
jne    1218 <extract_inchi_substring+0xd8>
jmp    1213 <extract_inchi_substring+0xd3>
jmp    121d <extract_inchi_substring+0xdd>
jmp    1222 <extract_inchi_substring+0xe2>
jmp    1233 <extract_inchi_substring+0xf3>
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     11df <extract_inchi_substring+0x9f>
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11df <extract_inchi_substring+0x9f>
lea    0xe8c(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
je     11df <extract_inchi_substring+0x9f>
mov    %rax,%r15
xor    %ebx,%ebx
test   %r12,%r12
je     11b9 <extract_inchi_substring+0x79>
movabs $0x100002601,%rax
jmp    11a9 <extract_inchi_substring+0x69>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r12
je     11eb <extract_inchi_substring+0xab>
movsbl (%r15,%rbx,1),%ecx
cmp    $0x20,%ecx
ja     11a0 <extract_inchi_substring+0x60>
bt     %rcx,%rax
jae    11a0 <extract_inchi_substring+0x60>
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
mov    %r12,%rbx
jmp    11b9 <extract_inchi_substring+0x79>

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*
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i8**, i8*** %4
store i8* null, i8** %9
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %3
br label %56
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = call i32 @strlen(i8* %14)
%16 = icmp slt i32 %15, 1
br i1 %16, label %17, label %18
17: ; preds = %13
br label %56
18: ; preds = %13
%19 = load i8*, i8** %5
%20 = call i8* @strstr(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %20, i8** %8
%21 = load i8*, i8** %8
%22 = icmp eq i8* null, %21
br i1 %22, label %23, label %24
23: ; preds = %18
br label %56
24: ; preds = %18
store i64 0, i64* %7
br label %25
25: ; preds = %38, %24
%26 = load i64, i64* %7
%27 = load i64, i64* %6
%28 = icmp ult i64 %26, %27
br i1 %28, label %29, label %41
29: ; preds = %25
%30 = load i8*, i8** %8
%31 = load i64, i64* %7
%32 = getelementptr inbounds i8, i8* %30, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
switch i32 %34, label %36 [
i32 32, label %35
i32 9, label %35
i32 13, label %35
i32 10, label %35
i32 0, label %35
]
35: ; preds = %29, %29, %29, %29, %29
br label %37
36: ; preds = %29
br label %38
37: ; preds = %35
br label %41
38: ; preds = %36
%39 = load i64, i64* %7
%40 = add i64 %39, 1
store i64 %40, i64* %7
br label %25
41: ; preds = %37, %25
%42 = load i64, i64* %7
%43 = add i64 %42, 1
%44 = call i64 @calloc(i64 %43, i32 1)
%45 = inttoptr i64 %44 to i8*
%46 = load i8**, i8*** %4
store i8* %45, i8** %46
%47 = load i8**, i8*** %4
%48 = load i8*, i8** %47
%49 = load i8*, i8** %8
%50 = load i64, i64* %7
%51 = call i32 @memcpy(i8* %48, i8* %49, i64 %50)
%52 = load i8**, i8*** %4
%53 = load i8*, i8** %52
%54 = load i64, i64* %7
%55 = getelementptr inbounds i8, i8* %53, i64 %54
store i8 0, i8* %55
br label %56
56: ; preds = %41, %23, %17, %12
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 %29, label %5
5: ; preds = %3
%6 = tail call i32 @strlen(i8* %1)
%7 = icmp slt i32 %6, 1
br i1 %7, label %29, 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 %29, label %11
11: ; preds = %8
%12 = icmp eq i64 %2, 0
br i1 %12, label %21, label %13
13: ; preds = %11, %18
%14 = phi i64 [ %19, %18 ], [ 0, %11 ]
%15 = getelementptr inbounds i8, i8* %9, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
switch i32 %17, label %18 [
i32 32, label %21
i32 9, label %21
i32 13, label %21
i32 10, label %21
i32 0, label %21
]
18: ; preds = %13
%19 = add nuw i64 %14, 1
%20 = icmp eq i64 %19, %2
br i1 %20, label %21, label %13
21: ; preds = %18, %13, %13, %13, %13, %13, %11
%22 = phi i64 [ 0, %11 ], [ %14, %13 ], [ %14, %13 ], [ %14, %13 ], [ %14, %13 ], [ %14, %13 ], [ %2, %18 ]
%23 = add i64 %22, 1
%24 = tail call i64 @calloc(i64 %23, i32 1)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %0
%26 = tail call i32 @memcpy(i8* %25, i8* %9, i64 %22)
%27 = load i8*, i8** %0
%28 = getelementptr inbounds i8, i8* %27, i64 %22
store i8 0, i8* %28
br label %29
29: ; preds = %8, %5, %3, %21
ret void
}