#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 */
struct stat {
  long st_size;
};

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ copyfile(int, int);
int *da_get_current_tag_info(int);
int /*<<< orphan*/ err_log(int, int, char *, long);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ fstat(int, struct stat *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ r_close(int);
int /*<<< orphan*/ r_write(int, ...);
int da_attach_image(int img_fd, int out_fd, int mp3_fd, int offset) {
  long img_size;
  int tag_size;
  int *tag_info;
  unsigned char buffer[4];
  struct stat sb;
  fstat(img_fd, &sb);
  img_size = sb.st_size;
  { err_log(5, 0x00000100, "Image appears to be %ld bytes\n", img_size); };
  if (img_size < 1) {
    r_close(img_fd);
    return 0;
  }
  if (offset > (img_size + 24)) {
    lseek(mp3_fd, (offset - img_size - 24), SEEK_SET);
    r_close(img_fd);
    return 0;
  }
  tag_info = da_get_current_tag_info(mp3_fd);
  tag_size = tag_info[1];
  { err_log(5, 0x00000100, "Current tag size is %d bytes\n", tag_size); };
  if (tag_info[0] == 3) {
    r_write(out_fd, "ID3\x03\0\0", 6);
    tag_size += img_size + 14 + 8;
  } else {
    r_write(out_fd, "ID3\x02\0\0", 6);
    tag_size += img_size + 6 + 6;
  }
  buffer[3] = tag_size & 0x7F;
  buffer[2] = (tag_size & 0x3F80) >> 7;
  buffer[1] = (tag_size & 0x1FC000) >> 14;
  buffer[0] = (tag_size & 0xFE00000) >> 21;
  r_write(out_fd, buffer, 4);
  if (tag_info[0] == 3) {
    r_write(out_fd, "APIC\0", 5);
    img_size = img_size + 14;
  } else {
    r_write(out_fd, "PIC", 3);
    img_size = img_size + 6;
  }
  buffer[0] = (img_size & 0xFF0000) >> 16;
  buffer[1] = (img_size & 0xFF00) >> 8;
  buffer[2] = (img_size & 0xFF);
  r_write(out_fd, buffer, 3);
  if (tag_info[0] == 3) {
    r_write(out_fd, "\0\0\0image/jpeg\0\0\0", 16);
  } else {
    r_write(out_fd, "\0JPG\x00\0", 6);
  }
  lseek(img_fd, 0, SEEK_SET);
  copyfile(img_fd, out_fd);
  { err_log(5, 0x00000100, "Done copying IMG %ld\n", img_size); };
  r_close(img_fd);
  free(tag_info);
  return 0;
}


x86 assembly (clang, -O0):
<da_attach_image>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1090 <fstat@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    $0x5,%edi
mov    $0x100,%esi
lea    0xe43(%rip),%rdx
call   1050 <err_log@plt>
cmpq   $0x1,-0x20(%rbp)
jge    11e1 <da_attach_image+0x61>
mov    -0x8(%rbp),%edi
call   1040 <r_close@plt>
movl   $0x0,-0x4(%rbp)
jmp    142f <da_attach_image+0x2af>
movslq -0x14(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    $0x18,%rcx
cmp    %rcx,%rax
jle    1229 <da_attach_image+0xa9>
mov    -0x10(%rbp),%edi
movslq -0x14(%rbp),%rax
sub    -0x20(%rbp),%rax
sub    $0x18,%rax
mov    %eax,%esi
mov    0x2dd2(%rip),%rax
mov    (%rax),%edx
call   1060 <lseek@plt>
mov    -0x8(%rbp),%edi
call   1040 <r_close@plt>
movl   $0x0,-0x4(%rbp)
jmp    142f <da_attach_image+0x2af>
mov    -0x10(%rbp),%edi
call   1070 <da_get_current_tag_info@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rcx
mov    $0x5,%edi
mov    $0x100,%esi
lea    0xdcb(%rip),%rdx
call   1050 <err_log@plt>
mov    -0x30(%rbp),%rax
cmpl   $0x3,(%rax)
jne    1297 <da_attach_image+0x117>
mov    -0xc(%rbp),%edi
lea    0xde7(%rip),%rsi
mov    $0x6,%edx
mov    $0x0,%al
call   1080 <r_write@plt>
mov    -0x20(%rbp),%rcx
add    $0xe,%rcx
add    $0x8,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
jmp    12c3 <da_attach_image+0x143>
mov    -0xc(%rbp),%edi
lea    0xdbd(%rip),%rsi
mov    $0x6,%edx
mov    $0x0,%al
call   1080 <r_write@plt>
mov    -0x20(%rbp),%rcx
add    $0x6,%rcx
add    $0x6,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
and    $0x7f,%eax
mov    %al,-0x31(%rbp)
mov    -0x24(%rbp),%eax
and    $0x3f80,%eax
sar    $0x7,%eax
mov    %al,-0x32(%rbp)
mov    -0x24(%rbp),%eax
and    $0x1fc000,%eax
sar    $0xe,%eax
mov    %al,-0x33(%rbp)
mov    -0x24(%rbp),%eax
and    $0xfe00000,%eax
sar    $0x15,%eax
mov    %al,-0x34(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x34(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1080 <r_write@plt>
mov    -0x30(%rbp),%rax
cmpl   $0x3,(%rax)
jne    133d <da_attach_image+0x1bd>
mov    -0xc(%rbp),%edi
lea    0xd45(%rip),%rsi
mov    $0x5,%edx
mov    $0x0,%al
call   1080 <r_write@plt>
mov    -0x20(%rbp),%rax
add    $0xe,%rax
mov    %rax,-0x20(%rbp)
jmp    135f <da_attach_image+0x1df>
mov    -0xc(%rbp),%edi
lea    0xcf6(%rip),%rsi
mov    $0x3,%edx
mov    $0x0,%al
call   1080 <r_write@plt>
mov    -0x20(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
and    $0xff0000,%rax
sar    $0x10,%rax
mov    %al,-0x34(%rbp)
mov    -0x20(%rbp),%rax
and    $0xff00,%rax
sar    $0x8,%rax
mov    %al,-0x33(%rbp)
mov    -0x20(%rbp),%rax
and    $0xff,%rax
mov    %al,-0x32(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x34(%rbp),%rsi
mov    $0x3,%edx
mov    $0x0,%al
call   1080 <r_write@plt>
mov    -0x30(%rbp),%rax
cmpl   $0x3,(%rax)
jne    13c9 <da_attach_image+0x249>
mov    -0xc(%rbp),%edi
lea    0xcb3(%rip),%rsi
mov    $0x10,%edx
mov    $0x0,%al
call   1080 <r_write@plt>
jmp    13df <da_attach_image+0x25f>
mov    -0xc(%rbp),%edi
lea    0xca9(%rip),%rsi
mov    $0x6,%edx
mov    $0x0,%al
call   1080 <r_write@plt>
mov    -0x8(%rbp),%edi
mov    0x2bf7(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   10a0 <copyfile@plt>
mov    -0x20(%rbp),%rcx
mov    $0x5,%edi
mov    $0x100,%esi
lea    0xc2f(%rip),%rdx
call   1050 <err_log@plt>
mov    -0x8(%rbp),%edi
call   1040 <r_close@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<da_attach_image>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebp
mov    %edx,%r15d
mov    %esi,%r14d
mov    %edi,%r12d
lea    0x10(%rsp),%rsi
call   1090 <fstat@plt>
mov    0x10(%rsp),%rbx
lea    0xe51(%rip),%rdx
mov    $0x5,%edi
mov    $0x100,%esi
mov    %rbx,%rcx
call   1050 <err_log@plt>
test   %rbx,%rbx
jle    11ea <da_attach_image+0x6a>
movslq %ebp,%rax
lea    0x18(%rbx),%rcx
cmp    %rax,%rcx
jge    11f7 <da_attach_image+0x77>
sub    %ebx,%ebp
add    $0xffffffe8,%ebp
mov    0x2e02(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
mov    %ebp,%esi
call   1060 <lseek@plt>
mov    %r12d,%edi
call   1040 <r_close@plt>
jmp    136a <da_attach_image+0x1ea>
mov    %r15d,%edi
call   1070 <da_get_current_tag_info@plt>
mov    %rax,%r15
movslq 0x4(%rax),%r13
lea    0xe12(%rip),%rdx
mov    $0x5,%edi
mov    $0x100,%esi
mov    %r13,%rcx
call   1050 <err_log@plt>
lea    0xc(%rbx),%eax
lea    0x16(%rbx),%ebp
cmpl   $0x3,(%r15)
lea    0xe27(%rip),%rcx
lea    0xe27(%rip),%rsi
cmove  %rcx,%rsi
cmovne %eax,%ebp
mov    %r14d,%edi
mov    $0x6,%edx
xor    %eax,%eax
call   1080 <r_write@plt>
add    %r13d,%ebp
mov    %ebp,%eax
and    $0x7f,%al
mov    %al,0xf(%rsp)
mov    %ebp,%eax
shr    $0x7,%eax
and    $0x7f,%al
mov    %al,0xe(%rsp)
mov    %ebp,%eax
shr    $0xe,%eax
and    $0x7f,%al
mov    %al,0xd(%rsp)
shr    $0x15,%ebp
and    $0x7f,%bpl
mov    %bpl,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %r14d,%edi
mov    $0x4,%edx
xor    %eax,%eax
call   1080 <r_write@plt>
cmpl   $0x3,(%r15)
jne    12b1 <da_attach_image+0x131>
lea    0xdca(%rip),%rsi
mov    %r14d,%edi
mov    $0x5,%edx
xor    %eax,%eax
call   1080 <r_write@plt>
mov    $0xe,%eax
jmp    12cc <da_attach_image+0x14c>
lea    0xd85(%rip),%rsi
mov    %r14d,%edi
mov    $0x3,%edx
xor    %eax,%eax
call   1080 <r_write@plt>
mov    $0x6,%eax
add    %rax,%rbx
mov    %rbx,%rax
shr    $0x10,%rax
mov    %al,0xc(%rsp)
mov    %bh,0xd(%rsp)
mov    %bl,0xe(%rsp)
lea    0xc(%rsp),%rsi
mov    %r14d,%edi
mov    $0x3,%edx
xor    %eax,%eax
call   1080 <r_write@plt>
cmpl   $0x3,(%r15)
jne    130d <da_attach_image+0x18d>
lea    0xd68(%rip),%rsi
mov    %r14d,%edi
mov    $0x10,%edx
jmp    131c <da_attach_image+0x19c>
lea    0xd68(%rip),%rsi
mov    %r14d,%edi
mov    $0x6,%edx
xor    %eax,%eax
call   1080 <r_write@plt>
mov    0x2cb6(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %r12d,%edi
mov    %r14d,%esi
call   10a0 <copyfile@plt>
lea    0xcf9(%rip),%rdx
mov    $0x5,%edi
mov    $0x100,%esi
mov    %rbx,%rcx
call   1050 <err_log@plt>
mov    %r12d,%edi
call   1040 <r_close@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [31 x i8] c"Image appears to be %ld bytes\0A\00"
@SEEK_SET = global i32 0
@.str.1 = [30 x i8] c"Current tag size is %d bytes\0A\00"
@.str.2 = [7 x i8] c"ID3\03\00\00\00"
@.str.3 = [7 x i8] c"ID3\02\00\00\00"
@.str.4 = [6 x i8] c"APIC\00\00"
@.str.5 = [4 x i8] c"PIC\00"
@.str.6 = [17 x i8] c"\00\00\00image/jpeg\00\00\00\00"
@.str.7 = [7 x i8] c"\00JPG\00\00\00"
@.str.8 = [22 x i8] c"Done copying IMG %ld\0A\00"
define i32 @da_attach_image(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32*
%13 = alloca [4 x i8]
%14 = alloca %struct.stat
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%15 = load i32, i32* %6
%16 = call i32 @fstat(i32 %15, %struct.stat* %14)
%17 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%18 = load i64, i64* %17
store i64 %18, i64* %10
%19 = load i64, i64* %10
%20 = call i32 @err_log(i32 5, i32 256, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i64 %19)
%21 = load i64, i64* %10
%22 = icmp slt i64 %21, 1
br i1 %22, label %23, label %26
23: ; preds = %4
%24 = load i32, i32* %6
%25 = call i32 @r_close(i32 %24)
store i32 0, i32* %5
br label %155
26: ; preds = %4
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = load i64, i64* %10
%30 = add nsw i64 %29, 24
%31 = icmp sgt i64 %28, %30
br i1 %31, label %32, label %44
32: ; preds = %26
%33 = load i32, i32* %8
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = load i64, i64* %10
%37 = sub nsw i64 %35, %36
%38 = sub nsw i64 %37, 24
%39 = trunc i64 %38 to i32
%40 = load i32, i32* @SEEK_SET
%41 = call i32 @lseek(i32 %33, i32 %39, i32 %40)
%42 = load i32, i32* %6
%43 = call i32 @r_close(i32 %42)
store i32 0, i32* %5
br label %155
44: ; preds = %26
%45 = load i32, i32* %8
%46 = call i32* @da_get_current_tag_info(i32 %45)
store i32* %46, i32** %12
%47 = load i32*, i32** %12
%48 = getelementptr inbounds i32, i32* %47, i64 1
%49 = load i32, i32* %48
store i32 %49, i32* %11
%50 = load i32, i32* %11
%51 = sext i32 %50 to i64
%52 = call i32 @err_log(i32 5, i32 256, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i64 %51)
%53 = load i32*, i32** %12
%54 = getelementptr inbounds i32, i32* %53, i64 0
%55 = load i32, i32* %54
%56 = icmp eq i32 %55, 3
br i1 %56, label %57, label %67
57: ; preds = %44
%58 = load i32, i32* %7
%59 = call i32 (i32, ...) @r_write(i32 %58, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 6)
%60 = load i64, i64* %10
%61 = add nsw i64 %60, 14
%62 = add nsw i64 %61, 8
%63 = load i32, i32* %11
%64 = sext i32 %63 to i64
%65 = add nsw i64 %64, %62
%66 = trunc i64 %65 to i32
store i32 %66, i32* %11
br label %77
67: ; preds = %44
%68 = load i32, i32* %7
%69 = call i32 (i32, ...) @r_write(i32 %68, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%70 = load i64, i64* %10
%71 = add nsw i64 %70, 6
%72 = add nsw i64 %71, 6
%73 = load i32, i32* %11
%74 = sext i32 %73 to i64
%75 = add nsw i64 %74, %72
%76 = trunc i64 %75 to i32
store i32 %76, i32* %11
br label %77
77: ; preds = %67, %57
%78 = load i32, i32* %11
%79 = and i32 %78, 127
%80 = trunc i32 %79 to i8
%81 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 3
store i8 %80, i8* %81
%82 = load i32, i32* %11
%83 = and i32 %82, 16256
%84 = ashr i32 %83, 7
%85 = trunc i32 %84 to i8
%86 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 2
store i8 %85, i8* %86
%87 = load i32, i32* %11
%88 = and i32 %87, 2080768
%89 = ashr i32 %88, 14
%90 = trunc i32 %89 to i8
%91 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 1
store i8 %90, i8* %91
%92 = load i32, i32* %11
%93 = and i32 %92, 266338304
%94 = ashr i32 %93, 21
%95 = trunc i32 %94 to i8
%96 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
store i8 %95, i8* %96
%97 = load i32, i32* %7
%98 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%99 = call i32 (i32, ...) @r_write(i32 %97, i8* %98, i32 4)
%100 = load i32*, i32** %12
%101 = getelementptr inbounds i32, i32* %100, i64 0
%102 = load i32, i32* %101
%103 = icmp eq i32 %102, 3
br i1 %103, label %104, label %109
104: ; preds = %77
%105 = load i32, i32* %7
%106 = call i32 (i32, ...) @r_write(i32 %105, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%107 = load i64, i64* %10
%108 = add nsw i64 %107, 14
store i64 %108, i64* %10
br label %114
109: ; preds = %77
%110 = load i32, i32* %7
%111 = call i32 (i32, ...) @r_write(i32 %110, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 3)
%112 = load i64, i64* %10
%113 = add nsw i64 %112, 6
store i64 %113, i64* %10
br label %114
114: ; preds = %109, %104
%115 = load i64, i64* %10
%116 = and i64 %115, 16711680
%117 = ashr i64 %116, 16
%118 = trunc i64 %117 to i8
%119 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
store i8 %118, i8* %119
%120 = load i64, i64* %10
%121 = and i64 %120, 65280
%122 = ashr i64 %121, 8
%123 = trunc i64 %122 to i8
%124 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 1
store i8 %123, i8* %124
%125 = load i64, i64* %10
%126 = and i64 %125, 255
%127 = trunc i64 %126 to i8
%128 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 2
store i8 %127, i8* %128
%129 = load i32, i32* %7
%130 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%131 = call i32 (i32, ...) @r_write(i32 %129, i8* %130, i32 3)
%132 = load i32*, i32** %12
%133 = getelementptr inbounds i32, i32* %132, i64 0
%134 = load i32, i32* %133
%135 = icmp eq i32 %134, 3
br i1 %135, label %136, label %139
136: ; preds = %114
%137 = load i32, i32* %7
%138 = call i32 (i32, ...) @r_write(i32 %137, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 16)
br label %142
139: ; preds = %114
%140 = load i32, i32* %7
%141 = call i32 (i32, ...) @r_write(i32 %140, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 6)
br label %142
142: ; preds = %139, %136
%143 = load i32, i32* %6
%144 = load i32, i32* @SEEK_SET
%145 = call i32 @lseek(i32 %143, i32 0, i32 %144)
%146 = load i32, i32* %6
%147 = load i32, i32* %7
%148 = call i32 @copyfile(i32 %146, i32 %147)
%149 = load i64, i64* %10
%150 = call i32 @err_log(i32 5, i32 256, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i64 %149)
%151 = load i32, i32* %6
%152 = call i32 @r_close(i32 %151)
%153 = load i32*, i32** %12
%154 = call i32 @free(i32* %153)
store i32 0, i32* %5
br label %155
155: ; preds = %142, %32, %23
%156 = load i32, i32* %5
ret i32 %156
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [31 x i8] c"Image appears to be %ld bytes\0A\00"
@SEEK_SET = global i32 0
@.str.1 = [30 x i8] c"Current tag size is %d bytes\0A\00"
@.str.2 = [7 x i8] c"ID3\03\00\00\00"
@.str.3 = [7 x i8] c"ID3\02\00\00\00"
@.str.4 = [6 x i8] c"APIC\00\00"
@.str.5 = [4 x i8] c"PIC\00"
@.str.6 = [17 x i8] c"\00\00\00image/jpeg\00\00\00\00"
@.str.7 = [7 x i8] c"\00JPG\00\00\00"
@.str.8 = [22 x i8] c"Done copying IMG %ld\0A\00"
define i32 @da_attach_image(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [4 x i8]
%6 = alloca %struct.stat
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%8 = bitcast %struct.stat* %6 to i8*
%9 = call i32 @fstat(i32 %0, %struct.stat* %6)
%10 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
%11 = load i64, i64* %10
%12 = tail call i32 @err_log(i32 5, i32 256, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i64 %11)
%13 = icmp slt i64 %11, 1
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = tail call i32 @r_close(i32 %0)
br label %84
16: ; preds = %4
%17 = sext i32 %3 to i64
%18 = add nuw nsw i64 %11, 24
%19 = icmp slt i64 %18, %17
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = trunc i64 %11 to i32
%22 = add i32 %3, -24
%23 = sub i32 %22, %21
%24 = load i32, i32* @SEEK_SET
%25 = tail call i32 @lseek(i32 %2, i32 %23, i32 %24)
%26 = tail call i32 @r_close(i32 %0)
br label %84
27: ; preds = %16
%28 = tail call i32* @da_get_current_tag_info(i32 %2)
%29 = getelementptr inbounds i32, i32* %28, i64 1
%30 = load i32, i32* %29
%31 = sext i32 %30 to i64
%32 = tail call i32 @err_log(i32 5, i32 256, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i64 %31)
%33 = load i32, i32* %28
%34 = icmp eq i32 %33, 3
%35 = select i1 %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0)
%36 = select i1 %34, i32 22, i32 12
%37 = tail call i32 (i32, ...) @r_write(i32 %1, i8* %35, i32 6)
%38 = trunc i64 %11 to i32
%39 = add i32 %36, %38
%40 = add i32 %39, %30
%41 = trunc i32 %40 to i8
%42 = and i8 %41, 127
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
store i8 %42, i8* %43
%44 = lshr i32 %40, 7
%45 = trunc i32 %44 to i8
%46 = and i8 %45, 127
%47 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 2
store i8 %46, i8* %47
%48 = lshr i32 %40, 14
%49 = trunc i32 %48 to i8
%50 = and i8 %49, 127
%51 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
store i8 %50, i8* %51
%52 = lshr i32 %40, 21
%53 = trunc i32 %52 to i8
%54 = and i8 %53, 127
store i8 %54, i8* %7
%55 = call i32 (i32, ...) @r_write(i32 %1, i8* %7, i32 4)
%56 = load i32, i32* %28
%57 = icmp eq i32 %56, 3
br i1 %57, label %58, label %60
58: ; preds = %27
%59 = call i32 (i32, ...) @r_write(i32 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
br label %62
60: ; preds = %27
%61 = call i32 (i32, ...) @r_write(i32 %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 3)
br label %62
62: ; preds = %60, %58
%63 = phi i64 [ 6, %60 ], [ 14, %58 ]
%64 = add nuw nsw i64 %11, %63
%65 = lshr i64 %64, 16
%66 = trunc i64 %65 to i8
store i8 %66, i8* %7
%67 = lshr i64 %64, 8
%68 = trunc i64 %67 to i8
store i8 %68, i8* %51
%69 = trunc i64 %64 to i8
store i8 %69, i8* %47
%70 = call i32 (i32, ...) @r_write(i32 %1, i8* %7, i32 3)
%71 = load i32, i32* %28
%72 = icmp eq i32 %71, 3
br i1 %72, label %73, label %75
73: ; preds = %62
%74 = call i32 (i32, ...) @r_write(i32 %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 16)
br label %77
75: ; preds = %62
%76 = call i32 (i32, ...) @r_write(i32 %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 6)
br label %77
77: ; preds = %75, %73
%78 = load i32, i32* @SEEK_SET
%79 = call i32 @lseek(i32 %0, i32 0, i32 %78)
%80 = call i32 @copyfile(i32 %0, i32 %1)
%81 = call i32 @err_log(i32 5, i32 256, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i64 %64)
%82 = call i32 @r_close(i32 %0)
%83 = call i32 @free(i32* %28)
br label %84
84: ; preds = %77, %20, %14
ret i32 0
}