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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, int, int);
void ihex_hexout(FILE *fhex, int byte, uint32_t memory_location, uint32_t end) {
  static int byte_buffer[32];
  static uint32_t last_mem, buffer_pos, buffer_addr;
  static int writing_in_progress = 0;
  int seg_swap = 0;
  register int i, sum;
  if (!writing_in_progress) {
    last_mem = memory_location - 1;
    buffer_pos = 0;
    buffer_addr = memory_location;
    writing_in_progress = 1;
  }
  uint32_t last_seg, new_seg;
  last_seg = last_mem >> 16;
  new_seg = memory_location >> 16;
  seg_swap = last_seg != new_seg;
  if (seg_swap)
    printf("seg_swap 0x%08x 0x%08x\n", last_seg, new_seg);
  if ((memory_location != (last_mem + 1)) || (buffer_pos >= 32) ||
      ((end) && (buffer_pos > 0)) || seg_swap) {
    fprintf(fhex, ":%02X%04X00", buffer_pos, buffer_addr);
    sum = buffer_pos + ((buffer_addr >> 8) & 255) + (buffer_addr & 255);
    for (i = 0; i < buffer_pos; i++) {
      fprintf(fhex, "%02X", byte_buffer[i] & 255);
      sum += byte_buffer[i] & 255;
    }
    fprintf(fhex, "%02X\n", (-sum) & 255);
    buffer_addr = memory_location;
    buffer_pos = 0;
  }
  if (seg_swap) {
    fprintf(fhex, ":04000002");
    sum = 0x04 + 0x00 + 0x00 + 0x02;
    fprintf(fhex, "%02X%02X", (new_seg >> 8) & 0xff, new_seg & 0xff);
    sum += (new_seg >> 8) & 0xff;
    sum += new_seg & 0xff;
    fprintf(fhex, "%02X\n", (-sum) & 255);
  }
  if (end) {
    fprintf(fhex, ":00000001FF\n");
    fclose(fhex);
    writing_in_progress = 0;
  }
  last_mem = memory_location;
  byte_buffer[buffer_pos] = byte & 255;
  buffer_pos++;
}


