#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_CUR;
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, size_t, int /*<<< orphan*/);
size_t strlen(char const *);
int seek_to_tar_position(FILE *in) {
  const char *find = "ustar";
  const char *finding = find;
  char buf[4096];
  while (!feof(in)) {
    size_t bytes_read = fread(buf, 1, 4096, in);
    size_t bytes_left = bytes_read;
    char *working;
    for (working = buf; bytes_left > 0; --bytes_left, ++working) {
      if (*working == *finding) {
        finding++;
        if (*finding == '\0') {
          break;
        }
      } else {
        finding = find;
      }
    }
    if (bytes_left != 0) {
      (void)fseek(in, -bytes_left - 256 - strlen(find), SEEK_CUR);
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<seek_to_tar_position>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1180 <seek_to_tar_position+0x40>
jmp    12a8 <seek_to_tar_position+0x168>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %rax,-0x1028(%rbp)
mov    -0x1028(%rbp),%rax
mov    %rax,-0x1030(%rbp)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1038(%rbp)
cmpq   $0x0,-0x1030(%rbp)
jbe    1240 <seek_to_tar_position+0x100>
mov    -0x1038(%rbp),%rax
movsbl (%rax),%eax
mov    -0x20(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    120a <seek_to_tar_position+0xca>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1205 <seek_to_tar_position+0xc5>
jmp    1240 <seek_to_tar_position+0x100>
jmp    1212 <seek_to_tar_position+0xd2>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1217 <seek_to_tar_position+0xd7>
mov    -0x1030(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x1030(%rbp)
mov    -0x1038(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1038(%rbp)
jmp    11bd <seek_to_tar_position+0x7d>
cmpq   $0x0,-0x1030(%rbp)
je     12a3 <seek_to_tar_position+0x163>
mov    -0x10(%rbp),%rax
mov    %rax,-0x1040(%rbp)
xor    %eax,%eax
sub    -0x1030(%rbp),%rax
sub    $0x100,%rax
mov    %rax,-0x1048(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1048(%rbp),%rsi
mov    -0x1040(%rbp),%rdi
sub    %rax,%rsi
mov    0x2d58(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
movl   $0x0,-0x4(%rbp)
jmp    12af <seek_to_tar_position+0x16f>
jmp    1162 <seek_to_tar_position+0x22>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seek_to_tar_position>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1000,%rsp
mov    %rdi,%r15
call   1040 <feof@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
jne    11f3 <seek_to_tar_position+0xc3>
lea    0xea2(%rip),%r12
mov    %rsp,%r14
mov    %r12,%rbx
jmp    1186 <seek_to_tar_position+0x56>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%r13
mov    %r15,%rdi
call   1040 <feof@plt>
mov    %r13,%rbx
test   %eax,%eax
jne    1204 <seek_to_tar_position+0xd4>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     1170 <seek_to_tar_position+0x40>
add    $0x105,%rax
mov    %r14,%rcx
jmp    11ca <seek_to_tar_position+0x9a>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %rbx,%r13
add    $0x1,%rcx
add    $0xffffffffffffffff,%rax
mov    %r13,%rbx
cmp    $0x105,%rax
je     1173 <seek_to_tar_position+0x43>
movzbl (%rcx),%edx
mov    %r12,%r13
cmp    (%rbx),%dl
jne    11b7 <seek_to_tar_position+0x87>
cmpb   $0x0,0x1(%rbx)
jne    11b0 <seek_to_tar_position+0x80>
neg    %rax
mov    0x2e04(%rip),%rcx
mov    (%rcx),%edx
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <fseek@plt>
xor    %eax,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    $0x1,%eax
jmp    11f3 <seek_to_tar_position+0xc3>

LLVM IR (-O0):
@.str = [6 x i8] c"ustar\00"
@SEEK_CUR = global i32 0
define i32 @seek_to_tar_position(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [4096 x i8]
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
store i32* %0, i32** %3
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %4
%10 = load i8*, i8** %4
store i8* %10, i8** %5
br label %11
11: ; preds = %63, %1
%12 = load i32*, i32** %3
%13 = call i32 @feof(i32* %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %64
16: ; preds = %11
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%18 = load i32*, i32** %3
%19 = call i64 @fread(i8* %17, i32 1, i32 4096, i32* %18)
store i64 %19, i64* %7
%20 = load i64, i64* %7
store i64 %20, i64* %8
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
store i8* %21, i8** %9
br label %22
22: ; preds = %45, %16
%23 = load i64, i64* %8
%24 = icmp ugt i64 %23, 0
br i1 %24, label %25, label %50
25: ; preds = %22
%26 = load i8*, i8** %9
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = load i8*, i8** %5
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %28, %31
br i1 %32, label %33, label %42
33: ; preds = %25
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %5
%36 = load i8*, i8** %5
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %33
br label %50
41: ; preds = %33
br label %44
42: ; preds = %25
%43 = load i8*, i8** %4
store i8* %43, i8** %5
br label %44
44: ; preds = %42, %41
br label %45
45: ; preds = %44
%46 = load i64, i64* %8
%47 = add i64 %46, -1
store i64 %47, i64* %8
%48 = load i8*, i8** %9
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %9
br label %22
50: ; preds = %40, %22
%51 = load i64, i64* %8
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %63
53: ; preds = %50
%54 = load i32*, i32** %3
%55 = load i64, i64* %8
%56 = sub i64 0, %55
%57 = sub i64 %56, 256
%58 = load i8*, i8** %4
%59 = call i64 @strlen(i8* %58)
%60 = sub i64 %57, %59
%61 = load i32, i32* @SEEK_CUR
%62 = call i32 @fseek(i32* %54, i64 %60, i32 %61)
store i32 0, i32* %2
br label %65
63: ; preds = %50
br label %11
64: ; preds = %11
store i32 1, i32* %2
br label %65
65: ; preds = %64, %53
%66 = load i32, i32* %2
ret i32 %66
}

LLVM IR (-O2):
@.str = [6 x i8] c"ustar\00"
@SEEK_CUR = global i32 0
define i32 @seek_to_tar_position(i32* nocapture %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @feof(i32* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %10, label %34
6: ; preds = %25, %10
%7 = phi i8* [ %11, %10 ], [ %26, %25 ]
%8 = tail call i32 @feof(i32* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %34
10: ; preds = %1, %6
%11 = phi i8* [ %7, %6 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %1 ]
%12 = call i64 @fread(i8* %3, i32 1, i32 4096, i32* %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %6, label %14
14: ; preds = %10, %25
%15 = phi i8* [ %28, %25 ], [ %3, %10 ]
%16 = phi i64 [ %27, %25 ], [ %12, %10 ]
%17 = phi i8* [ %26, %25 ], [ %11, %10 ]
%18 = load i8, i8* %15
%19 = load i8, i8* %17
%20 = icmp eq i8 %18, %19
br i1 %20, label %21, label %25
21: ; preds = %14
%22 = getelementptr inbounds i8, i8* %17, i64 1
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %14, %21
%26 = phi i8* [ %22, %21 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %14 ]
%27 = add i64 %16, -1
%28 = getelementptr inbounds i8, i8* %15, i64 1
%29 = icmp eq i64 %27, 0
br i1 %29, label %6, label %14
30: ; preds = %21
%31 = sub i64 -261, %16
%32 = load i32, i32* @SEEK_CUR
%33 = tail call i32 @fseek(i32* %0, i64 %31, i32 %32)
br label %34
34: ; preds = %6, %1, %30
%35 = phi i32 [ 0, %30 ], [ 1, %1 ], [ 1, %6 ]
ret i32 %35
}