#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 */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
long E_SkipHeader(FILE *input) {
  char buf[1024];
  long offset = 0;
  char *ptr = NULL;
  rewind(input);
  do {
    ptr = fgets(buf, 1024, input);
    if (buf[0] != '#') {
      fseek(input, offset, SEEK_SET);
      return offset;
    }
    offset = ftell(input);
  } while (!feof(input));
  return 0;
}


x86 assembly (clang, -O0):
<E_SkipHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x418(%rbp)
movq   $0x0,-0x420(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <rewind@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
mov    %rax,-0x420(%rbp)
movsbl -0x410(%rbp),%eax
cmp    $0x23,%eax
je     11d3 <E_SkipHeader+0x83>
mov    -0x10(%rbp),%rdi
mov    -0x418(%rbp),%rsi
mov    0x2e24(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    -0x418(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1204 <E_SkipHeader+0xb4>
mov    -0x10(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x418(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    117e <E_SkipHeader+0x2e>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<E_SkipHeader>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
call   1030 <rewind@plt>
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
cmpb   $0x23,(%rsp)
jne    11af <E_SkipHeader+0x5f>
mov    %rsp,%r15
nopl   (%rax)
mov    %r14,%rdi
call   1050 <ftell@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11c7 <E_SkipHeader+0x77>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
cmpb   $0x23,(%rsp)
je     1180 <E_SkipHeader+0x30>
jmp    11b1 <E_SkipHeader+0x61>
xor    %ebx,%ebx
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <fseek@plt>
jmp    11c9 <E_SkipHeader+0x79>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i64 @E_SkipHeader(i32* %0) {
%2 = alloca i64
%3 = alloca i32*
%4 = alloca [1024 x i8]
%5 = alloca i64
%6 = alloca i8*
store i32* %0, i32** %3
store i64 0, i64* %5
store i8* null, i8** %6
%7 = load i32*, i32** %3
%8 = call i32 @rewind(i32* %7)
br label %9
9: ; preds = %26, %1
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = load i32*, i32** %3
%12 = call i8* @fgets(i8* %10, i32 1024, i32* %11)
store i8* %12, i8** %6
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 35
br i1 %16, label %17, label %23
17: ; preds = %9
%18 = load i32*, i32** %3
%19 = load i64, i64* %5
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @fseek(i32* %18, i64 %19, i32 %20)
%22 = load i64, i64* %5
store i64 %22, i64* %2
br label %32
23: ; preds = %9
%24 = load i32*, i32** %3
%25 = call i64 @ftell(i32* %24)
store i64 %25, i64* %5
br label %26
26: ; preds = %23
%27 = load i32*, i32** %3
%28 = call i32 @feof(i32* %27)
%29 = icmp ne i32 %28, 0
%30 = xor i1 %29, true
br i1 %30, label %9, label %31
31: ; preds = %26
store i64 0, i64* %2
br label %32
32: ; preds = %31, %17
%33 = load i64, i64* %2
ret i64 %33
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i64 @E_SkipHeader(i32* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @rewind(i32* %0)
%5 = call i8* @fgets(i8* %3, i32 1024, i32* %0)
%6 = load i8, i8* %3
%7 = icmp eq i8 %6, 35
br i1 %7, label %16, label %12
8: ; preds = %16
%9 = call i8* @fgets(i8* %3, i32 1024, i32* %0)
%10 = load i8, i8* %3
%11 = icmp eq i8 %10, 35
br i1 %11, label %16, label %12
12: ; preds = %8, %1
%13 = phi i64 [ 0, %1 ], [ %17, %8 ]
%14 = load i32, i32* @SEEK_SET
%15 = call i32 @fseek(i32* %0, i64 %13, i32 %14)
br label %20
16: ; preds = %1, %8
%17 = call i64 @ftell(i32* %0)
%18 = call i32 @feof(i32* %0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %8, label %20
20: ; preds = %16, %12
%21 = phi i64 [ %13, %12 ], [ 0, %16 ]
ret i64 %21
}