x86 assembly (clang, -O0):
<ihex_hexout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,0x2f89(%rip)
jne    1182 <ihex_hexout+0x52>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,0x2f6b(%rip)
movl   $0x0,0x2f65(%rip)
mov    -0x10(%rbp),%eax
mov    %eax,0x2f60(%rip)
movl   $0x1,0x2f5a(%rip)
mov    0x2f48(%rip),%eax
sar    $0x10,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x10,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11c4 <ihex_hexout+0x94>
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
mov    0x2f03(%rip),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jne    1206 <ihex_hexout+0xd6>
cmpl   $0x20,0x2ef5(%rip)
jge    1206 <ihex_hexout+0xd6>
cmpl   $0x0,-0x14(%rbp)
je     11fc <ihex_hexout+0xcc>
cmpl   $0x0,0x2ede(%rip)
jg     1206 <ihex_hexout+0xd6>
cmpl   $0x0,-0x18(%rbp)
je     12df <ihex_hexout+0x1af>
mov    -0x8(%rbp),%rdi
mov    0x2ec4(%rip),%edx
mov    0x2ec2(%rip),%ecx
lea    0xdfb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2eaa(%rip),%eax
mov    0x2ea8(%rip),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    0x2e97(%rip),%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    0x2e78(%rip),%eax
jge    12af <ihex_hexout+0x17f>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rcx
lea    0x2ddf(%rip),%rax
mov    (%rax,%rcx,4),%edx
and    $0xff,%edx
lea    0xdb7(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movslq -0x1c(%rbp),%rcx
lea    0x2dbd(%rip),%rax
mov    (%rax,%rcx,4),%eax
and    $0xff,%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1253 <ihex_hexout+0x123>
mov    -0x8(%rbp),%rdi
xor    %edx,%edx
sub    -0x20(%rbp),%edx
and    $0xff,%edx
lea    0xd5f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,0x2e03(%rip)
movl   $0x0,0x2df5(%rip)
cmpl   $0x0,-0x18(%rbp)
je     1365 <ihex_hexout+0x235>
mov    -0x8(%rbp),%rdi
lea    0xd36(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x6,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%edx
sar    $0x8,%edx
and    $0xff,%edx
mov    -0x28(%rbp),%ecx
and    $0xff,%ecx
lea    0xd12(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%eax
and    $0xff,%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
xor    %edx,%edx
sub    -0x20(%rbp),%edx
and    $0xff,%edx
lea    0xcc6(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpl   $0x0,-0x14(%rbp)
je     1394 <ihex_hexout+0x264>
mov    -0x8(%rbp),%rdi
lea    0xcc3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,0x2d48(%rip)
mov    -0x10(%rbp),%eax
mov    %eax,0x2d33(%rip)
mov    -0xc(%rbp),%edx
and    $0xff,%edx
movslq 0x2d27(%rip),%rcx
lea    0x2c9c(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    0x2d17(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2d0e(%rip)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ihex_hexout>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %edx,%r15d
mov    %esi,%r13d
mov    %rdi,%rbp
cmpb   $0x1,0x2f7b(%rip)
jne    116b <ihex_hexout+0x2b>
mov    0x2f67(%rip),%eax
jmp    118d <ihex_hexout+0x4d>
lea    -0x1(%r15),%eax
mov    %eax,0x2f5b(%rip)
movl   $0x0,0x2f55(%rip)
mov    %r15d,0x2f52(%rip)
movb   $0x1,0x2f4f(%rip)
mov    %eax,%ebx
sar    $0x10,%ebx
mov    %r15d,%r14d
sar    $0x10,%r14d
cmp    %r14d,%ebx
je     11b5 <ihex_hexout+0x75>
lea    0xe5b(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
call   1040 <printf@plt>
mov    0x2f1b(%rip),%eax
add    $0x1,%eax
mov    0x2f16(%rip),%edx
cmp    %r15d,%eax
jne    124a <ihex_hexout+0x10a>
cmp    $0x1f,%edx
jg     124a <ihex_hexout+0x10a>
test   %r12d,%r12d
setne  %al
test   %edx,%edx
setg   %cl
test   %cl,%al
jne    124a <ihex_hexout+0x10a>
cmp    %r14d,%ebx
jne    124a <ihex_hexout+0x10a>
cmp    %r14d,%ebx
jne    1326 <ihex_hexout+0x1e6>
test   %r12d,%r12d
je     1216 <ihex_hexout+0xd6>
lea    0xe48(%rip),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1060 <fwrite@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
movb   $0x0,0x2ec6(%rip)
mov    %r15d,0x2eb3(%rip)
movzbl %r13b,%eax
movslq 0x2eac(%rip),%rcx
lea    0x2e21(%rip),%rdx
mov    %eax,(%rdx,%rcx,4)
lea    0x1(%rcx),%eax
mov    %eax,0x2e99(%rip)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,0x4(%rsp)
mov    %r14d,%ebx
mov    %r12d,0x8(%rsp)
mov    %r15,0x10(%rsp)
mov    %r13d,0xc(%rsp)
mov    0x2e72(%rip),%ecx
lea    0xdab(%rip),%rsi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2e57(%rip),%eax
mov    0x2e55(%rip),%ecx
movzbl %ch,%edx
movzbl %cl,%r15d
add    %eax,%r15d
add    %edx,%r15d
test   %eax,%eax
jle    12de <ihex_hexout+0x19e>
lea    0x2db5(%rip),%r12
lea    0xd96(%rip),%r14
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r12),%edx
mov    %rbp,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
movzbl (%r12),%eax
add    %eax,%r15d
add    $0x1,%r13
movslq 0x2dff(%rip),%rax
add    $0x4,%r12
cmp    %rax,%r13
jl     12b0 <ihex_hexout+0x170>
neg    %r15d
movzbl %r15b,%edx
lea    0xd38(%rip),%rsi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x10(%rsp),%r15
mov    %r15d,0x2dd6(%rip)
movl   $0x0,0x2dc8(%rip)
mov    0xc(%rsp),%r13d
mov    0x8(%rsp),%r12d
mov    %ebx,%r14d
mov    0x4(%rsp),%ebx
cmp    %r14d,%ebx
je     11e9 <ihex_hexout+0xa9>
lea    0xcfd(%rip),%rdi
mov    $0x9,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1060 <fwrite@plt>
mov    %r13d,%ebx
mov    %r15d,%r13d
shr    $0x18,%r13d
movzbl %r14b,%ecx
lea    0xce0(%rip),%rsi
mov    %rbp,%rdi
mov    %r13d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
add    %r14d,%r13d
mov    $0xfa,%eax
sub    %r13d,%eax
mov    %ebx,%r13d
movzbl %al,%edx
lea    0xcab(%rip),%rsi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %r12d,%r12d
jne    11ee <ihex_hexout+0xae>
jmp    1216 <ihex_hexout+0xd6>

LLVM IR (-O0):
@ihex_hexout.byte_buffer = internal global [32 x i32] zeroinitializer
@ihex_hexout.last_mem = internal global i32 0
@ihex_hexout.buffer_pos = internal global i32 0
@ihex_hexout.buffer_addr = internal global i32 0
@ihex_hexout.writing_in_progress = internal global i32 0
@.str = [24 x i8] c"seg_swap 0x%08x 0x%08x\0A\00"
@.str.1 = [12 x i8] c":%02X%04X00\00"
@.str.2 = [5 x i8] c"%02X\00"
@.str.3 = [6 x i8] c"%02X\0A\00"
@.str.4 = [10 x i8] c":04000002\00"
@.str.5 = [9 x i8] c"%02X%02X\00"
@.str.6 = [13 x i8] c":00000001FF\0A\00"
define void @ihex_hexout(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 i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
%14 = load i32, i32* @ihex_hexout.writing_in_progress
%15 = icmp ne i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %4
%17 = load i32, i32* %7
%18 = sub nsw i32 %17, 1
store i32 %18, i32* @ihex_hexout.last_mem
store i32 0, i32* @ihex_hexout.buffer_pos
%19 = load i32, i32* %7
store i32 %19, i32* @ihex_hexout.buffer_addr
store i32 1, i32* @ihex_hexout.writing_in_progress
br label %20
20: ; preds = %16, %4
%21 = load i32, i32* @ihex_hexout.last_mem
%22 = ashr i32 %21, 16
store i32 %22, i32* %12
%23 = load i32, i32* %7
%24 = ashr i32 %23, 16
store i32 %24, i32* %13
%25 = load i32, i32* %12
%26 = load i32, i32* %13
%27 = icmp ne i32 %25, %26
%28 = zext i1 %27 to i32
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %20
%32 = load i32, i32* %12
%33 = load i32, i32* %13
%34 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %32, i32 %33)
br label %35
35: ; preds = %31, %20
%36 = load i32, i32* %7
%37 = load i32, i32* @ihex_hexout.last_mem
%38 = add nsw i32 %37, 1
%39 = icmp ne i32 %36, %38
br i1 %39, label %52, label %40
40: ; preds = %35
%41 = load i32, i32* @ihex_hexout.buffer_pos
%42 = icmp sge i32 %41, 32
br i1 %42, label %52, label %43
43: ; preds = %40
%44 = load i32, i32* %8
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32, i32* @ihex_hexout.buffer_pos
%48 = icmp sgt i32 %47, 0
br i1 %48, label %52, label %49
49: ; preds = %46, %43
%50 = load i32, i32* %9
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %94
52: ; preds = %49, %46, %40, %35
%53 = load i32*, i32** %5
%54 = load i32, i32* @ihex_hexout.buffer_pos
%55 = load i32, i32* @ihex_hexout.buffer_addr
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %54, i32 %55)
%57 = load i32, i32* @ihex_hexout.buffer_pos
%58 = load i32, i32* @ihex_hexout.buffer_addr
%59 = ashr i32 %58, 8
%60 = and i32 %59, 255
%61 = add nsw i32 %57, %60
%62 = load i32, i32* @ihex_hexout.buffer_addr
%63 = and i32 %62, 255
%64 = add nsw i32 %61, %63
store i32 %64, i32* %11
store i32 0, i32* %10
br label %65
65: ; preds = %84, %52
%66 = load i32, i32* %10
%67 = load i32, i32* @ihex_hexout.buffer_pos
%68 = icmp slt i32 %66, %67
br i1 %68, label %69, label %87
69: ; preds = %65
%70 = load i32*, i32** %5
%71 = load i32, i32* %10
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [32 x i32], [32 x i32]* @ihex_hexout.byte_buffer, i64 0, i64 %72
%74 = load i32, i32* %73
%75 = and i32 %74, 255
%76 = call i32 (i32*, i8*, ...) @fprintf(i32* %70, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %75)
%77 = load i32, i32* %10
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [32 x i32], [32 x i32]* @ihex_hexout.byte_buffer, i64 0, i64 %78
%80 = load i32, i32* %79
%81 = and i32 %80, 255
%82 = load i32, i32* %11
%83 = add nsw i32 %82, %81
store i32 %83, i32* %11
br label %84
84: ; preds = %69
%85 = load i32, i32* %10
%86 = add nsw i32 %85, 1
store i32 %86, i32* %10
br label %65
87: ; preds = %65
%88 = load i32*, i32** %5
%89 = load i32, i32* %11
%90 = sub nsw i32 0, %89
%91 = and i32 %90, 255
%92 = call i32 (i32*, i8*, ...) @fprintf(i32* %88, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %91)
%93 = load i32, i32* %7
store i32 %93, i32* @ihex_hexout.buffer_addr
store i32 0, i32* @ihex_hexout.buffer_pos
br label %94
94: ; preds = %87, %49
%95 = load i32, i32* %9
%96 = icmp ne i32 %95, 0
br i1 %96, label %97, label %121
97: ; preds = %94
%98 = load i32*, i32** %5
%99 = call i32 (i32*, i8*, ...) @fprintf(i32* %98, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i32 6, i32* %11
%100 = load i32*, i32** %5
%101 = load i32, i32* %13
%102 = ashr i32 %101, 8
%103 = and i32 %102, 255
%104 = load i32, i32* %13
%105 = and i32 %104, 255
%106 = call i32 (i32*, i8*, ...) @fprintf(i32* %100, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %103, i32 %105)
%107 = load i32, i32* %13
%108 = ashr i32 %107, 8
%109 = and i32 %108, 255
%110 = load i32, i32* %11
%111 = add nsw i32 %110, %109
store i32 %111, i32* %11
%112 = load i32, i32* %13
%113 = and i32 %112, 255
%114 = load i32, i32* %11
%115 = add nsw i32 %114, %113
store i32 %115, i32* %11
%116 = load i32*, i32** %5
%117 = load i32, i32* %11
%118 = sub nsw i32 0, %117
%119 = and i32 %118, 255
%120 = call i32 (i32*, i8*, ...) @fprintf(i32* %116, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %119)
br label %121
121: ; preds = %97, %94
%122 = load i32, i32* %8
%123 = icmp ne i32 %122, 0
br i1 %123, label %124, label %129
124: ; preds = %121
%125 = load i32*, i32** %5
%126 = call i32 (i32*, i8*, ...) @fprintf(i32* %125, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%127 = load i32*, i32** %5
%128 = call i32 @fclose(i32* %127)
store i32 0, i32* @ihex_hexout.writing_in_progress
br label %129
129: ; preds = %124, %121
%130 = load i32, i32* %7
store i32 %130, i32* @ihex_hexout.last_mem
%131 = load i32, i32* %6
%132 = and i32 %131, 255
%133 = load i32, i32* @ihex_hexout.buffer_pos
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds [32 x i32], [32 x i32]* @ihex_hexout.byte_buffer, i64 0, i64 %134
store i32 %132, i32* %135
%136 = load i32, i32* @ihex_hexout.buffer_pos
%137 = add nsw i32 %136, 1
store i32 %137, i32* @ihex_hexout.buffer_pos
ret void
}

LLVM IR (-O2):
@ihex_hexout.byte_buffer = internal unnamed_addr global [32 x i32] zeroinitializer
@ihex_hexout.last_mem = internal unnamed_addr global i32 0
@ihex_hexout.buffer_pos = internal unnamed_addr global i32 0
@ihex_hexout.buffer_addr = internal unnamed_addr global i32 0
@ihex_hexout.writing_in_progress = internal unnamed_addr global i1 false
@.str = [24 x i8] c"seg_swap 0x%08x 0x%08x\0A\00"
@.str.1 = [12 x i8] c":%02X%04X00\00"
@.str.2 = [5 x i8] c"%02X\00"
@.str.3 = [6 x i8] c"%02X\0A\00"
@.str.4 = [10 x i8] c":04000002\00"
@.str.5 = [9 x i8] c"%02X%02X\00"
@.str.6 = [13 x i8] c":00000001FF\0A\00"
define void @ihex_hexout(i32* nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = load i1, i1* @ihex_hexout.writing_in_progress
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = load i32, i32* @ihex_hexout.last_mem
br label %10
8: ; preds = %4
%9 = add nsw i32 %2, -1
store i32 %9, i32* @ihex_hexout.last_mem
store i32 0, i32* @ihex_hexout.buffer_pos
store i32 %2, i32* @ihex_hexout.buffer_addr
store i1 true, i1* @ihex_hexout.writing_in_progress
br label %10
10: ; preds = %6, %8
%11 = phi i32 [ %7, %6 ], [ %9, %8 ]
%12 = ashr i32 %11, 16
%13 = ashr i32 %2, 16
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
%17 = load i32, i32* @ihex_hexout.last_mem
br label %18
18: ; preds = %15, %10
%19 = phi i32 [ %17, %15 ], [ %11, %10 ]
%20 = add nsw i32 %19, 1
%21 = icmp ne i32 %20, %2
%22 = load i32, i32* @ihex_hexout.buffer_pos
%23 = icmp sgt i32 %22, 31
%24 = select i1 %21, i1 true, i1 %23
br i1 %24, label %30, label %25
25: ; preds = %18
%26 = icmp ne i32 %3, 0
%27 = icmp sgt i32 %22, 0
%28 = select i1 %26, i1 %27, i1 false
%29 = select i1 %28, i1 true, i1 %14
br i1 %29, label %30, label %60
30: ; preds = %25, %18
%31 = load i32, i32* @ihex_hexout.buffer_addr
%32 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %31)
%33 = load i32, i32* @ihex_hexout.buffer_pos
%34 = load i32, i32* @ihex_hexout.buffer_addr
%35 = lshr i32 %34, 8
%36 = and i32 %35, 255
%37 = and i32 %34, 255
%38 = add i32 %37, %33
%39 = add i32 %38, %36
%40 = icmp sgt i32 %33, 0
br i1 %40, label %41, label %55
41: ; preds = %30, %41
%42 = phi i64 [ %51, %41 ], [ 0, %30 ]
%43 = phi i32 [ %50, %41 ], [ %39, %30 ]
%44 = getelementptr inbounds [32 x i32], [32 x i32]* @ihex_hexout.byte_buffer, i64 0, i64 %42
%45 = load i32, i32* %44
%46 = and i32 %45, 255
%47 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %44
%49 = and i32 %48, 255
%50 = add nsw i32 %49, %43
%51 = add nuw nsw i64 %42, 1
%52 = load i32, i32* @ihex_hexout.buffer_pos
%53 = sext i32 %52 to i64
%54 = icmp slt i64 %51, %53
br i1 %54, label %41, label %55
55: ; preds = %41, %30
%56 = phi i32 [ %39, %30 ], [ %50, %41 ]
%57 = sub nsw i32 0, %56
%58 = and i32 %57, 255
%59 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %58)
store i32 %2, i32* @ihex_hexout.buffer_addr
store i32 0, i32* @ihex_hexout.buffer_pos
br label %60
60: ; preds = %25, %55
br i1 %14, label %61, label %70
61: ; preds = %60
%62 = tail call i64 @fwrite(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i64 9, i64 1, i32* %0)
%63 = lshr i32 %2, 24
%64 = and i32 %13, 255
%65 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %63, i32 %64)
%66 = add nsw i32 %13, %63
%67 = sub nsw i32 250, %66
%68 = and i32 %67, 255
%69 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %68)
br label %70
70: ; preds = %61, %60
%71 = icmp eq i32 %3, 0
br i1 %71, label %75, label %72
72: ; preds = %70
%73 = tail call i64 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i64 12, i64 1, i32* %0)
%74 = tail call i32 @fclose(i32* %0)
store i1 false, i1* @ihex_hexout.writing_in_progress
br label %75
75: ; preds = %72, %70
store i32 %2, i32* @ihex_hexout.last_mem
%76 = and i32 %1, 255
%77 = load i32, i32* @ihex_hexout.buffer_pos
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [32 x i32], [32 x i32]* @ihex_hexout.byte_buffer, i64 0, i64 %78
store i32 %76, i32* %79
%80 = add nsw i32 %77, 1
store i32 %80, i32* @ihex_hexout.buffer_pos
ret void
}