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

/* Variables and functions */
int /*<<< orphan*/ dec_to_octal(int, char *);
int /*<<< orphan*/ padded_octal(char *, int, char *);
void calc_checksum(char *header, char *pchecksum) {
  int checksum = 0;
  char ochecksum[100];
  int i;
  for (i = 0; i < 265; i++) {
    checksum += (int)header[i];
  }
  dec_to_octal(checksum - 64, ochecksum);
  padded_octal(ochecksum, 6, pchecksum);
}


x86 assembly (clang, -O0):
<calc_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x84(%rbp)
cmpl   $0x109,-0x84(%rbp)
jge    117d <calc_checksum+0x5d>
mov    -0x8(%rbp),%rax
movslq -0x84(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    1144 <calc_checksum+0x24>
mov    -0x14(%rbp),%edi
sub    $0x40,%edi
lea    -0x80(%rbp),%rsi
call   1030 <dec_to_octal@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x6,%esi
call   1040 <padded_octal@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_checksum>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r14
pxor   %xmm0,%xmm0
mov    $0x14,%eax
pxor   %xmm1,%xmm1
nopw   0x0(%rax,%rax,1)
movd   -0x14(%rdi,%rax,1),%xmm2
punpcklbw %xmm2,%xmm2
punpcklwd %xmm2,%xmm3
movd   -0x10(%rdi,%rax,1),%xmm2
punpcklbw %xmm2,%xmm2
punpcklwd %xmm2,%xmm2
psrad  $0x18,%xmm3
paddd  %xmm0,%xmm3
psrad  $0x18,%xmm2
paddd  %xmm1,%xmm2
movd   -0xc(%rdi,%rax,1),%xmm0
punpcklbw %xmm0,%xmm0
punpcklwd %xmm0,%xmm4
movd   -0x8(%rdi,%rax,1),%xmm0
punpcklbw %xmm0,%xmm0
punpcklwd %xmm0,%xmm5
psrad  $0x18,%xmm4
psrad  $0x18,%xmm5
movd   -0x4(%rdi,%rax,1),%xmm0
punpcklbw %xmm0,%xmm0
punpcklwd %xmm0,%xmm0
movd   (%rdi,%rax,1),%xmm1
punpcklbw %xmm1,%xmm1
punpcklwd %xmm1,%xmm1
psrad  $0x18,%xmm0
paddd  %xmm4,%xmm0
paddd  %xmm3,%xmm0
psrad  $0x18,%xmm1
paddd  %xmm5,%xmm1
paddd  %xmm2,%xmm1
add    $0x18,%rax
cmp    $0x11c,%rax
jne    1140 <calc_checksum+0x20>
paddd  %xmm0,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddd  %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%eax
movsbl 0x108(%rdi),%ecx
lea    (%rax,%rcx,1),%edi
add    $0xffffffc0,%edi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1030 <dec_to_octal@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
mov    %r14,%rdx
call   1040 <padded_octal@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @calc_checksum(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [100 x i8]
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32 0, i32* %7
br label %8
8: ; preds = %20, %2
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 265
br i1 %10, label %11, label %23
11: ; preds = %8
%12 = load i8*, i8** %3
%13 = load i32, i32* %7
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = load i32, i32* %5
%19 = add nsw i32 %18, %17
store i32 %19, i32* %5
br label %20
20: ; preds = %11
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 1
store i32 %22, i32* %7
br label %8
23: ; preds = %8
%24 = load i32, i32* %5
%25 = sub nsw i32 %24, 64
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%27 = call i32 @dec_to_octal(i32 %25, i8* %26)
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%29 = load i8*, i8** %4
%30 = call i32 @padded_octal(i8* %28, i32 6, i8* %29)
ret void
}

LLVM IR (-O2):
define void @calc_checksum(i8* nocapture %0, i8* %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %5, %2
%6 = phi i64 [ 0, %2 ], [ %41, %5 ]
%7 = phi <4 x i32> [ zeroinitializer, %2 ], [ %39, %5 ]
%8 = phi <4 x i32> [ zeroinitializer, %2 ], [ %40, %5 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %6
%10 = bitcast i8* %9 to <4 x i8>*
%11 = load <4 x i8>, <4 x i8>* %10
%12 = getelementptr inbounds i8, i8* %9, i64 4
%13 = bitcast i8* %12 to <4 x i8>*
%14 = load <4 x i8>, <4 x i8>* %13
%15 = sext <4 x i8> %11 to <4 x i32>
%16 = sext <4 x i8> %14 to <4 x i32>
%17 = add <4 x i32> %7, %15
%18 = add <4 x i32> %8, %16
%19 = add nuw nsw i64 %6, 8
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = bitcast i8* %20 to <4 x i8>*
%22 = load <4 x i8>, <4 x i8>* %21
%23 = getelementptr inbounds i8, i8* %20, i64 4
%24 = bitcast i8* %23 to <4 x i8>*
%25 = load <4 x i8>, <4 x i8>* %24
%26 = sext <4 x i8> %22 to <4 x i32>
%27 = sext <4 x i8> %25 to <4 x i32>
%28 = add <4 x i32> %17, %26
%29 = add <4 x i32> %18, %27
%30 = add nuw nsw i64 %6, 16
%31 = getelementptr inbounds i8, i8* %0, i64 %30
%32 = bitcast i8* %31 to <4 x i8>*
%33 = load <4 x i8>, <4 x i8>* %32
%34 = getelementptr inbounds i8, i8* %31, i64 4
%35 = bitcast i8* %34 to <4 x i8>*
%36 = load <4 x i8>, <4 x i8>* %35
%37 = sext <4 x i8> %33 to <4 x i32>
%38 = sext <4 x i8> %36 to <4 x i32>
%39 = add <4 x i32> %28, %37
%40 = add <4 x i32> %29, %38
%41 = add nuw nsw i64 %6, 24
%42 = icmp eq i64 %41, 264
br i1 %42, label %43, label %5
43: ; preds = %5
%44 = add <4 x i32> %40, %39
%45 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %44)
%46 = getelementptr inbounds i8, i8* %0, i64 264
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = add nsw i32 %45, %48
%50 = add nsw i32 %49, -64
%51 = call i32 @dec_to_octal(i32 %50, i8* %4)
%52 = call i32 @padded_octal(i8* %4, i32 6, i8* %1)
ret void
}