#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*/ printf(char *, unsigned char, ...);
void line2hex(unsigned short nb, unsigned char i, unsigned char *line) {
  unsigned int j;
  unsigned char ck = 0;
  printf(":%02X%04X00", i, nb);
  ck -= i;
  ck -= nb & 0xFF;
  ck -= (nb >> 8) & 0xFF;
  for (j = 0; j < i; j++) {
    ck -= line[j];
    printf("%02X", line[j]);
  }
  printf("%02X\n", ck);
}


x86 assembly (clang, -O0):
<line2hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %di,%cx
mov    %cx,-0x2(%rbp)
mov    %al,-0x3(%rbp)
mov    %rdx,-0x10(%rbp)
movb   $0x0,-0x15(%rbp)
mov    -0x3(%rbp),%al
movzwl -0x2(%rbp),%edx
lea    0xec5(%rip),%rdi
movzbl %al,%esi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0x3(%rbp),%ecx
movzbl -0x15(%rbp),%eax
sub    %ecx,%eax
mov    %al,-0x15(%rbp)
movzwl -0x2(%rbp),%ecx
and    $0xff,%ecx
movzbl -0x15(%rbp),%eax
sub    %ecx,%eax
mov    %al,-0x15(%rbp)
movzwl -0x2(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
movzbl -0x15(%rbp),%eax
sub    %ecx,%eax
mov    %al,-0x15(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
movzbl -0x3(%rbp),%ecx
cmp    %ecx,%eax
jae    11cc <line2hex+0xbc>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movzbl (%rax,%rcx,1),%ecx
movzbl -0x15(%rbp),%eax
sub    %ecx,%eax
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
lea    0xe59(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1182 <line2hex+0x72>
lea    0xe3e(%rip),%rdi
movzbl -0x15(%rbp),%esi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<line2hex>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%r13d
lea    0xed7(%rip),%rdi
mov    %r13d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    (%r15,%r13,1),%eax
shr    $0x8,%r13d
add    %al,%r13b
neg    %r13b
test   %r15d,%r15d
je     117b <line2hex+0x6b>
movzbl %r15b,%r12d
lea    0xebb(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r14,%rbx,1),%esi
sub    %sil,%r13b
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <line2hex+0x50>
movzbl %r13b,%esi
lea    0xe8b(%rip),%rdi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [12 x i8] c":%02X%04X00\00"
@.str.1 = [5 x i8] c"%02X\00"
@.str.2 = [6 x i8] c"%02X\0A\00"
define void @line2hex(i16 zeroext %0, i8 zeroext %1, i8* %2) {
%4 = alloca i16
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8
store i16 %0, i16* %4
store i8 %1, i8* %5
store i8* %2, i8** %6
store i8 0, i8* %8
%9 = load i8, i8* %5
%10 = load i16, i16* %4
%11 = zext i16 %10 to i32
%12 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8 zeroext %9, i32 %11)
%13 = load i8, i8* %5
%14 = zext i8 %13 to i32
%15 = load i8, i8* %8
%16 = zext i8 %15 to i32
%17 = sub nsw i32 %16, %14
%18 = trunc i32 %17 to i8
store i8 %18, i8* %8
%19 = load i16, i16* %4
%20 = zext i16 %19 to i32
%21 = and i32 %20, 255
%22 = load i8, i8* %8
%23 = zext i8 %22 to i32
%24 = sub nsw i32 %23, %21
%25 = trunc i32 %24 to i8
store i8 %25, i8* %8
%26 = load i16, i16* %4
%27 = zext i16 %26 to i32
%28 = ashr i32 %27, 8
%29 = and i32 %28, 255
%30 = load i8, i8* %8
%31 = zext i8 %30 to i32
%32 = sub nsw i32 %31, %29
%33 = trunc i32 %32 to i8
store i8 %33, i8* %8
store i32 0, i32* %7
br label %34
34: ; preds = %56, %3
%35 = load i32, i32* %7
%36 = load i8, i8* %5
%37 = zext i8 %36 to i32
%38 = icmp ult i32 %35, %37
br i1 %38, label %39, label %59
39: ; preds = %34
%40 = load i8*, i8** %6
%41 = load i32, i32* %7
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = load i8, i8* %8
%47 = zext i8 %46 to i32
%48 = sub nsw i32 %47, %45
%49 = trunc i32 %48 to i8
store i8 %49, i8* %8
%50 = load i8*, i8** %6
%51 = load i32, i32* %7
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %54)
br label %56
56: ; preds = %39
%57 = load i32, i32* %7
%58 = add i32 %57, 1
store i32 %58, i32* %7
br label %34
59: ; preds = %34
%60 = load i8, i8* %8
%61 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %60)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c":%02X%04X00\00"
@.str.1 = [5 x i8] c"%02X\00"
@.str.2 = [6 x i8] c"%02X\0A\00"
define void @line2hex(i16 zeroext %0, i8 zeroext %1, i8* nocapture %2) {
%4 = zext i16 %0 to i32
%5 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8 zeroext %1, i32 %4)
%6 = trunc i16 %0 to i8
%7 = add i8 %6, %1
%8 = lshr i16 %0, 8
%9 = trunc i16 %8 to i8
%10 = add i8 %7, %9
%11 = sub i8 0, %10
%12 = icmp eq i8 %1, 0
br i1 %12, label %24, label %13
13: ; preds = %3
%14 = zext i8 %1 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %22, %15 ]
%17 = phi i8 [ %11, %13 ], [ %20, %15 ]
%18 = getelementptr inbounds i8, i8* %2, i64 %16
%19 = load i8, i8* %18
%20 = sub i8 %17, %19
%21 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %19)
%22 = add nuw nsw i64 %16, 1
%23 = icmp eq i64 %22, %14
br i1 %23, label %24, label %15
24: ; preds = %15, %3
%25 = phi i8 [ %11, %3 ], [ %20, %15 ]
%26 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %25)
ret void
}