#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 */

/* Variables and functions */
int /*<<< orphan*/ analyse(char *, size_t, char *, size_t, char *, size_t);
int /*<<< orphan*/ clamp_buf_len(size_t *, size_t *);
int /*<<< orphan*/ free(char *);
size_t line_len(char *, char *);
char *malloc(size_t);
int max_lines(size_t, size_t);
int /*<<< orphan*/ render_line(char **, char *, size_t, char *, size_t, int,
                               char *);
void hexcdiff(void *_expect_buf, size_t expect_buf_len, void *_actual_buf,
              size_t actual_buf_len, char *msg) {
  char *expect_buf = (char *)_expect_buf;
  char *actual_buf = (char *)_actual_buf;
  char *mark_buf;
  size_t mark_buf_len;
  char *mark_buf_end;
  char *msg_ptr = msg;
  char *mark_buf_idx;
  char *expect_buf_idx = expect_buf;
  char *expect_buf_end = expect_buf + expect_buf_len;
  char *actual_buf_idx = actual_buf;
  char *actual_buf_end = actual_buf + actual_buf_len;
  int offset = 0;
  clamp_buf_len(&expect_buf_len, &actual_buf_len);
  mark_buf_len = max_lines(expect_buf_len, actual_buf_len) * 16;
  mark_buf = malloc(mark_buf_len);
  mark_buf_end = mark_buf + mark_buf_len;
  mark_buf_idx = mark_buf;
  analyse(expect_buf, expect_buf_len, actual_buf, actual_buf_len, mark_buf,
          mark_buf_len);
  while (mark_buf_idx < mark_buf_end) {
    size_t expect_line_len = line_len(expect_buf_idx, expect_buf_end);
    size_t actual_line_len = line_len(actual_buf_idx, actual_buf_end);
    render_line(&msg_ptr, expect_buf_idx, expect_line_len, actual_buf_idx,
                actual_line_len, offset, mark_buf_idx);
    mark_buf_idx += 16;
    expect_buf_idx += expect_line_len;
    actual_buf_idx += actual_line_len;
    offset += 16;
  }
  free(mark_buf);
}


