#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int sscanf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *strtok(char *, char *);
char *get_contig_name_fromSQ_line(const char *line) {
  char *tmp_line = malloc(sizeof(char) * (strlen(line) + 1));
  strcpy(tmp_line, line);
  char *nom = NULL;
  char *tag = strtok(tmp_line, "\t");
  char *tmp = NULL;
  while (tag != NULL) {
    int chk = 0;
    tmp = malloc(sizeof(char) * 5000);
    chk = sscanf(tag, "SN:%[^\t\n]", tmp);
    if (chk > 0) {
      nom = malloc(sizeof(char) * (strlen(tmp) + 1));
      strcpy(nom, tmp);
      tag = strtok(NULL, "\t");
      continue;
    }
    tag = strtok(NULL, "\t");
  }
  if (tmp)
    free(tmp);
  free(tmp_line);
  if (nom == NULL) {
    fprintf(stderr, "Error fetching contig name given line %s\n", line);
    exit(1);
  }
  return nom;
}


x86 assembly (clang, -O0):
<get_contig_name_fromSQ_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1277 <get_contig_name_fromSQ_line+0xf7>
movl   $0x0,-0x2c(%rbp)
mov    $0x1388,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xdf9(%rip),%rsi
call   1080 <sscanf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jle    125e <get_contig_name_fromSQ_line+0xde>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdb0(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    11da <get_contig_name_fromSQ_line+0x5a>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd97(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    11da <get_contig_name_fromSQ_line+0x5a>
cmpq   $0x0,-0x28(%rbp)
je     128b <get_contig_name_fromSQ_line+0x10b>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x18(%rbp)
jne    12c2 <get_contig_name_fromSQ_line+0x142>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd59(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_contig_name_fromSQ_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,(%rsp)
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xe4c(%rip),%rsi
mov    %r15,%rdi
call   1090 <strtok@plt>
test   %rax,%rax
je     125d <get_contig_name_fromSQ_line+0xdd>
mov    %rax,%r14
xor    %ebx,%ebx
lea    0xe31(%rip),%r12
lea    0xe28(%rip),%r13
jmp    11f2 <get_contig_name_fromSQ_line+0x72>
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r13,%rsi
call   1090 <strtok@plt>
mov    %rax,%r14
test   %rax,%rax
je     1231 <get_contig_name_fromSQ_line+0xb1>
mov    $0x1388,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   1080 <sscanf@plt>
test   %eax,%eax
jle    11e0 <get_contig_name_fromSQ_line+0x60>
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
jmp    11e0 <get_contig_name_fromSQ_line+0x60>
test   %rbp,%rbp
je     123e <get_contig_name_fromSQ_line+0xbe>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
test   %rbx,%rbx
je     1265 <get_contig_name_fromSQ_line+0xe5>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
mov    (%rsp),%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\09\00"
@.str.1 = [10 x i8] c"SN:%[^\09\0A]\00"
@stderr = global i32 0
@.str.2 = [42 x i8] c"Error fetching contig name given line %s\0A\00"
define i8* @get_contig_name_fromSQ_line(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = mul i64 1, %11
%13 = trunc i64 %12 to i32
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %3
%15 = load i8*, i8** %3
%16 = load i8*, i8** %2
%17 = call i32 @strcpy(i8* %15, i8* %16)
store i8* null, i8** %4
%18 = load i8*, i8** %3
%19 = call i8* @strtok(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %19, i8** %5
store i8* null, i8** %6
br label %20
20: ; preds = %42, %30, %1
%21 = load i8*, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %44
23: ; preds = %20
store i32 0, i32* %7
%24 = call i8* @malloc(i32 5000)
store i8* %24, i8** %6
%25 = load i8*, i8** %5
%26 = load i8*, i8** %6
%27 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %26)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %42
30: ; preds = %23
%31 = load i8*, i8** %6
%32 = call i32 @strlen(i8* %31)
%33 = add nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = mul i64 1, %34
%36 = trunc i64 %35 to i32
%37 = call i8* @malloc(i32 %36)
store i8* %37, i8** %4
%38 = load i8*, i8** %4
%39 = load i8*, i8** %6
%40 = call i32 @strcpy(i8* %38, i8* %39)
%41 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %41, i8** %5
br label %20
42: ; preds = %23
%43 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %43, i8** %5
br label %20
44: ; preds = %20
%45 = load i8*, i8** %6
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i8*, i8** %6
%49 = call i32 @free(i8* %48)
br label %50
50: ; preds = %47, %44
%51 = load i8*, i8** %3
%52 = call i32 @free(i8* %51)
%53 = load i8*, i8** %4
%54 = icmp eq i8* %53, null
br i1 %54, label %55, label %60
55: ; preds = %50
%56 = load i32, i32* @stderr
%57 = load i8*, i8** %2
%58 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %57)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %50
%61 = load i8*, i8** %4
ret i8* %61
}

LLVM IR (-O2):
@.str = [2 x i8] c"\09\00"
@.str.1 = [10 x i8] c"SN:%[^\09\0A]\00"
@stderr = global i32 0
@.str.2 = [42 x i8] c"Error fetching contig name given line %s\0A\00"
define i8* @get_contig_name_fromSQ_line(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = tail call i8* @malloc(i32 %3)
%5 = tail call i32 @strcpy(i8* %4, i8* %0)
%6 = tail call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @free(i8* %4)
br label %32
10: ; preds = %1, %21
%11 = phi i8* [ %22, %21 ], [ null, %1 ]
%12 = phi i8* [ %23, %21 ], [ %6, %1 ]
%13 = tail call dereferenceable_or_null(5000) i8* @malloc(i32 5000)
%14 = tail call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %10
%17 = tail call i32 @strlen(i8* %13)
%18 = add nsw i32 %17, 1
%19 = tail call i8* @malloc(i32 %18)
%20 = tail call i32 @strcpy(i8* %19, i8* %13)
br label %21
21: ; preds = %10, %16
%22 = phi i8* [ %19, %16 ], [ %11, %10 ]
%23 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %10
25: ; preds = %21
%26 = icmp eq i8* %13, null
br i1 %26, label %29, label %27
27: ; preds = %25
%28 = tail call i32 @free(i8* %13)
br label %29
29: ; preds = %27, %25
%30 = tail call i32 @free(i8* %4)
%31 = icmp eq i8* %22, null
br i1 %31, label %32, label %36
32: ; preds = %8, %29
%33 = load i32, i32* @stderr
%34 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %29
ret i8* %22
}