#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 */
struct seq {
  int dummy;
};
typedef int /*<<< orphan*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ cctools_fatal(char *, char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int getc_unlocked(int /*<<< orphan*/ *);
scalar_t__ isspace(int);
char *malloc(int);
char *realloc(char *, int);
struct seq *seq_create(char *, char *, char *);
int sscanf(char *, char *, char *, char *);
char toupper(int);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
struct seq *seq_read(FILE *file) {
  static char *buffer = 0;
  static int buffer_size = 1024;
  char line[1024];
  char name[1024];
  char metadata[1024];
  if (!fgets(line, sizeof(line), file))
    return 0;
  if (line[0] == '>' && line[1] == '>')
    return 0;
  metadata[0] = 0;
  int n = sscanf(line, ">%s %[^\n]\n", name, metadata);
  if (n < 1)
    cctools_fatal("syntax error near: %s\n", line);
  if (!buffer)
    buffer = malloc(buffer_size);
  int num_bases = 0;
  while (1) {
    int c = getc_unlocked(file);
    if (isspace(c))
      continue;
    if (c == EOF)
      break;
    if (c == '>') {
      ungetc(c, file);
      break;
    }
    buffer[num_bases++] = toupper(c);
    if (num_bases > (buffer_size - 2)) {
      buffer_size *= 2;
      buffer = realloc(buffer, buffer_size);
    }
  }
  buffer[num_bases] = 0;
  return seq_create(name, buffer, metadata);
}