x86 assembly (clang, -O0):
<hexcdiff>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x30(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x38(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x80(%rbp)
movl   $0x0,-0x84(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <clamp_buf_len@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <max_lines@plt>
shl    $0x4,%eax
cltq
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x40(%rbp),%r8
mov    -0x48(%rbp),%r9
call   1060 <analyse@plt>
mov    -0x60(%rbp),%rax
cmp    -0x50(%rbp),%rax
jae    12dc <hexcdiff+0x16c>
mov    -0x68(%rbp),%rdi
mov    -0x70(%rbp),%rsi
call   1090 <line_len@plt>
mov    %rax,-0x90(%rbp)
mov    -0x78(%rbp),%rdi
mov    -0x80(%rbp),%rsi
call   1090 <line_len@plt>
mov    %rax,-0x98(%rbp)
mov    -0x68(%rbp),%rsi
mov    -0x90(%rbp),%rdx
mov    -0x78(%rbp),%rcx
mov    -0x98(%rbp),%r8
mov    -0x84(%rbp),%r9d
mov    -0x60(%rbp),%rax
lea    -0x58(%rbp),%rdi
mov    %rax,(%rsp)
call   1040 <render_line@plt>
mov    -0x60(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x60(%rbp)
mov    -0x90(%rbp),%rax
add    -0x68(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x98(%rbp),%rax
add    -0x78(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x84(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x84(%rbp)
jmp    123a <hexcdiff+0xca>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexcdiff>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%r12
mov    %rdi,%rbx
mov    %rsi,0x28(%rsp)
mov    %rsi,0x18(%rsp)
mov    %rcx,0x30(%rsp)
mov    %rcx,0x10(%rsp)
mov    %r8,0x40(%rsp)
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1080 <clamp_buf_len@plt>
mov    0x18(%rsp),%rdi
mov    0x10(%rsp),%rsi
call   1050 <max_lines@plt>
mov    %eax,%r14d
shl    $0x4,%eax
movslq %eax,%rbp
mov    %rbp,%rdi
call   1070 <malloc@plt>
mov    0x18(%rsp),%rsi
mov    0x10(%rsp),%rcx
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %rax,0x8(%rsp)
mov    %rax,%r8
mov    %rbp,0x20(%rsp)
mov    %rbp,%r9
call   1060 <analyse@plt>
test   %r14d,%r14d
jle    1284 <hexcdiff+0x114>
add    %rbx,0x28(%rsp)
add    %r12,0x30(%rsp)
mov    0x8(%rsp),%rax
add    %rax,0x20(%rsp)
xor    %r14d,%r14d
mov    0x8(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
lea    (%r14,%rbp,1),%rax
mov    %rax,0x38(%rsp)
mov    %rbx,%rdi
mov    0x28(%rsp),%rsi
call   1090 <line_len@plt>
mov    %rax,%r15
mov    %r12,%rdi
mov    0x30(%rsp),%rsi
call   1090 <line_len@plt>
mov    %rax,%r13
mov    0x38(%rsp),%rax
mov    %rax,(%rsp)
lea    0x40(%rsp),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
mov    %r14d,%r9d
call   1040 <render_line@plt>
add    %r15,%rbx
add    %r13,%r12
lea    (%r14,%rbp,1),%rax
add    $0x10,%rax
add    $0x10,%r14
cmp    0x20(%rsp),%rax
jb     1220 <hexcdiff+0xb0>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @hexcdiff(i8* %0, i64 %1, i8* %2, i64 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i8*
%21 = alloca i8*
%22 = alloca i32
%23 = alloca i64
%24 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store i8* %4, i8** %10
%25 = load i8*, i8** %6
store i8* %25, i8** %11
%26 = load i8*, i8** %8
store i8* %26, i8** %12
%27 = load i8*, i8** %10
store i8* %27, i8** %16
%28 = load i8*, i8** %11
store i8* %28, i8** %18
%29 = load i8*, i8** %11
%30 = load i64, i64* %7
%31 = getelementptr inbounds i8, i8* %29, i64 %30
store i8* %31, i8** %19
%32 = load i8*, i8** %12
store i8* %32, i8** %20
%33 = load i8*, i8** %12
%34 = load i64, i64* %9
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8* %35, i8** %21
store i32 0, i32* %22
%36 = call i32 @clamp_buf_len(i64* %7, i64* %9)
%37 = load i64, i64* %7
%38 = load i64, i64* %9
%39 = call i32 @max_lines(i64 %37, i64 %38)
%40 = mul nsw i32 %39, 16
%41 = sext i32 %40 to i64
store i64 %41, i64* %14
%42 = load i64, i64* %14
%43 = call i8* @malloc(i64 %42)
store i8* %43, i8** %13
%44 = load i8*, i8** %13
%45 = load i64, i64* %14
%46 = getelementptr inbounds i8, i8* %44, i64 %45
store i8* %46, i8** %15
%47 = load i8*, i8** %13
store i8* %47, i8** %17
%48 = load i8*, i8** %11
%49 = load i64, i64* %7
%50 = load i8*, i8** %12
%51 = load i64, i64* %9
%52 = load i8*, i8** %13
%53 = load i64, i64* %14
%54 = call i32 @analyse(i8* %48, i64 %49, i8* %50, i64 %51, i8* %52, i64 %53)
br label %55
55: ; preds = %59, %5
%56 = load i8*, i8** %17
%57 = load i8*, i8** %15
%58 = icmp ult i8* %56, %57
br i1 %58, label %59, label %83
59: ; preds = %55
%60 = load i8*, i8** %18
%61 = load i8*, i8** %19
%62 = call i64 @line_len(i8* %60, i8* %61)
store i64 %62, i64* %23
%63 = load i8*, i8** %20
%64 = load i8*, i8** %21
%65 = call i64 @line_len(i8* %63, i8* %64)
store i64 %65, i64* %24
%66 = load i8*, i8** %18
%67 = load i64, i64* %23
%68 = load i8*, i8** %20
%69 = load i64, i64* %24
%70 = load i32, i32* %22
%71 = load i8*, i8** %17
%72 = call i32 @render_line(i8** %16, i8* %66, i64 %67, i8* %68, i64 %69, i32 %70, i8* %71)
%73 = load i8*, i8** %17
%74 = getelementptr inbounds i8, i8* %73, i64 16
store i8* %74, i8** %17
%75 = load i64, i64* %23
%76 = load i8*, i8** %18
%77 = getelementptr inbounds i8, i8* %76, i64 %75
store i8* %77, i8** %18
%78 = load i64, i64* %24
%79 = load i8*, i8** %20
%80 = getelementptr inbounds i8, i8* %79, i64 %78
store i8* %80, i8** %20
%81 = load i32, i32* %22
%82 = add nsw i32 %81, 16
store i32 %82, i32* %22
br label %55
83: ; preds = %55
%84 = load i8*, i8** %13
%85 = call i32 @free(i8* %84)
ret void
}

LLVM IR (-O2):
define void @hexcdiff(i8* %0, i64 %1, i8* %2, i64 %3, i8* %4) {
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i64 %1, i64* %6
store i64 %3, i64* %7
%9 = bitcast i8** %8 to i8*
store i8* %4, i8** %8
%10 = getelementptr inbounds i8, i8* %0, i64 %1
%11 = getelementptr inbounds i8, i8* %2, i64 %3
%12 = call i32 @clamp_buf_len(i64* %6, i64* %7)
%13 = load i64, i64* %6
%14 = load i64, i64* %7
%15 = call i32 @max_lines(i64 %13, i64 %14)
%16 = shl nsw i32 %15, 4
%17 = sext i32 %16 to i64
%18 = call i8* @malloc(i64 %17)
%19 = getelementptr inbounds i8, i8* %18, i64 %17
%20 = load i64, i64* %6
%21 = load i64, i64* %7
%22 = call i32 @analyse(i8* %0, i64 %20, i8* %2, i64 %21, i8* %18, i64 %17)
%23 = icmp sgt i32 %15, 0
br i1 %23, label %24, label %37
24: ; preds = %5, %24
%25 = phi i8* [ %32, %24 ], [ %18, %5 ]
%26 = phi i8* [ %33, %24 ], [ %0, %5 ]
%27 = phi i32 [ %35, %24 ], [ 0, %5 ]
%28 = phi i8* [ %34, %24 ], [ %2, %5 ]
%29 = call i64 @line_len(i8* %26, i8* %10)
%30 = call i64 @line_len(i8* %28, i8* %11)
%31 = call i32 @render_line(i8** %8, i8* %26, i64 %29, i8* %28, i64 %30, i32 %27, i8* %25)
%32 = getelementptr inbounds i8, i8* %25, i64 16
%33 = getelementptr inbounds i8, i8* %26, i64 %29
%34 = getelementptr inbounds i8, i8* %28, i64 %30
%35 = add nuw nsw i32 %27, 16
%36 = icmp ult i8* %32, %19
br i1 %36, label %24, label %37
37: ; preds = %24, %5
%38 = call i32 @free(i8* %18)
ret void
}