#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*/ FILE;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ isspace(char);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ *safe_fopen(char const *, char *);
scalar_t__ safe_malloc(int);
int /*<<< orphan*/ skip_header(int /*<<< orphan*/ *);
char *sequence_from_file(const char *fn) {
  char *s = 0;
  int n;
  char c;
  FILE *f = safe_fopen(fn, "r");
  skip_header(f);
  n = 0;
  while ((c = fgetc(f)), c != EOF && c != '1')
    if (!isspace(c))
      n++;
  s = (char *)safe_malloc(n + 1);
  rewind(f);
  skip_header(f);
  n = 0;
  while ((c = fgetc(f)), c != EOF && c != '1')
    if (!isspace(c))
      s[n++] = c;
  s[n] = 0;
  fclose(f);
  return s;
}


x86 assembly (clang, -O0):
<sequence_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1090 <safe_fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <skip_header@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%ecx
mov    0x2e29(%rip),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x21(%rbp)
je     11dc <sequence_from_file+0x6c>
movsbl -0x15(%rbp),%eax
cmp    $0x31,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11ec <sequence_from_file+0x7c>
jmp    120c <sequence_from_file+0x9c>
movsbl -0x15(%rbp),%edi
call   1080 <isspace@plt>
cmp    $0x0,%eax
jne    1207 <sequence_from_file+0x97>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a8 <sequence_from_file+0x38>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1030 <safe_malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x20(%rbp),%rdi
call   1040 <skip_header@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%ecx
mov    0x2d9d(%rip),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x22(%rbp)
je     1268 <sequence_from_file+0xf8>
movsbl -0x15(%rbp),%eax
cmp    $0x31,%eax
setne  %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    1278 <sequence_from_file+0x108>
jmp    12a7 <sequence_from_file+0x137>
movsbl -0x15(%rbp),%edi
call   1080 <isspace@plt>
cmp    $0x0,%eax
jne    12a2 <sequence_from_file+0x132>
mov    -0x15(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1234 <sequence_from_file+0xc4>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sequence_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe81(%rip),%rsi
call   1090 <safe_fopen@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <skip_header@plt>
mov    %r15,%rdi
call   1070 <fgetc@plt>
mov    0x2e4a(%rip),%r12
mov    $0x1,%ebp
cmp    $0x31,%al
je     11d3 <sequence_from_file+0x63>
cmp    (%r12),%al
je     11d3 <sequence_from_file+0x63>
xor    %ebp,%ebp
nop
movsbl %al,%edi
call   1080 <isspace@plt>
cmp    $0x1,%eax
adc    $0x0,%ebp
mov    %r15,%rdi
call   1070 <fgetc@plt>
cmp    $0x31,%al
je     11d0 <sequence_from_file+0x60>
cmp    (%r12),%al
jne    11b0 <sequence_from_file+0x40>
add    $0x1,%ebp
mov    %ebp,%edi
call   1030 <safe_malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1060 <rewind@plt>
mov    %r15,%rdi
call   1040 <skip_header@plt>
mov    %r15,%rdi
call   1070 <fgetc@plt>
xor    %ebp,%ebp
cmp    $0x31,%al
je     123a <sequence_from_file+0xca>
mov    %eax,%ebx
cmp    (%r12),%al
je     123a <sequence_from_file+0xca>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %bl,%edi
call   1080 <isspace@plt>
test   %eax,%eax
jne    1226 <sequence_from_file+0xb6>
movslq %ebp,%rax
add    $0x1,%ebp
mov    %bl,(%r14,%rax,1)
mov    %r15,%rdi
call   1070 <fgetc@plt>
cmp    $0x31,%al
je     123a <sequence_from_file+0xca>
mov    %eax,%ebx
cmp    (%r12),%al
jne    1210 <sequence_from_file+0xa0>
movslq %ebp,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
define i8* @sequence_from_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32*
store i8* %0, i8** %2
store i8* null, i8** %3
%7 = load i8*, i8** %2
%8 = call i32* @safe_fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = call i32 @skip_header(i32* %9)
store i32 0, i32* %4
br label %11
11: ; preds = %32, %1
%12 = load i32*, i32** %6
%13 = call signext i8 @fgetc(i32* %12)
store i8 %13, i8* %5
%14 = load i8, i8* %5
%15 = sext i8 %14 to i32
%16 = load i8, i8* @EOF
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %15, %17
br i1 %18, label %19, label %23
19: ; preds = %11
%20 = load i8, i8* %5
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 49
br label %23
23: ; preds = %19, %11
%24 = phi i1 [ false, %11 ], [ %22, %19 ]
br i1 %24, label %25, label %33
25: ; preds = %23
%26 = load i8, i8* %5
%27 = call i32 @isspace(i8 signext %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %32
32: ; preds = %29, %25
br label %11
33: ; preds = %23
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
%36 = call i64 @safe_malloc(i32 %35)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %3
%38 = load i32*, i32** %6
%39 = call i32 @rewind(i32* %38)
%40 = load i32*, i32** %6
%41 = call i32 @skip_header(i32* %40)
store i32 0, i32* %4
br label %42
42: ; preds = %67, %33
%43 = load i32*, i32** %6
%44 = call signext i8 @fgetc(i32* %43)
store i8 %44, i8* %5
%45 = load i8, i8* %5
%46 = sext i8 %45 to i32
%47 = load i8, i8* @EOF
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %46, %48
br i1 %49, label %50, label %54
50: ; preds = %42
%51 = load i8, i8* %5
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 49
br label %54
54: ; preds = %50, %42
%55 = phi i1 [ false, %42 ], [ %53, %50 ]
br i1 %55, label %56, label %68
56: ; preds = %54
%57 = load i8, i8* %5
%58 = call i32 @isspace(i8 signext %57)
%59 = icmp ne i32 %58, 0
br i1 %59, label %67, label %60
60: ; preds = %56
%61 = load i8, i8* %5
%62 = load i8*, i8** %3
%63 = load i32, i32* %4
%64 = add nsw i32 %63, 1
store i32 %64, i32* %4
%65 = sext i32 %63 to i64
%66 = getelementptr inbounds i8, i8* %62, i64 %65
store i8 %61, i8* %66
br label %67
67: ; preds = %60, %56
br label %42
68: ; preds = %54
%69 = load i8*, i8** %3
%70 = load i32, i32* %4
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
store i8 0, i8* %72
%73 = load i32*, i32** %6
%74 = call i32 @fclose(i32* %73)
%75 = load i8*, i8** %3
ret i8* %75
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
define i8* @sequence_from_file(i8* %0) {
%2 = tail call i32* @safe_fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @skip_header(i32* %2)
%4 = tail call signext i8 @fgetc(i32* %2)
%5 = load i8, i8* @EOF
%6 = icmp ne i8 %4, %5
%7 = icmp ne i8 %4, 49
%8 = and i1 %7, %6
br i1 %8, label %9, label %23
9: ; preds = %1, %9
%10 = phi i8 [ %16, %9 ], [ %4, %1 ]
%11 = phi i32 [ %15, %9 ], [ 0, %1 ]
%12 = tail call i32 @isspace(i8 signext %10)
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
%15 = add nuw nsw i32 %11, %14
%16 = tail call signext i8 @fgetc(i32* %2)
%17 = load i8, i8* @EOF
%18 = icmp ne i8 %16, %17
%19 = icmp ne i8 %16, 49
%20 = and i1 %19, %18
br i1 %20, label %9, label %21
21: ; preds = %9
%22 = add nuw i32 %15, 1
br label %23
23: ; preds = %21, %1
%24 = phi i32 [ 1, %1 ], [ %22, %21 ]
%25 = tail call i64 @safe_malloc(i32 %24)
%26 = inttoptr i64 %25 to i8*
%27 = tail call i32 @rewind(i32* %2)
%28 = tail call i32 @skip_header(i32* %2)
%29 = tail call signext i8 @fgetc(i32* %2)
%30 = load i8, i8* @EOF
%31 = icmp ne i8 %29, %30
%32 = icmp ne i8 %29, 49
%33 = and i1 %32, %31
br i1 %33, label %34, label %50
34: ; preds = %23, %43
%35 = phi i8 [ %45, %43 ], [ %29, %23 ]
%36 = phi i32 [ %44, %43 ], [ 0, %23 ]
%37 = tail call i32 @isspace(i8 signext %35)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = add nsw i32 %36, 1
%41 = sext i32 %36 to i64
%42 = getelementptr inbounds i8, i8* %26, i64 %41
store i8 %35, i8* %42
br label %43
43: ; preds = %39, %34
%44 = phi i32 [ %36, %34 ], [ %40, %39 ]
%45 = tail call signext i8 @fgetc(i32* %2)
%46 = load i8, i8* @EOF
%47 = icmp ne i8 %45, %46
%48 = icmp ne i8 %45, 49
%49 = and i1 %48, %47
br i1 %49, label %34, label %50
50: ; preds = %43, %23
%51 = phi i32 [ 0, %23 ], [ %44, %43 ]
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %26, i64 %52
store i8 0, i8* %53
%54 = tail call i32 @fclose(i32* %2)
ret i8* %26
}