#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*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ finalize_tar(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ get_file_modified(char *);
int /*<<< orphan*/ get_file_size(char *);
int /*<<< orphan*/ merge_entries(char *, char **, int);
int /*<<< orphan*/ p_write_tar_entry(char *, char *, int /*<<< orphan*/,
                                     int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ split(char *, char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ write_checksum(char *, int /*<<< orphan*/);
int write_tar_entries(char *tarname, char *manifest) {
  char line[10000];
  char unused[50];
  char tentry[50];
  char part[50];
  char file[50];
  char *entries[100];
  int i = 0;
  FILE *f;
  f = fopen(manifest, "r");
  while (fgets(line, sizeof(line), f)) {
    split(line, "\n", tentry, unused);
    split(tentry, ":", part, file);
    p_write_tar_entry(part, file, get_file_size(file), get_file_modified(file),
                      0);
    write_checksum(part, 0);
    strcpy(entries[i], part);
    i++;
  }
  fclose(f);
  merge_entries(tarname, entries, i);
  finalize_tar(tarname);
  return 0;
}


x86 assembly (clang, -O0):
<write_tar_entries>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2b70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2b44(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x2b50(%rbp)
lea    -0x2720(%rbp),%rdi
mov    -0x2b50(%rbp),%rdx
mov    $0x2710,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12dd <write_tar_entries+0x12d>
lea    -0x2720(%rbp),%rdi
lea    -0x27a0(%rbp),%rdx
lea    -0x2760(%rbp),%rcx
lea    0xde0(%rip),%rsi
call   1060 <split@plt>
lea    -0x27a0(%rbp),%rdi
lea    -0x27e0(%rbp),%rdx
lea    -0x2820(%rbp),%rcx
lea    0xdc1(%rip),%rsi
call   1060 <split@plt>
lea    -0x27e0(%rbp),%rax
mov    %rax,-0x2b68(%rbp)
lea    -0x2820(%rbp),%rax
mov    %rax,-0x2b60(%rbp)
lea    -0x2820(%rbp),%rdi
call   10a0 <get_file_size@plt>
mov    %eax,-0x2b54(%rbp)
lea    -0x2820(%rbp),%rdi
call   1040 <get_file_modified@plt>
mov    -0x2b68(%rbp),%rdi
mov    -0x2b60(%rbp),%rsi
mov    -0x2b54(%rbp),%edx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1090 <p_write_tar_entry@plt>
lea    -0x27e0(%rbp),%rdi
xor    %esi,%esi
call   10c0 <write_checksum@plt>
movslq -0x2b44(%rbp),%rax
mov    -0x2b40(%rbp,%rax,8),%rdi
ff
lea    -0x27e0(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x2b44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2b44(%rbp)
jmp    11e4 <write_tar_entries+0x34>
mov    -0x2b50(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x8(%rbp),%rdi
lea    -0x2b40(%rbp),%rsi
mov    -0x2b44(%rbp),%edx
call   1080 <merge_entries@plt>
mov    -0x8(%rbp),%rdi
call   10d0 <finalize_tar@plt>
xor    %eax,%eax
add    $0x2b70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_tar_entries>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2b48,%rsp
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xe32(%rip),%rsi
mov    %rax,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r15
lea    0x430(%rsp),%rdi
mov    $0x2710,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12b9 <write_tar_entries+0x109>
mov    %r14,0x8(%rsp)
xor    %ebx,%ebx
lea    0x50(%rsp),%r14
lea    0x10(%rsp),%r12
nopl   0x0(%rax,%rax,1)
lea    0x430(%rsp),%r13
mov    %r13,%rdi
lea    0xde0(%rip),%rsi
lea    0x90(%rsp),%rbp
mov    %rbp,%rdx
lea    0xd0(%rsp),%rcx
call   1060 <split@plt>
mov    %rbp,%rdi
lea    0xdc0(%rip),%rsi
mov    %r14,%rdx
mov    %r12,%rcx
call   1060 <split@plt>
mov    %r12,%rdi
call   10a0 <get_file_size@plt>
mov    %r15,%rbp
mov    %eax,%r15d
mov    %r12,%rdi
call   1040 <get_file_modified@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
mov    %rbp,%r15
mov    %eax,%ecx
xor    %r8d,%r8d
call   1090 <p_write_tar_entry@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   10c0 <write_checksum@plt>
mov    0x110(%rsp,%rbx,8),%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
add    $0x1,%rbx
mov    %r13,%rdi
mov    $0x2710,%esi
mov    %rbp,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    1210 <write_tar_entries+0x60>
mov    0x8(%rsp),%r14
jmp    12bb <write_tar_entries+0x10b>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1050 <fclose@plt>
lea    0x110(%rsp),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1080 <merge_entries@plt>
mov    %r14,%rdi
call   10d0 <finalize_tar@plt>
xor    %eax,%eax
add    $0x2b48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [2 x i8] c":\00"
define i32 @write_tar_entries(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [10000 x i8]
%6 = alloca [50 x i8]
%7 = alloca [50 x i8]
%8 = alloca [50 x i8]
%9 = alloca [50 x i8]
%10 = alloca [100 x i8*]
%11 = alloca i32
%12 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %11
%13 = load i8*, i8** %4
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %12
br label %15
15: ; preds = %20, %2
%16 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%17 = load i32*, i32** %12
%18 = call i64 @fgets(i8* %16, i32 10000, i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %46
20: ; preds = %15
%21 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%22 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%23 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%24 = call i32 @split(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %23)
%25 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%26 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%27 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%28 = call i32 @split(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %26, i8* %27)
%29 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%30 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%31 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%32 = call i32 @get_file_size(i8* %31)
%33 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%34 = call i32 @get_file_modified(i8* %33)
%35 = call i32 @p_write_tar_entry(i8* %29, i8* %30, i32 %32, i32 %34, i32 0)
%36 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%37 = call i32 @write_checksum(i8* %36, i32 0)
%38 = load i32, i32* %11
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [100 x i8*], [100 x i8*]* %10, i64 0, i64 %39
%41 = load i8*, i8** %40
%42 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%43 = call i32 @strcpy(i8* %41, i8* %42)
%44 = load i32, i32* %11
%45 = add nsw i32 %44, 1
store i32 %45, i32* %11
br label %15
46: ; preds = %15
%47 = load i32*, i32** %12
%48 = call i32 @fclose(i32* %47)
%49 = load i8*, i8** %3
%50 = getelementptr inbounds [100 x i8*], [100 x i8*]* %10, i64 0, i64 0
%51 = load i32, i32* %11
%52 = call i32 @merge_entries(i8* %49, i8** %50, i32 %51)
%53 = load i8*, i8** %3
%54 = call i32 @finalize_tar(i8* %53)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [2 x i8] c":\00"
define i32 @write_tar_entries(i8* %0, i8* nocapture %1) {
%3 = alloca [10000 x i8]
%4 = alloca [50 x i8]
%5 = alloca [50 x i8]
%6 = alloca [50 x i8]
%7 = alloca [50 x i8]
%8 = alloca [100 x i8*]
%9 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%14 = bitcast [100 x i8*]* %8 to i8*
%15 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = call i64 @fgets(i8* %9, i32 10000, i32* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %34, label %18
18: ; preds = %2, %18
%19 = phi i64 [ %29, %18 ], [ 0, %2 ]
%20 = call i32 @split(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %11, i8* %10)
%21 = call i32 @split(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %12, i8* %13)
%22 = call i32 @get_file_size(i8* %13)
%23 = call i32 @get_file_modified(i8* %13)
%24 = call i32 @p_write_tar_entry(i8* %12, i8* %13, i32 %22, i32 %23, i32 0)
%25 = call i32 @write_checksum(i8* %12, i32 0)
%26 = getelementptr inbounds [100 x i8*], [100 x i8*]* %8, i64 0, i64 %19
%27 = load i8*, i8** %26
%28 = call i32 @strcpy(i8* %27, i8* %12)
%29 = add nuw i64 %19, 1
%30 = call i64 @fgets(i8* %9, i32 10000, i32* %15)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %18
32: ; preds = %18
%33 = trunc i64 %29 to i32
br label %34
34: ; preds = %32, %2
%35 = phi i32 [ 0, %2 ], [ %33, %32 ]
%36 = call i32 @fclose(i32* %15)
%37 = getelementptr inbounds [100 x i8*], [100 x i8*]* %8, i64 0, i64 0
%38 = call i32 @merge_entries(i8* %0, i8** %37, i32 %35)
%39 = call i32 @finalize_tar(i8* %0)
ret i32 0
}