#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*/ sprintf(char *, char *, unsigned int);
int tar_write_header(gzFile f, char b[512]) {
  unsigned chksum = 8 * 32;
  int i;
  for (i = 0; i < 512; i++) {
    chksum += (unsigned char)b[i];
  }
  chksum &= 0777777;
  sprintf(b + 148, "%06o", chksum);
  b[155] = ' ';
  return gzwrite(f, b, 512) == 512 ? 0 : -1;
}


x86 assembly (clang, -O0):
<tar_write_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x100,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x200,-0x18(%rbp)
jge    116a <tar_write_header+0x4a>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113d <tar_write_header+0x1d>
mov    -0x14(%rbp),%eax
and    $0x3ffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x94,%rdi
mov    -0x14(%rbp),%edx
lea    0xe76(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rax
movb   $0x20,0x9b(%rax)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x200,%edx
call   1030 <gzwrite@plt>
mov    %eax,%edx
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    $0x200,%edx
cmove  %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tar_write_header>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
pxor   %xmm0,%xmm0
movdqa 0xecc(%rip),%xmm2
mov    $0xc,%eax
pxor   %xmm1,%xmm1
nopl   (%rax)
movd   -0xc(%rbx,%rax,1),%xmm3
movd   -0x8(%rbx,%rax,1),%xmm4
punpcklbw %xmm0,%xmm3
punpcklwd %xmm0,%xmm3
paddd  %xmm2,%xmm3
punpcklbw %xmm0,%xmm4
punpcklwd %xmm0,%xmm4
paddd  %xmm1,%xmm4
movd   -0x4(%rbx,%rax,1),%xmm2
movd   (%rbx,%rax,1),%xmm1
punpcklbw %xmm0,%xmm2
punpcklwd %xmm0,%xmm2
paddd  %xmm3,%xmm2
punpcklbw %xmm0,%xmm1
punpcklwd %xmm0,%xmm1
paddd  %xmm4,%xmm1
add    $0x10,%rax
cmp    $0x20c,%rax
jne    1140 <tar_write_header+0x20>
paddd  %xmm2,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddd  %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%edx
and    $0x3ffff,%edx
lea    0x94(%rbx),%rdi
lea    0xe4f(%rip),%rsi
call   1040 <sprintf@plt>
movb   $0x20,0x9b(%rbx)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1030 <gzwrite@plt>
xor    %ecx,%ecx
cmp    $0x200,%eax
setne  %cl
neg    %ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%06o\00"
define i32 @tar_write_header(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 256, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %19, %2
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 512
br i1 %9, label %10, label %22
10: ; preds = %7
%11 = load i8*, i8** %4
%12 = load i32, i32* %6
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = load i32, i32* %5
%18 = add i32 %17, %16
store i32 %18, i32* %5
br label %19
19: ; preds = %10
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
br label %7
22: ; preds = %7
%23 = load i32, i32* %5
%24 = and i32 %23, 262143
store i32 %24, i32* %5
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 148
%27 = load i32, i32* %5
%28 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i64 155
store i8 32, i8* %30
%31 = load i32, i32* %3
%32 = load i8*, i8** %4
%33 = call i32 @gzwrite(i32 %31, i8* %32, i32 512)
%34 = icmp eq i32 %33, 512
%35 = zext i1 %34 to i64
%36 = select i1 %34, i32 0, i32 -1
ret i32 %36
}

LLVM IR (-O2):
@.str = [5 x i8] c"%06o\00"
define i32 @tar_write_header(i32 %0, i8* %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i64 [ 0, %2 ], [ %28, %3 ]
%5 = phi <4 x i32> [ <i32 256, i32 0, i32 0, i32 0>, %2 ], [ %26, %3 ]
%6 = phi <4 x i32> [ zeroinitializer, %2 ], [ %27, %3 ]
%7 = getelementptr inbounds i8, i8* %1, i64 %4
%8 = bitcast i8* %7 to <4 x i8>*
%9 = load <4 x i8>, <4 x i8>* %8
%10 = getelementptr inbounds i8, i8* %7, i64 4
%11 = bitcast i8* %10 to <4 x i8>*
%12 = load <4 x i8>, <4 x i8>* %11
%13 = zext <4 x i8> %9 to <4 x i32>
%14 = zext <4 x i8> %12 to <4 x i32>
%15 = add <4 x i32> %5, %13
%16 = add <4 x i32> %6, %14
%17 = or i64 %4, 8
%18 = getelementptr inbounds i8, i8* %1, i64 %17
%19 = bitcast i8* %18 to <4 x i8>*
%20 = load <4 x i8>, <4 x i8>* %19
%21 = getelementptr inbounds i8, i8* %18, i64 4
%22 = bitcast i8* %21 to <4 x i8>*
%23 = load <4 x i8>, <4 x i8>* %22
%24 = zext <4 x i8> %20 to <4 x i32>
%25 = zext <4 x i8> %23 to <4 x i32>
%26 = add <4 x i32> %15, %24
%27 = add <4 x i32> %16, %25
%28 = add nuw nsw i64 %4, 16
%29 = icmp eq i64 %28, 512
br i1 %29, label %30, label %3
30: ; preds = %3
%31 = add <4 x i32> %27, %26
%32 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %31)
%33 = and i32 %32, 262143
%34 = getelementptr inbounds i8, i8* %1, i64 148
%35 = tail call i32 @sprintf(i8* %34, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %33)
%36 = getelementptr inbounds i8, i8* %1, i64 155
store i8 32, i8* %36
%37 = tail call i32 @gzwrite(i32 %0, i8* %1, i32 512)
%38 = icmp ne i32 %37, 512
%39 = sext i1 %38 to i32
ret i32 %39
}