#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 */
typedef int /*<<< orphan*/ gzFile;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
long gzread(int /*<<< orphan*/ *, char *, int);
int sscanf(char *, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(char *, char *, int);
int read_seq_header(gzFile *gzf_bin, char *seq_name, int *fastaS, int *qualS,
                    int *extrasS) {
  int header_size = 4;
  char hsize[40];
  char tmp[1000];
  char sname[10000];
  long pos = gzread(gzf_bin, hsize, header_size);
  if (pos == 0)
    return -2;
  if (pos == -1) {
    fprintf(stderr, "error reading header\n");
    return -1;
  }
  hsize[pos] = 0;
  sscanf(hsize, "%d", &header_size);
  pos = gzread(gzf_bin, tmp, header_size);
  if (pos == 0)
    return -2;
  if (pos == -1) {
    fprintf(stderr, "error reading header\n");
    return -1;
  }
  tmp[header_size] = 0;
  int reads = sscanf(tmp, "%s %d %d %d", sname, fastaS, qualS, extrasS);
  if (reads != 4) {
    return -1;
  };
  if (seq_name != NULL)
    strncpy(seq_name, sname, 10000);
  return 0;
}


x86 assembly (clang, -O0):
<read_seq_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2b70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x4,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1040 <gzread@plt>
mov    %rax,-0x2b68(%rbp)
cmpq   $0x0,-0x2b68(%rbp)
jne    1197 <read_seq_header+0x57>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12c5 <read_seq_header+0x185>
cmpq   $0xffffffffffffffff,-0x2b68(%rbp)
ff
jne    11c6 <read_seq_header+0x86>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c5 <read_seq_header+0x185>
mov    -0x2b68(%rbp),%rax
movb   $0x0,-0x60(%rbp,%rax,1)
lea    -0x60(%rbp),%rdi
lea    0xe42(%rip),%rsi
lea    -0x34(%rbp),%rdx
mov    $0x0,%al
call   1060 <sscanf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x450(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1040 <gzread@plt>
mov    %rax,-0x2b68(%rbp)
cmpq   $0x0,-0x2b68(%rbp)
jne    121c <read_seq_header+0xdc>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12c5 <read_seq_header+0x185>
cmpq   $0xffffffffffffffff,-0x2b68(%rbp)
ff
jne    124b <read_seq_header+0x10b>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c5 <read_seq_header+0x185>
movslq -0x34(%rbp),%rax
movb   $0x0,-0x450(%rbp,%rax,1)
lea    -0x450(%rbp),%rdi
lea    -0x2b60(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
lea    0xd9e(%rip),%rsi
mov    $0x0,%al
call   1060 <sscanf@plt>
mov    %eax,-0x2b6c(%rbp)
cmpl   $0x4,-0x2b6c(%rbp)
je     129e <read_seq_header+0x15e>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c5 <read_seq_header+0x185>
cmpq   $0x0,-0x18(%rbp)
je     12be <read_seq_header+0x17e>
mov    -0x18(%rbp),%rdi
lea    -0x2b60(%rbp),%rsi
mov    $0x2710,%edx
call   1030 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2b70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_seq_header>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2b48,%rsp
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x4,0xc(%rsp)
lea    0x10(%rsp),%rsi
mov    $0x4,%edx
call   1040 <gzread@plt>
mov    $0xfffffffe,%ebp
test   %rax,%rax
je     11da <read_seq_header+0x9a>
cmp    $0xffffffffffffffff,%rax
je     11c0 <read_seq_header+0x80>
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xe8c(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1060 <sscanf@plt>
mov    0xc(%rsp),%edx
lea    0x40(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <gzread@plt>
test   %rax,%rax
je     11da <read_seq_header+0x9a>
cmp    $0xffffffffffffffff,%rax
jne    11ee <read_seq_header+0xae>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x2b48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movslq 0xc(%rsp),%rax
movb   $0x0,0x40(%rsp,%rax,1)
lea    0xe17(%rip),%rsi
lea    0x40(%rsp),%rdi
lea    0x430(%rsp),%rdx
mov    %r13,%rcx
mov    %r12,%r8
mov    %r15,%r9
xor    %eax,%eax
call   1060 <sscanf@plt>
mov    $0xffffffff,%ebp
cmp    $0x4,%eax
jne    11da <read_seq_header+0x9a>
test   %r14,%r14
je     1240 <read_seq_header+0x100>
lea    0x430(%rsp),%rsi
mov    %r14,%rdi
mov    $0x2710,%edx
call   1030 <strncpy@plt>
xor    %ebp,%ebp
jmp    11da <read_seq_header+0x9a>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"error reading header\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [12 x i8] c"%s %d %d %d\00"
define i32 @read_seq_header(i32* %0, i8* %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca [40 x i8]
%14 = alloca [1000 x i8]
%15 = alloca [10000 x i8]
%16 = alloca i64
%17 = alloca i32
store i32* %0, i32** %7
store i8* %1, i8** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32 4, i32* %12
%18 = load i32*, i32** %7
%19 = getelementptr inbounds [40 x i8], [40 x i8]* %13, i64 0, i64 0
%20 = load i32, i32* %12
%21 = call i64 @gzread(i32* %18, i8* %19, i32 %20)
store i64 %21, i64* %16
%22 = load i64, i64* %16
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %5
store i32 -2, i32* %6
br label %70
25: ; preds = %5
%26 = load i64, i64* %16
%27 = icmp eq i64 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %6
br label %70
31: ; preds = %25
%32 = load i64, i64* %16
%33 = getelementptr inbounds [40 x i8], [40 x i8]* %13, i64 0, i64 %32
store i8 0, i8* %33
%34 = getelementptr inbounds [40 x i8], [40 x i8]* %13, i64 0, i64 0
%35 = call i32 (i8*, i8*, ...) @sscanf(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %12)
%36 = load i32*, i32** %7
%37 = getelementptr inbounds [1000 x i8], [1000 x i8]* %14, i64 0, i64 0
%38 = load i32, i32* %12
%39 = call i64 @gzread(i32* %36, i8* %37, i32 %38)
store i64 %39, i64* %16
%40 = load i64, i64* %16
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %31
store i32 -2, i32* %6
br label %70
43: ; preds = %31
%44 = load i64, i64* %16
%45 = icmp eq i64 %44, -1
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %6
br label %70
49: ; preds = %43
%50 = load i32, i32* %12
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [1000 x i8], [1000 x i8]* %14, i64 0, i64 %51
store i8 0, i8* %52
%53 = getelementptr inbounds [1000 x i8], [1000 x i8]* %14, i64 0, i64 0
%54 = getelementptr inbounds [10000 x i8], [10000 x i8]* %15, i64 0, i64 0
%55 = load i32*, i32** %9
%56 = load i32*, i32** %10
%57 = load i32*, i32** %11
%58 = call i32 (i8*, i8*, ...) @sscanf(i8* %53, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %54, i32* %55, i32* %56, i32* %57)
store i32 %58, i32* %17
%59 = load i32, i32* %17
%60 = icmp ne i32 %59, 4
br i1 %60, label %61, label %62
61: ; preds = %49
store i32 -1, i32* %6
br label %70
62: ; preds = %49
%63 = load i8*, i8** %8
%64 = icmp ne i8* %63, null
br i1 %64, label %65, label %69
65: ; preds = %62
%66 = load i8*, i8** %8
%67 = getelementptr inbounds [10000 x i8], [10000 x i8]* %15, i64 0, i64 0
%68 = call i32 @strncpy(i8* %66, i8* %67, i32 10000)
br label %69
69: ; preds = %65, %62
store i32 0, i32* %6
br label %70
70: ; preds = %69, %61, %46, %42, %28, %24
%71 = load i32, i32* %6
ret i32 %71
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"error reading header\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [12 x i8] c"%s %d %d %d\00"
define i32 @read_seq_header(i32* %0, i8* %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca [40 x i8]
%8 = alloca [1000 x i8]
%9 = alloca [10000 x i8]
%10 = bitcast i32* %6 to i8*
store i32 4, i32* %6
%11 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%13 = getelementptr inbounds [10000 x i8], [10000 x i8]* %9, i64 0, i64 0
%14 = call i64 @gzread(i32* %0, i8* %11, i32 4)
switch i64 %14, label %18 [
i64 0, label %36
i64 -1, label %15
]
15: ; preds = %5
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %36
18: ; preds = %5
%19 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 %14
store i8 0, i8* %19
%20 = call i32 (i8*, i8*, ...) @sscanf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%21 = load i32, i32* %6
%22 = call i64 @gzread(i32* %0, i8* %12, i32 %21)
switch i64 %22, label %26 [
i64 0, label %36
i64 -1, label %23
]
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %36
26: ; preds = %18
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 %28
store i8 0, i8* %29
%30 = call i32 (i8*, i8*, ...) @sscanf(i8* %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %13, i32* %2, i32* %3, i32* %4)
%31 = icmp eq i32 %30, 4
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = icmp eq i8* %1, null
br i1 %33, label %36, label %34
34: ; preds = %32
%35 = call i32 @strncpy(i8* %1, i8* %13, i32 10000)
br label %36
36: ; preds = %26, %34, %32, %18, %5, %23, %15
%37 = phi i32 [ -1, %15 ], [ -1, %23 ], [ -2, %5 ], [ -2, %18 ], [ -1, %26 ], [ 0, %34 ], [ 0, %32 ]
ret i32 %37
}