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

/* Variables and functions */
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, ...);
int32_t tms_prt_bits(FILE *fp, uint8_t *msg, int32_t n, int32_t idx) {
  int32_t nc = 0;
  int32_t i, j, a;
  nc += fprintf(fp, "Hex MSB");
  for (i = n - 1; i >= idx; i--) {
    nc += fprintf(fp, "       %02X", msg[i]);
  }
  nc += fprintf(fp, " LSB\n");
  nc += fprintf(fp, "Bin MSB");
  for (i = n - 1; i >= idx; i--) {
    fprintf(fp, " ");
    a = msg[i];
    for (j = 0; j < 8; j++) {
      nc += fprintf(fp, "%1d", (a & 0x80 ? 1 : 0));
      a = a << 1;
    }
  }
  nc += fprintf(fp, " LSB\n");
  return (nc);
}


x86 assembly (clang, -O0):
<tms_prt_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec8(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     1199 <tms_prt_bits+0x89>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1155 <tms_prt_bits+0x45>
mov    -0x8(%rbp),%rdi
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     127c <tms_prt_bits+0x16c>
mov    -0x8(%rbp),%rdi
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x8,-0x24(%rbp)
jge    1269 <tms_prt_bits+0x159>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%ecx
and    $0x80,%ecx
xor    %edx,%edx
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%edx
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1213 <tms_prt_bits+0x103>
jmp    126e <tms_prt_bits+0x15e>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    11e0 <tms_prt_bits+0xd0>
mov    -0x8(%rbp),%rdi
lea    0xd8d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tms_prt_bits>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebx
mov    %edx,%r15d
mov    %rsi,0x10(%rsp)
mov    %rdi,%r12
lea    0xebe(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rax,%rbp
movslq %ebx,%r14
mov    %ebx,0xc(%rsp)
cmp    %ebx,%r15d
mov    %r15d,(%rsp)
jle    1191 <tms_prt_bits+0x71>
movslq %r15d,%rbx
lea    0xea2(%rip),%r13
mov    0x10(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    -0x4(%r15,%rbx,4),%edx
add    $0xffffffffffffffff,%rbx
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
movslq %ebp,%rbp
add    %rax,%rbp
cmp    %r14,%rbx
jg     1170 <tms_prt_bits+0x50>
lea    0xe7c(%rip),%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    %eax,%ebp
lea    0xe6f(%rip),%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    (%rsp),%eax
cmp    0xc(%rsp),%eax
jle    12dd <tms_prt_bits+0x1bd>
movslq %eax,%rbp
lea    0xe51(%rip),%r15
mov    %r14,(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x1(%rbp),%r14
mov    $0x20,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
mov    0x10(%rsp),%rax
mov    -0x4(%rax,%rbp,4),%r13d
mov    %r13d,%edx
shr    $0x7,%edx
and    $0x1,%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    %r13d,%edx
shr    $0x6,%edx
and    $0x1,%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    %r13d,%edx
shr    $0x5,%edx
and    $0x1,%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    %r13d,%edx
shr    $0x4,%edx
and    $0x1,%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    %r13d,%edx
shr    $0x3,%edx
and    $0x1,%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    %r13d,%edx
shr    $0x2,%edx
and    $0x1,%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    %r13d,%edx
shr    %edx
and    $0x1,%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rax,%rbp
add    %ebx,%ebp
and    $0x1,%r13d
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    %r14,%rbp
cmp    (%rsp),%r14
jg     11e0 <tms_prt_bits+0xc0>
lea    0xd30(%rip),%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"Hex MSB\00"
@.str.1 = [12 x i8] c" %02X\00"
@.str.2 = [6 x i8] c" LSB\0A\00"
@.str.3 = [8 x i8] c"Bin MSB\00"
@.str.4 = [2 x i8] c" \00"
@.str.5 = [4 x i8] c"%1d\00"
define i32 @tms_prt_bits(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
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
%13 = load i32*, i32** %5
%14 = call i64 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* %9
%16 = sext i32 %15 to i64
%17 = add nsw i64 %16, %14
%18 = trunc i64 %17 to i32
store i32 %18, i32* %9
%19 = load i32, i32* %7
%20 = sub nsw i32 %19, 1
store i32 %20, i32* %10
br label %21
21: ; preds = %37, %4
%22 = load i32, i32* %10
%23 = load i32, i32* %8
%24 = icmp sge i32 %22, %23
br i1 %24, label %25, label %40
25: ; preds = %21
%26 = load i32*, i32** %5
%27 = load i32*, i32** %6
%28 = load i32, i32* %10
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = call i64 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = add nsw i64 %34, %32
%36 = trunc i64 %35 to i32
store i32 %36, i32* %9
br label %37
37: ; preds = %25
%38 = load i32, i32* %10
%39 = add nsw i32 %38, -1
store i32 %39, i32* %10
br label %21
40: ; preds = %21
%41 = load i32*, i32** %5
%42 = call i64 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = add nsw i64 %44, %42
%46 = trunc i64 %45 to i32
store i32 %46, i32* %9
%47 = load i32*, i32** %5
%48 = call i64 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = add nsw i64 %50, %48
%52 = trunc i64 %51 to i32
store i32 %52, i32* %9
%53 = load i32, i32* %7
%54 = sub nsw i32 %53, 1
store i32 %54, i32* %10
br label %55
55: ; preds = %88, %40
%56 = load i32, i32* %10
%57 = load i32, i32* %8
%58 = icmp sge i32 %56, %57
br i1 %58, label %59, label %91
59: ; preds = %55
%60 = load i32*, i32** %5
%61 = call i64 (i32*, i8*, ...) @fprintf(i32* %60, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%62 = load i32*, i32** %6
%63 = load i32, i32* %10
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i32, i32* %62, i64 %64
%66 = load i32, i32* %65
store i32 %66, i32* %12
store i32 0, i32* %11
br label %67
67: ; preds = %84, %59
%68 = load i32, i32* %11
%69 = icmp slt i32 %68, 8
br i1 %69, label %70, label %87
70: ; preds = %67
%71 = load i32*, i32** %5
%72 = load i32, i32* %12
%73 = and i32 %72, 128
%74 = icmp ne i32 %73, 0
%75 = zext i1 %74 to i64
%76 = select i1 %74, i32 1, i32 0
%77 = call i64 (i32*, i8*, ...) @fprintf(i32* %71, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %76)
%78 = load i32, i32* %9
%79 = sext i32 %78 to i64
%80 = add nsw i64 %79, %77
%81 = trunc i64 %80 to i32
store i32 %81, i32* %9
%82 = load i32, i32* %12
%83 = shl i32 %82, 1
store i32 %83, i32* %12
br label %84
84: ; preds = %70
%85 = load i32, i32* %11
%86 = add nsw i32 %85, 1
store i32 %86, i32* %11
br label %67
87: ; preds = %67
br label %88
88: ; preds = %87
%89 = load i32, i32* %10
%90 = add nsw i32 %89, -1
store i32 %90, i32* %10
br label %55
91: ; preds = %55
%92 = load i32*, i32** %5
%93 = call i64 (i32*, i8*, ...) @fprintf(i32* %92, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%94 = load i32, i32* %9
%95 = sext i32 %94 to i64
%96 = add nsw i64 %95, %93
%97 = trunc i64 %96 to i32
store i32 %97, i32* %9
%98 = load i32, i32* %9
ret i32 %98
}

LLVM IR (-O2):
@.str = [8 x i8] c"Hex MSB\00"
@.str.1 = [12 x i8] c" %02X\00"
@.str.2 = [6 x i8] c" LSB\0A\00"
@.str.3 = [8 x i8] c"Bin MSB\00"
@.str.5 = [4 x i8] c"%1d\00"
define i32 @tms_prt_bits(i32* nocapture %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = icmp sgt i32 %2, %3
br i1 %6, label %7, label %21
7: ; preds = %4
%8 = sext i32 %2 to i64
%9 = sext i32 %3 to i64
br label %10
10: ; preds = %7, %10
%11 = phi i64 [ %8, %7 ], [ %13, %10 ]
%12 = phi i64 [ %5, %7 ], [ %19, %10 ]
%13 = add nsw i64 %11, -1
%14 = getelementptr inbounds i32, i32* %1, i64 %13
%15 = load i32, i32* %14
%16 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = shl i64 %12, 32
%18 = ashr exact i64 %17, 32
%19 = add nsw i64 %16, %18
%20 = icmp sgt i64 %13, %9
br i1 %20, label %10, label %21
21: ; preds = %10, %4
%22 = phi i64 [ %5, %4 ], [ %19, %10 ]
%23 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%24 = add i64 %23, %22
%25 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%26 = add i64 %24, %25
%27 = trunc i64 %26 to i32
br i1 %6, label %28, label %78
28: ; preds = %21
%29 = sext i32 %2 to i64
%30 = sext i32 %3 to i64
br label %31
31: ; preds = %28, %31
%32 = phi i64 [ %29, %28 ], [ %34, %31 ]
%33 = phi i32 [ %27, %28 ], [ %76, %31 ]
%34 = add nsw i64 %32, -1
%35 = tail call i32 @fputc(i32 32, i32* %0)
%36 = getelementptr inbounds i32, i32* %1, i64 %34
%37 = load i32, i32* %36
%38 = lshr i32 %37, 7
%39 = and i32 %38, 1
%40 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %39)
%41 = trunc i64 %40 to i32
%42 = add i32 %33, %41
%43 = lshr i32 %37, 6
%44 = and i32 %43, 1
%45 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %44)
%46 = trunc i64 %45 to i32
%47 = add i32 %42, %46
%48 = lshr i32 %37, 5
%49 = and i32 %48, 1
%50 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %49)
%51 = trunc i64 %50 to i32
%52 = add i32 %47, %51
%53 = lshr i32 %37, 4
%54 = and i32 %53, 1
%55 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %54)
%56 = trunc i64 %55 to i32
%57 = add i32 %52, %56
%58 = lshr i32 %37, 3
%59 = and i32 %58, 1
%60 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %59)
%61 = trunc i64 %60 to i32
%62 = add i32 %57, %61
%63 = lshr i32 %37, 2
%64 = and i32 %63, 1
%65 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %64)
%66 = trunc i64 %65 to i32
%67 = add i32 %62, %66
%68 = lshr i32 %37, 1
%69 = and i32 %68, 1
%70 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %69)
%71 = trunc i64 %70 to i32
%72 = add i32 %67, %71
%73 = and i32 %37, 1
%74 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %73)
%75 = trunc i64 %74 to i32
%76 = add i32 %72, %75
%77 = icmp sgt i64 %34, %30
br i1 %77, label %31, label %78
78: ; preds = %31, %21
%79 = phi i32 [ %27, %21 ], [ %76, %31 ]
%80 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%81 = trunc i64 %80 to i32
%82 = add i32 %79, %81
ret i32 %82
}