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

/* Variables and functions */
int gzwrite(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ memcpy(char *, char const *const, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ tar_write_header(int /*<<< orphan*/, char *);
int tar_write_long_link_header(gzFile f, char header[512], int link_length,
                               const char *const data) {
  if (tar_write_header(f, header) < 0) {
    return (-21);
  }
  int i;
  for (i = 0; i < link_length + 1; i += 512) {
    int o = link_length + 1 - i;
    if (o > 512) {
      o = 512;
    }
    memset(header, 0, 512);
    memcpy(header, data + i, o);
    if (gzwrite(f, header, 512) != 512) {
      return (-23);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<tar_write_long_link_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <tar_write_header@plt>
cmp    $0x0,%rax
jge    1178 <tar_write_long_link_header+0x38>
movl   $0xffffffeb,-0x4(%rbp)
jmp    121b <tar_write_long_link_header+0xdb>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1214 <tar_write_long_link_header+0xd4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x200,-0x28(%rbp)
jle    11b0 <tar_write_long_link_header+0x70>
movl   $0x200,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
mov    -0x28(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x200,%edx
call   1060 <gzwrite@plt>
cmp    $0x200,%eax
je     11ff <tar_write_long_link_header+0xbf>
movl   $0xffffffe9,-0x4(%rbp)
jmp    121b <tar_write_long_link_header+0xdb>
jmp    1204 <tar_write_long_link_header+0xc4>
mov    -0x24(%rbp),%eax
add    $0x200,%eax
mov    %eax,-0x24(%rbp)
jmp    117f <tar_write_long_link_header+0x3f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tar_write_long_link_header>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,(%rsp)
mov    %edx,%r15d
mov    %rsi,%r13
mov    %edi,%r12d
call   1030 <tar_write_header@plt>
test   %rax,%rax
js     11cc <tar_write_long_link_header+0x8c>
test   %r15d,%r15d
js     11c8 <tar_write_long_link_header+0x88>
lea    0x1(%r15),%ebx
xor    %r14d,%r14d
xchg   %ax,%ax
cmp    $0x200,%ebx
mov    $0x200,%ebp
cmovl  %ebx,%ebp
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
mov    (%rsp),%rax
lea    (%rax,%r14,1),%rsi
mov    %r13,%rdi
mov    %ebp,%edx
call   1050 <memcpy@plt>
mov    %r12d,%edi
mov    %r13,%rsi
mov    $0x200,%edx
call   1060 <gzwrite@plt>
cmp    $0x200,%eax
jne    11d3 <tar_write_long_link_header+0x93>
add    $0x200,%r14
add    $0xfffffe00,%ebx
cmp    %r15d,%r14d
jle    1170 <tar_write_long_link_header+0x30>
xor    %eax,%eax
jmp    11d8 <tar_write_long_link_header+0x98>
mov    $0xffffffeb,%eax
jmp    11d8 <tar_write_long_link_header+0x98>
mov    $0xffffffe9,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @tar_write_long_link_header(i32 %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%12 = load i32, i32* %6
%13 = load i8*, i8** %7
%14 = call i64 @tar_write_header(i32 %12, i8* %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 -21, i32* %5
br label %51
17: ; preds = %4
store i32 0, i32* %10
br label %18
18: ; preds = %47, %17
%19 = load i32, i32* %10
%20 = load i32, i32* %8
%21 = add nsw i32 %20, 1
%22 = icmp slt i32 %19, %21
br i1 %22, label %23, label %50
23: ; preds = %18
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
%26 = load i32, i32* %10
%27 = sub nsw i32 %25, %26
store i32 %27, i32* %11
%28 = load i32, i32* %11
%29 = icmp sgt i32 %28, 512
br i1 %29, label %30, label %31
30: ; preds = %23
store i32 512, i32* %11
br label %31
31: ; preds = %30, %23
%32 = load i8*, i8** %7
%33 = call i32 @memset(i8* %32, i32 0, i32 512)
%34 = load i8*, i8** %7
%35 = load i8*, i8** %9
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i32, i32* %11
%40 = call i32 @memcpy(i8* %34, i8* %38, i32 %39)
%41 = load i32, i32* %6
%42 = load i8*, i8** %7
%43 = call i32 @gzwrite(i32 %41, i8* %42, i32 512)
%44 = icmp ne i32 %43, 512
br i1 %44, label %45, label %46
45: ; preds = %31
store i32 -23, i32* %5
br label %51
46: ; preds = %31
br label %47
47: ; preds = %46
%48 = load i32, i32* %10
%49 = add nsw i32 %48, 512
store i32 %49, i32* %10
br label %18
50: ; preds = %18
store i32 0, i32* %5
br label %51
51: ; preds = %50, %45, %16
%52 = load i32, i32* %5
ret i32 %52
}

LLVM IR (-O2):
define i32 @tar_write_long_link_header(i32 %0, i8* %1, i32 %2, i8* %3) {
%5 = tail call i64 @tar_write_header(i32 %0, i8* %1)
%6 = icmp slt i64 %5, 0
br i1 %6, label %25, label %7
7: ; preds = %4
%8 = add nsw i32 %2, 1
%9 = icmp slt i32 %2, 0
br i1 %9, label %25, label %13
10: ; preds = %13
%11 = trunc i64 %24 to i32
%12 = icmp sgt i32 %11, %2
br i1 %12, label %25, label %13
13: ; preds = %7, %10
%14 = phi i64 [ %24, %10 ], [ 0, %7 ]
%15 = trunc i64 %14 to i32
%16 = sub i32 %8, %15
%17 = icmp slt i32 %16, 512
%18 = select i1 %17, i32 %16, i32 512
%19 = tail call i32 @memset(i8* %1, i32 0, i32 512)
%20 = getelementptr inbounds i8, i8* %3, i64 %14
%21 = tail call i32 @memcpy(i8* %1, i8* %20, i32 %18)
%22 = tail call i32 @gzwrite(i32 %0, i8* %1, i32 512)
%23 = icmp eq i32 %22, 512
%24 = add nuw i64 %14, 512
br i1 %23, label %10, label %25
25: ; preds = %10, %13, %7, %4
%26 = phi i32 [ -21, %4 ], [ 0, %7 ], [ 0, %10 ], [ -23, %13 ]
ret i32 %26
}