#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 _tar_error(char const *, int);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ *stdin;
int _tar_seek(FILE *fp, char const *archive, size_t count) {
  char buf[512];
  size_t step;
  if (fp == stdin)
    for (; count != 0; count -= step) {
      if ((step = count % 512) == 0)
        step = 512;
      if (fread(buf, sizeof(*buf), step, fp) != step)
        return _tar_error(archive, 1);
    }
  else if (fseek(fp, count, SEEK_CUR) != 0)
    return _tar_error(archive, 1);
  return 0;
}


x86 assembly (clang, -O0):
<_tar_seek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e8e(%rip),%rcx
cmp    (%rcx),%rax
jne    11f1 <_tar_seek+0xc1>
jmp    1160 <_tar_seek+0x30>
cmpq   $0x0,-0x20(%rbp)
je     11ec <_tar_seek+0xbc>
mov    -0x20(%rbp),%rax
and    $0x1ff,%rax
mov    %rax,-0x228(%rbp)
cmp    $0x0,%rax
jne    1191 <_tar_seek+0x61>
movq   $0x200,-0x228(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x228(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
cmp    -0x228(%rbp),%rax
je     11d0 <_tar_seek+0xa0>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1030 <_tar_error@plt>
mov    %eax,-0x4(%rbp)
jmp    1233 <_tar_seek+0x103>
jmp    11d5 <_tar_seek+0xa5>
mov    -0x228(%rbp),%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    1160 <_tar_seek+0x30>
jmp    122c <_tar_seek+0xfc>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2de8(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
cmp    $0x0,%rax
je     1227 <_tar_seek+0xf7>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1030 <_tar_error@plt>
mov    %eax,-0x4(%rbp)
jmp    1233 <_tar_seek+0x103>
jmp    122c <_tar_seek+0xfc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_tar_seek>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e8f(%rip),%rax
cmp    %rdi,(%rax)
je     118d <_tar_seek+0x5d>
mov    0x2e8b(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    %r13,%rsi
call   1050 <fseek@plt>
test   %rax,%rax
je     11cd <_tar_seek+0x9d>
mov    %r14,%rdi
mov    $0x1,%esi
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <_tar_error@plt>
test   %r13,%r13
je     11cd <_tar_seek+0x9d>
mov    $0x200,%ebp
mov    %rsp,%r12
nopw   0x0(%rax,%rax,1)
mov    %r13d,%ebx
and    $0x1ff,%ebx
test   %rbx,%rbx
cmove  %rbp,%rbx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1040 <fread@plt>
cmp    %rbx,%rax
jne    116f <_tar_seek+0x3f>
sub    %rbx,%r13
jne    11a0 <_tar_seek+0x70>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32* null
@SEEK_CUR = global i32 0
define i32 @_tar_seek(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [512 x i8]
%9 = alloca i64
store i32* %0, i32** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%10 = load i32*, i32** %5
%11 = load i32*, i32** @stdin
%12 = icmp eq i32* %10, %11
br i1 %12, label %13, label %38
13: ; preds = %3
br label %14
14: ; preds = %33, %13
%15 = load i64, i64* %7
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %37
17: ; preds = %14
%18 = load i64, i64* %7
%19 = urem i64 %18, 512
store i64 %19, i64* %9
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i64 512, i64* %9
br label %22
22: ; preds = %21, %17
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%24 = load i64, i64* %9
%25 = load i32*, i32** %5
%26 = call i64 @fread(i8* %23, i32 1, i64 %24, i32* %25)
%27 = load i64, i64* %9
%28 = icmp ne i64 %26, %27
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i8*, i8** %6
%31 = call i32 @_tar_error(i8* %30, i32 1)
store i32 %31, i32* %4
br label %49
32: ; preds = %22
br label %33
33: ; preds = %32
%34 = load i64, i64* %9
%35 = load i64, i64* %7
%36 = sub i64 %35, %34
store i64 %36, i64* %7
br label %14
37: ; preds = %14
br label %48
38: ; preds = %3
%39 = load i32*, i32** %5
%40 = load i64, i64* %7
%41 = load i32, i32* @SEEK_CUR
%42 = call i64 @fseek(i32* %39, i64 %40, i32 %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %38
%45 = load i8*, i8** %6
%46 = call i32 @_tar_error(i8* %45, i32 1)
store i32 %46, i32* %4
br label %49
47: ; preds = %38
br label %48
48: ; preds = %47, %37
store i32 0, i32* %4
br label %49
49: ; preds = %48, %44, %29
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
@stdin = global i32* null
@SEEK_CUR = global i32 0
define i32 @_tar_seek(i32* nocapture %0, i8* %1, i64 %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%6 = load i32*, i32** @stdin
%7 = icmp eq i32* %6, %0
br i1 %7, label %8, label %20
8: ; preds = %3
%9 = icmp eq i64 %2, 0
br i1 %9, label %26, label %12
10: ; preds = %12
%11 = icmp eq i64 %19, 0
br i1 %11, label %26, label %12
12: ; preds = %8, %10
%13 = phi i64 [ %19, %10 ], [ %2, %8 ]
%14 = and i64 %13, 511
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i64 512, i64 %14
%17 = call i64 @fread(i8* %5, i32 1, i64 %16, i32* %0)
%18 = icmp eq i64 %17, %16
%19 = sub i64 %13, %16
br i1 %18, label %10, label %24
20: ; preds = %3
%21 = load i32, i32* @SEEK_CUR
%22 = tail call i64 @fseek(i32* %0, i64 %2, i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %12, %20
%25 = tail call i32 @_tar_error(i8* %1, i32 1)
br label %26
26: ; preds = %10, %24, %8, %20
%27 = phi i32 [ 0, %20 ], [ 0, %8 ], [ %25, %24 ], [ 0, %10 ]
ret i32 %27
}