x86 assembly (clang, -O0):
<seq_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
cmp    $0x0,%eax
jne    11da <seq_read+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    1382 <seq_read+0x1e2>
movsbl -0x410(%rbp),%eax
cmp    $0x3e,%eax
jne    1207 <seq_read+0x67>
movsbl -0x40f(%rbp),%eax
cmp    $0x3e,%eax
jne    1207 <seq_read+0x67>
movq   $0x0,-0x8(%rbp)
jmp    1382 <seq_read+0x1e2>
movb   $0x0,-0xc10(%rbp)
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rdx
lea    -0xc10(%rbp),%rcx
lea    0xdd6(%rip),%rsi
call   10b0 <sscanf@plt>
mov    %eax,-0xc14(%rbp)
cmpl   $0x1,-0xc14(%rbp)
jge    1255 <seq_read+0xb5>
lea    -0x410(%rbp),%rsi
lea    0xdbb(%rip),%rdi
call   1080 <cctools_fatal@plt>
cmpq   $0x0,0x2e23(%rip)
jne    1275 <seq_read+0xd5>
mov    0x2e07(%rip),%edi
call   1090 <malloc@plt>
mov    %rax,0x2e0b(%rip)
movl   $0x0,-0xc18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <getc_unlocked@plt>
mov    %eax,-0xc1c(%rbp)
mov    -0xc1c(%rbp),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
je     12a8 <seq_read+0x108>
jmp    127f <seq_read+0xdf>
mov    -0xc1c(%rbp),%eax
mov    0x2d33(%rip),%rcx
cmp    (%rcx),%eax
jne    12c2 <seq_read+0x122>
jmp    1352 <seq_read+0x1b2>
cmpl   $0x3e,-0xc1c(%rbp)
jne    12e3 <seq_read+0x143>
mov    -0xc1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10a0 <ungetc@plt>
jmp    1352 <seq_read+0x1b2>
mov    -0xc1c(%rbp),%edi
call   1030 <toupper@plt>
mov    %al,%dl
mov    0x2d89(%rip),%rax
mov    -0xc18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0xc18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc18(%rbp),%eax
mov    0x2d56(%rip),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jle    134d <seq_read+0x1ad>
mov    0x2d45(%rip),%eax
shl    $0x1,%eax
mov    %eax,0x2d3c(%rip)
mov    0x2d45(%rip),%rdi
mov    0x2d2f(%rip),%esi
call   10c0 <realloc@plt>
mov    %rax,0x2d33(%rip)
jmp    127f <seq_read+0xdf>
mov    0x2d27(%rip),%rax
movslq -0xc18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x810(%rbp),%rdi
mov    0x2d0e(%rip),%rsi
lea    -0xc10(%rbp),%rdx
call   1050 <seq_create@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xc20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seq_read>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xc00,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
je     12d5 <seq_read+0x135>
mov    0x1(%rsp),%cl
xor    %eax,%eax
cmpb   $0x3e,(%rsp)
jne    11e3 <seq_read+0x43>
cmp    $0x3e,%cl
je     12d5 <seq_read+0x135>
movb   $0x0,0x400(%rsp)
lea    0xe0e(%rip),%rsi
mov    %rsp,%rdi
lea    0x800(%rsp),%rdx
lea    0x400(%rsp),%rcx
call   10b0 <sscanf@plt>
test   %eax,%eax
jg     121d <seq_read+0x7d>
lea    0xdf6(%rip),%rdi
mov    %rsp,%rsi
call   1080 <cctools_fatal@plt>
xor    %r14d,%r14d
cmpq   $0x0,0x2e58(%rip)
jne    123f <seq_read+0x9f>
mov    0x2e40(%rip),%edi
call   1090 <malloc@plt>
xor    %r14d,%r14d
mov    %rax,0x2e41(%rip)
mov    0x2da2(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <getc_unlocked@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <isspace@plt>
test   %rax,%rax
jne    1250 <seq_read+0xb0>
movslq %r14d,%r12
cmp    (%r15),%ebp
je     12b4 <seq_read+0x114>
cmp    $0x3e,%ebp
je     12a7 <seq_read+0x107>
mov    %ebp,%edi
call   1030 <toupper@plt>
mov    0x2dff(%rip),%rdi
lea    0x1(%r12),%r14d
mov    %al,(%rdi,%r12,1)
mov    0x2de0(%rip),%esi
lea    -0x2(%rsi),%eax
cmp    %eax,%r12d
jl     1250 <seq_read+0xb0>
add    %esi,%esi
mov    %esi,0x2dd0(%rip)
call   10c0 <realloc@plt>
jmp    1238 <seq_read+0x98>
mov    $0x3e,%edi
mov    %rbx,%rsi
call   10a0 <ungetc@plt>
mov    0x2dc5(%rip),%rsi
movb   $0x0,(%rsi,%r12,1)
lea    0x800(%rsp),%rdi
lea    0x400(%rsp),%rdx
call   1050 <seq_create@plt>
add    $0xc00,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.seq = type { i32 }
@seq_read.buffer = internal global i8* null
@seq_read.buffer_size = internal global i32 1024
@.str = [11 x i8] c">%s %[^\0A]\0A\00"
@.str.1 = [23 x i8] c"syntax error near: %s\0A\00"
@EOF = global i32 0
define %struct.seq* @seq_read(i32* %0) {
%2 = alloca %struct.seq*
%3 = alloca i32*
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %3
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = load i32*, i32** %3
%12 = call i32 @fgets(i8* %10, i32 1024, i32* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %1
store %struct.seq* null, %struct.seq** %2
br label %91
15: ; preds = %1
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 62
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 1
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 62
br i1 %24, label %25, label %26
25: ; preds = %20
store %struct.seq* null, %struct.seq** %2
br label %91
26: ; preds = %20, %15
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
store i8 0, i8* %27
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%31 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %29, i8* %30)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp slt i32 %32, 1
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%36 = call i32 @cctools_fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %35)
br label %37
37: ; preds = %34, %26
%38 = load i8*, i8** @seq_read.buffer
%39 = icmp ne i8* %38, null
br i1 %39, label %43, label %40
40: ; preds = %37
%41 = load i32, i32* @seq_read.buffer_size
%42 = call i8* @malloc(i32 %41)
store i8* %42, i8** @seq_read.buffer
br label %43
43: ; preds = %40, %37
store i32 0, i32* %8
br label %44
44: ; preds = %43, %50, %81
%45 = load i32*, i32** %3
%46 = call i32 @getc_unlocked(i32* %45)
store i32 %46, i32* %9
%47 = load i32, i32* %9
%48 = call i64 @isspace(i32 %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %44
br label %44
51: ; preds = %44
%52 = load i32, i32* %9
%53 = load i32, i32* @EOF
%54 = icmp eq i32 %52, %53
br i1 %54, label %55, label %56
55: ; preds = %51
br label %82
56: ; preds = %51
%57 = load i32, i32* %9
%58 = icmp eq i32 %57, 62
br i1 %58, label %59, label %63
59: ; preds = %56
%60 = load i32, i32* %9
%61 = load i32*, i32** %3
%62 = call i32 @ungetc(i32 %60, i32* %61)
br label %82
63: ; preds = %56
%64 = load i32, i32* %9
%65 = call signext i8 @toupper(i32 %64)
%66 = load i8*, i8** @seq_read.buffer
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 1
store i32 %68, i32* %8
%69 = sext i32 %67 to i64
%70 = getelementptr inbounds i8, i8* %66, i64 %69
store i8 %65, i8* %70
%71 = load i32, i32* %8
%72 = load i32, i32* @seq_read.buffer_size
%73 = sub nsw i32 %72, 2
%74 = icmp sgt i32 %71, %73
br i1 %74, label %75, label %81
75: ; preds = %63
%76 = load i32, i32* @seq_read.buffer_size
%77 = mul nsw i32 %76, 2
store i32 %77, i32* @seq_read.buffer_size
%78 = load i8*, i8** @seq_read.buffer
%79 = load i32, i32* @seq_read.buffer_size
%80 = call i8* @realloc(i8* %78, i32 %79)
store i8* %80, i8** @seq_read.buffer
br label %81
81: ; preds = %75, %63
br label %44
82: ; preds = %59, %55
%83 = load i8*, i8** @seq_read.buffer
%84 = load i32, i32* %8
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %83, i64 %85
store i8 0, i8* %86
%87 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%88 = load i8*, i8** @seq_read.buffer
%89 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%90 = call %struct.seq* @seq_create(i8* %87, i8* %88, i8* %89)
store %struct.seq* %90, %struct.seq** %2
br label %91
91: ; preds = %82, %25, %14
%92 = load %struct.seq*, %struct.seq** %2
ret %struct.seq* %92
}

LLVM IR (-O2):
%struct.seq = type { i32 }
@seq_read.buffer = internal unnamed_addr global i8* null
@seq_read.buffer_size = internal unnamed_addr global i32 1024
@.str = [11 x i8] c">%s %[^\0A]\0A\00"
@.str.1 = [23 x i8] c"syntax error near: %s\0A\00"
@EOF = global i32 0
define %struct.seq* @seq_read(i32* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = call i32 @fgets(i8* %5, i32 1024, i32* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %63, label %10
10: ; preds = %1
%11 = load i8, i8* %5
%12 = icmp eq i8 %11, 62
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 62
%16 = select i1 %12, i1 %15, i1 false
br i1 %16, label %63, label %17
17: ; preds = %10
store i8 0, i8* %7
%18 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %7)
%19 = icmp slt i32 %18, 1
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @cctools_fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %22
22: ; preds = %20, %17
%23 = load i8*, i8** @seq_read.buffer
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i32, i32* @seq_read.buffer_size
%27 = call i8* @malloc(i32 %26)
br label %28
28: ; preds = %25, %55
%29 = phi i8* [ %57, %55 ], [ %27, %25 ]
%30 = phi i32 [ %49, %55 ], [ 0, %25 ]
store i8* %29, i8** @seq_read.buffer
br label %31
31: ; preds = %22, %28
%32 = phi i32 [ %30, %28 ], [ 0, %22 ]
br label %33
33: ; preds = %31, %46
%34 = phi i32 [ %32, %31 ], [ %49, %46 ]
br label %35
35: ; preds = %33, %35
%36 = call i32 @getc_unlocked(i32* %0)
%37 = call i64 @isspace(i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %35
39: ; preds = %35
%40 = load i32, i32* @EOF
%41 = icmp eq i32 %36, %40
br i1 %41, label %58, label %42
42: ; preds = %39
%43 = icmp eq i32 %36, 62
br i1 %43, label %44, label %46
44: ; preds = %42
%45 = call i32 @ungetc(i32 62, i32* %0)
br label %58
46: ; preds = %42
%47 = call signext i8 @toupper(i32 %36)
%48 = load i8*, i8** @seq_read.buffer
%49 = add nsw i32 %34, 1
%50 = sext i32 %34 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 %47, i8* %51
%52 = load i32, i32* @seq_read.buffer_size
%53 = add nsw i32 %52, -2
%54 = icmp slt i32 %34, %53
br i1 %54, label %33, label %55
55: ; preds = %46
%56 = shl nsw i32 %52, 1
store i32 %56, i32* @seq_read.buffer_size
%57 = call i8* @realloc(i8* %48, i32 %56)
br label %28
58: ; preds = %39, %44
%59 = load i8*, i8** @seq_read.buffer
%60 = sext i32 %34 to i64
%61 = getelementptr inbounds i8, i8* %59, i64 %60
store i8 0, i8* %61
%62 = call %struct.seq* @seq_create(i8* %6, i8* %59, i8* %7)
br label %63
63: ; preds = %10, %1, %58
%64 = phi %struct.seq* [ %62, %58 ], [ null, %1 ], [ null, %10 ]
ret %struct.seq* %64
}