#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_SET;
int /*<<< orphan*/ calc_checksum(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
void write_checksum(char *tarname, int etype) {
  char checksum[7];
  char header[265];
  FILE *tar;
  tar = fopen(tarname, "rb+");
  fread(header, 265, 1, tar);
  calc_checksum(header, checksum);
  fseek(tar, 148, SEEK_SET);
  fputs(checksum, tar);
  fclose(tar);
}


x86 assembly (clang, -O0):
<write_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rcx
mov    $0x109,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
lea    -0x120(%rbp),%rdi
lea    -0x13(%rbp),%rsi
call   1060 <calc_checksum@plt>
mov    -0x128(%rbp),%rdi
mov    0x2e1c(%rip),%rax
mov    (%rax),%edx
mov    $0x94,%esi
call   1070 <fseek@plt>
lea    -0x13(%rbp),%rdi
mov    -0x128(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x128(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_checksum>:
push   %r15
push   %r14
push   %rbx
sub    $0x120,%rsp
lea    0xe8d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x109,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
lea    0x9(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <calc_checksum@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x94,%esi
call   1070 <fseek@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x120,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"rb+\00"
@SEEK_SET = global i32 0
define void @write_checksum(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [7 x i8]
%6 = alloca [265 x i8]
%7 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
%10 = getelementptr inbounds [265 x i8], [265 x i8]* %6, i64 0, i64 0
%11 = load i32*, i32** %7
%12 = call i32 @fread(i8* %10, i32 265, i32 1, i32* %11)
%13 = getelementptr inbounds [265 x i8], [265 x i8]* %6, i64 0, i64 0
%14 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%15 = call i32 @calc_checksum(i8* %13, i8* %14)
%16 = load i32*, i32** %7
%17 = load i32, i32* @SEEK_SET
%18 = call i32 @fseek(i32* %16, i32 148, i32 %17)
%19 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%20 = load i32*, i32** %7
%21 = call i32 @fputs(i8* %19, i32* %20)
%22 = load i32*, i32** %7
%23 = call i32 @fclose(i32* %22)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"rb+\00"
@SEEK_SET = global i32 0
define void @write_checksum(i8* nocapture %0, i32 %1) {
%3 = alloca [7 x i8]
%4 = alloca [265 x i8]
%5 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [265 x i8], [265 x i8]* %4, i64 0, i64 0
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @fread(i8* %6, i32 265, i32 1, i32* %7)
%9 = call i32 @calc_checksum(i8* %6, i8* %5)
%10 = load i32, i32* @SEEK_SET
%11 = call i32 @fseek(i32* %7, i32 148, i32 %10)
%12 = call i32 @fputs(i8* %5, i32* %7)
%13 = call i32 @fclose(i32* %7)
ret void
}