#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_END;
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fread(unsigned char *, unsigned int, int,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
void *getwlh(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ puth(unsigned char, int /*<<< orphan*/ *);
void convert(int format, FILE *in, FILE *out) {
  unsigned int org = 0;
  unsigned int idx;
  long len;
  unsigned char buf[256];
  if (format < 3)
    org = getwlh(in);
  if (format == 2) {
    len = getwlh(in);
  } else {
    long begin = ftell(in);
    fseek(in, 0, SEEK_END);
    len = ftell(in) - begin;
    fseek(in, begin, 0);
  }
  for (;;) {
    while (len > 0) {
      register unsigned char chk;
      register unsigned int i;
      idx = (len > 16) ? 16 : len;
      fread(buf, idx, 1, in);
      putc(':', out);
      puth(idx, out);
      puth(org >> 8, out);
      puth(org & 0xFF, out);
      putc('0', out);
      putc('0', out);
      chk = idx + (org >> 8) + (org & 0xFF);
      for (i = 0; i < idx; ++i) {
        chk += buf[i];
        puth(buf[i], out);
      }
      puth((unsigned char)-chk, out);
      putc('\r', out);
      putc('\n', out);
      len -= idx;
      org += idx;
    }
    if (format == 2) {
      org = getwlh(in);
      if (feof(in))
        break;
      len = getwlh(in);
    } else {
      break;
    }
  }
  fprintf(out, ":00000001FF\r\n");
}


x86 assembly (clang, -O0):
<convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x4(%rbp)
jge    11b3 <convert+0x33>
mov    -0x10(%rbp),%rdi
call   10a0 <getwlh@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x2,-0x4(%rbp)
jne    11cf <convert+0x4f>
mov    -0x10(%rbp),%rdi
call   10a0 <getwlh@plt>
mov    %rax,-0x28(%rbp)
jmp    121b <convert+0x9b>
mov    -0x10(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x138(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2dfe(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1090 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1070 <ftell@plt>
sub    -0x138(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x138(%rbp),%rsi
xor    %edx,%edx
call   1090 <fseek@plt>
jmp    1220 <convert+0xa0>
jmp    1225 <convert+0xa5>
cmpq   $0x0,-0x28(%rbp)
jle    13a8 <convert+0x228>
cmpq   $0x10,-0x28(%rbp)
jle    124c <convert+0xcc>
mov    $0x10,%eax
mov    %rax,-0x148(%rbp)
jmp    1257 <convert+0xd7>
mov    -0x28(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x148(%rbp),%rax
mov    %eax,-0x20(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x18(%rbp),%rsi
mov    $0x3a,%edi
call   1050 <putc@plt>
mov    -0x20(%rbp),%eax
mov    -0x18(%rbp),%rsi
movzbl %al,%edi
call   1040 <puth@plt>
mov    -0x1c(%rbp),%eax
shr    $0x8,%eax
mov    -0x18(%rbp),%rsi
movzbl %al,%edi
call   1040 <puth@plt>
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
mov    -0x18(%rbp),%rsi
movzbl %al,%edi
call   1040 <puth@plt>
mov    -0x18(%rbp),%rsi
mov    $0x30,%edi
call   1050 <putc@plt>
mov    -0x18(%rbp),%rsi
mov    $0x30,%edi
call   1050 <putc@plt>
mov    -0x20(%rbp),%eax
mov    -0x1c(%rbp),%ecx
shr    $0x8,%ecx
add    %ecx,%eax
mov    -0x1c(%rbp),%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    %al,-0x139(%rbp)
movl   $0x0,-0x140(%rbp)
mov    -0x140(%rbp),%eax
cmp    -0x20(%rbp),%eax
jae    1357 <convert+0x1d7>
mov    -0x140(%rbp),%eax
movzbl -0x130(%rbp,%rax,1),%ecx
ff
movzbl -0x139(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x139(%rbp)
mov    -0x140(%rbp),%eax
mov    -0x130(%rbp,%rax,1),%al
mov    -0x18(%rbp),%rsi
movzbl %al,%edi
call   1040 <puth@plt>
mov    -0x140(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x140(%rbp)
jmp    12fe <convert+0x17e>
movzbl -0x139(%rbp),%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    -0x18(%rbp),%rsi
movzbl %al,%edi
call   1040 <puth@plt>
mov    -0x18(%rbp),%rsi
mov    $0xd,%edi
call   1050 <putc@plt>
mov    -0x18(%rbp),%rsi
mov    $0xa,%edi
call   1050 <putc@plt>
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1225 <convert+0xa5>
cmpl   $0x2,-0x4(%rbp)
jne    13e8 <convert+0x268>
mov    -0x10(%rbp),%rdi
call   10a0 <getwlh@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     13d6 <convert+0x256>
jmp    13f2 <convert+0x272>
mov    -0x10(%rbp),%rdi
call   10a0 <getwlh@plt>
mov    %rax,-0x28(%rbp)
jmp    13ed <convert+0x26d>
jmp    13f2 <convert+0x272>
jmp    1220 <convert+0xa0>
mov    -0x18(%rbp),%rdi
lea    0xc03(%rip),%rsi
call   1060 <fprintf@plt>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
xor    %r15d,%r15d
cmp    $0x2,%edi
jg     11c4 <convert+0x44>
mov    %edi,%ebp
mov    %r14,%rdi
call   10a0 <getwlh@plt>
mov    %rax,%r15
cmp    $0x2,%ebp
jne    11c4 <convert+0x44>
mov    %r14,%rdi
call   10a0 <getwlh@plt>
mov    %rax,%r13
mov    $0x1,%al
mov    %rax,(%rsp)
jmp    1203 <convert+0x83>
mov    %r14,%rdi
call   1060 <ftell@plt>
mov    %rax,%rbp
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %rax,(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r14,%rdi
call   1060 <ftell@plt>
mov    %rax,%r13
sub    %rbp,%r13
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %edx,%edx
call   1080 <fseek@plt>
mov    %r14,0x8(%rsp)
test   %r13,%r13
jle    12f5 <convert+0x175>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x10,%r13
mov    $0x10,%ebp
cmovb  %r13,%rbp
lea    0x10(%rsp),%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    $0x3a,%edi
mov    %rbx,%rsi
call   1050 <putc@plt>
movzbl %bpl,%edi
mov    %rbx,%rsi
call   1040 <puth@plt>
mov    %r15d,%r12d
shr    $0x8,%r12d
movzbl %r12b,%edi
mov    %rbx,%rsi
call   1040 <puth@plt>
movzbl %r15b,%edi
mov    %rbx,%rsi
call   1040 <puth@plt>
mov    $0x30,%edi
mov    %rbx,%rsi
call   1050 <putc@plt>
mov    $0x30,%edi
mov    %rbx,%rsi
call   1050 <putc@plt>
add    %ebp,%r15d
add    %r15d,%r12d
xor    %r14d,%r14d
nopl   0x0(%rax)
movzbl 0x10(%rsp,%r14,1),%edi
movzbl %r12b,%r12d
add    %edi,%r12d
mov    %rbx,%rsi
call   1040 <puth@plt>
add    $0x1,%r14
cmp    %r14,%rbp
jne    12a0 <convert+0x120>
neg    %r12b
movzbl %r12b,%edi
mov    %rbx,%rsi
call   1040 <puth@plt>
mov    $0xd,%edi
mov    %rbx,%rsi
call   1050 <putc@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <putc@plt>
sub    %rbp,%r13
mov    0x8(%rsp),%r14
jg     1220 <convert+0xa0>
cmpb   $0x0,(%rsp)
je     1329 <convert+0x1a9>
mov    %r14,%rdi
call   10a0 <getwlh@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    1329 <convert+0x1a9>
mov    %r14,%rdi
call   10a0 <getwlh@plt>
mov    %rax,%r13
test   %r13,%r13
jg     1220 <convert+0xa0>
jmp    12f5 <convert+0x175>
lea    0xcd0(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <fwrite@plt>

LLVM IR (-O0):
@SEEK_END = global i32 0
@.str = [14 x i8] c":00000001FF\0D\0A\00"
define void @convert(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca [256 x i8]
%11 = alloca i64
%12 = alloca i8
%13 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 0, i32* %7
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i32*, i32** %5
%18 = call i8* @getwlh(i32* %17)
%19 = ptrtoint i8* %18 to i32
store i32 %19, i32* %7
br label %20
20: ; preds = %16, %3
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 2
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32*, i32** %5
%25 = call i8* @getwlh(i32* %24)
%26 = ptrtoint i8* %25 to i64
store i64 %26, i64* %9
br label %40
27: ; preds = %20
%28 = load i32*, i32** %5
%29 = call i64 @ftell(i32* %28)
store i64 %29, i64* %11
%30 = load i32*, i32** %5
%31 = load i32, i32* @SEEK_END
%32 = call i32 @fseek(i32* %30, i64 0, i32 %31)
%33 = load i32*, i32** %5
%34 = call i64 @ftell(i32* %33)
%35 = load i64, i64* %11
%36 = sub nsw i64 %34, %35
store i64 %36, i64* %9
%37 = load i32*, i32** %5
%38 = load i64, i64* %11
%39 = call i32 @fseek(i32* %37, i64 %38, i32 0)
br label %40
40: ; preds = %27, %23
br label %41
41: ; preds = %143, %40
br label %42
42: ; preds = %109, %41
%43 = load i64, i64* %9
%44 = icmp sgt i64 %43, 0
br i1 %44, label %45, label %127
45: ; preds = %42
%46 = load i64, i64* %9
%47 = icmp sgt i64 %46, 16
br i1 %47, label %48, label %49
48: ; preds = %45
br label %51
49: ; preds = %45
%50 = load i64, i64* %9
br label %51
51: ; preds = %49, %48
%52 = phi i64 [ 16, %48 ], [ %50, %49 ]
%53 = trunc i64 %52 to i32
store i32 %53, i32* %8
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%55 = load i32, i32* %8
%56 = load i32*, i32** %5
%57 = call i32 @fread(i8* %54, i32 %55, i32 1, i32* %56)
%58 = load i32*, i32** %6
%59 = call i32 @putc(i8 signext 58, i32* %58)
%60 = load i32, i32* %8
%61 = trunc i32 %60 to i8
%62 = load i32*, i32** %6
%63 = call i32 @puth(i8 zeroext %61, i32* %62)
%64 = load i32, i32* %7
%65 = lshr i32 %64, 8
%66 = trunc i32 %65 to i8
%67 = load i32*, i32** %6
%68 = call i32 @puth(i8 zeroext %66, i32* %67)
%69 = load i32, i32* %7
%70 = and i32 %69, 255
%71 = trunc i32 %70 to i8
%72 = load i32*, i32** %6
%73 = call i32 @puth(i8 zeroext %71, i32* %72)
%74 = load i32*, i32** %6
%75 = call i32 @putc(i8 signext 48, i32* %74)
%76 = load i32*, i32** %6
%77 = call i32 @putc(i8 signext 48, i32* %76)
%78 = load i32, i32* %8
%79 = load i32, i32* %7
%80 = lshr i32 %79, 8
%81 = add i32 %78, %80
%82 = load i32, i32* %7
%83 = and i32 %82, 255
%84 = add i32 %81, %83
%85 = trunc i32 %84 to i8
store i8 %85, i8* %12
store i32 0, i32* %13
br label %86
86: ; preds = %106, %51
%87 = load i32, i32* %13
%88 = load i32, i32* %8
%89 = icmp ult i32 %87, %88
br i1 %89, label %90, label %109
90: ; preds = %86
%91 = load i32, i32* %13
%92 = zext i32 %91 to i64
%93 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %92
%94 = load i8, i8* %93
%95 = zext i8 %94 to i32
%96 = load i8, i8* %12
%97 = zext i8 %96 to i32
%98 = add nsw i32 %97, %95
%99 = trunc i32 %98 to i8
store i8 %99, i8* %12
%100 = load i32, i32* %13
%101 = zext i32 %100 to i64
%102 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %101
%103 = load i8, i8* %102
%104 = load i32*, i32** %6
%105 = call i32 @puth(i8 zeroext %103, i32* %104)
br label %106
106: ; preds = %90
%107 = load i32, i32* %13
%108 = add i32 %107, 1
store i32 %108, i32* %13
br label %86
109: ; preds = %86
%110 = load i8, i8* %12
%111 = zext i8 %110 to i32
%112 = sub nsw i32 0, %111
%113 = trunc i32 %112 to i8
%114 = load i32*, i32** %6
%115 = call i32 @puth(i8 zeroext %113, i32* %114)
%116 = load i32*, i32** %6
%117 = call i32 @putc(i8 signext 13, i32* %116)
%118 = load i32*, i32** %6
%119 = call i32 @putc(i8 signext 10, i32* %118)
%120 = load i32, i32* %8
%121 = zext i32 %120 to i64
%122 = load i64, i64* %9
%123 = sub nsw i64 %122, %121
store i64 %123, i64* %9
%124 = load i32, i32* %8
%125 = load i32, i32* %7
%126 = add i32 %125, %124
store i32 %126, i32* %7
br label %42
127: ; preds = %42
%128 = load i32, i32* %4
%129 = icmp eq i32 %128, 2
br i1 %129, label %130, label %142
130: ; preds = %127
%131 = load i32*, i32** %5
%132 = call i8* @getwlh(i32* %131)
%133 = ptrtoint i8* %132 to i32
store i32 %133, i32* %7
%134 = load i32*, i32** %5
%135 = call i64 @feof(i32* %134)
%136 = icmp ne i64 %135, 0
br i1 %136, label %137, label %138
137: ; preds = %130
br label %144
138: ; preds = %130
%139 = load i32*, i32** %5
%140 = call i8* @getwlh(i32* %139)
%141 = ptrtoint i8* %140 to i64
store i64 %141, i64* %9
br label %143
142: ; preds = %127
br label %144
143: ; preds = %138
br label %41
144: ; preds = %142, %137
%145 = load i32*, i32** %6
%146 = call i32 @fprintf(i32* %145, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@.str = [14 x i8] c":00000001FF\0D\0A\00"
define void @convert(i32 %0, i32* %1, i32* %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = icmp slt i32 %0, 3
br i1 %6, label %7, label %15
7: ; preds = %3
%8 = tail call i8* @getwlh(i32* %1)
%9 = ptrtoint i8* %8 to i64
%10 = trunc i64 %9 to i32
%11 = icmp eq i32 %0, 2
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = tail call i8* @getwlh(i32* %1)
%14 = ptrtoint i8* %13 to i64
br label %23
15: ; preds = %3, %7
%16 = phi i32 [ %10, %7 ], [ 0, %3 ]
%17 = tail call i64 @ftell(i32* %1)
%18 = load i32, i32* @SEEK_END
%19 = tail call i32 @fseek(i32* %1, i64 0, i32 %18)
%20 = tail call i64 @ftell(i32* %1)
%21 = sub nsw i64 %20, %17
%22 = tail call i32 @fseek(i32* %1, i64 %17, i32 0)
br label %23
23: ; preds = %15, %12
%24 = phi i1 [ true, %12 ], [ false, %15 ]
%25 = phi i32 [ %10, %12 ], [ %16, %15 ]
%26 = phi i64 [ %14, %12 ], [ %21, %15 ]
br label %27
27: ; preds = %74, %23
%28 = phi i64 [ %26, %23 ], [ %78, %74 ]
%29 = phi i32 [ %25, %23 ], [ %76, %74 ]
%30 = icmp sgt i64 %28, 0
br i1 %30, label %31, label %69
31: ; preds = %27, %61
%32 = phi i32 [ %48, %61 ], [ %29, %27 ]
%33 = phi i64 [ %67, %61 ], [ %28, %27 ]
%34 = icmp ult i64 %33, 16
%35 = select i1 %34, i64 %33, i64 16
%36 = trunc i64 %35 to i32
%37 = call i32 @fread(i8* %5, i32 %36, i32 1, i32* %1)
%38 = tail call i32 @putc(i8 signext 58, i32* %2)
%39 = trunc i64 %35 to i8
%40 = tail call i32 @puth(i8 zeroext %39, i32* %2)
%41 = lshr i32 %32, 8
%42 = trunc i32 %41 to i8
%43 = tail call i32 @puth(i8 zeroext %42, i32* %2)
%44 = trunc i32 %32 to i8
%45 = tail call i32 @puth(i8 zeroext %44, i32* %2)
%46 = tail call i32 @putc(i8 signext 48, i32* %2)
%47 = tail call i32 @putc(i8 signext 48, i32* %2)
%48 = add i32 %32, %36
%49 = add i32 %48, %41
br label %50
50: ; preds = %31, %50
%51 = phi i64 [ 0, %31 ], [ %59, %50 ]
%52 = phi i32 [ %49, %31 ], [ %57, %50 ]
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %51
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = and i32 %52, 255
%57 = add nuw nsw i32 %56, %55
%58 = tail call i32 @puth(i8 zeroext %54, i32* %2)
%59 = add nuw nsw i64 %51, 1
%60 = icmp eq i64 %59, %35
br i1 %60, label %61, label %50
61: ; preds = %50
%62 = trunc i32 %57 to i8
%63 = sub i8 0, %62
%64 = tail call i32 @puth(i8 zeroext %63, i32* %2)
%65 = tail call i32 @putc(i8 signext 13, i32* %2)
%66 = tail call i32 @putc(i8 signext 10, i32* %2)
%67 = sub nsw i64 %33, %35
%68 = icmp sgt i64 %67, 0
br i1 %68, label %31, label %69
69: ; preds = %61, %27
br i1 %24, label %70, label %79
70: ; preds = %69
%71 = tail call i8* @getwlh(i32* %1)
%72 = tail call i64 @feof(i32* %1)
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %79
74: ; preds = %70
%75 = ptrtoint i8* %71 to i64
%76 = trunc i64 %75 to i32
%77 = tail call i8* @getwlh(i32* %1)
%78 = ptrtoint i8* %77 to i64
br label %27
79: ; preds = %69, %70
%80 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 13, i64 1, i32* %2)
ret void
}