unsigned int databits_decode_uic(char *output, unsigned long long input,
                                 unsigned int type) {
  int written;
  if (!output) {
    return 0;
  }
  unsigned int code = (unsigned int)bit_reverse(bit_window(input, 24, 8), 8);
  written = sprintf(output, "Train ID: %X%X%X%X%X%X - Message: %02X (%s)\n",
                    (unsigned int)bit_window(input, 0, 4),
                    (unsigned int)bit_window(input, 4, 4),
                    (unsigned int)bit_window(input, 8, 4),
                    (unsigned int)bit_window(input, 12, 4),
                    (unsigned int)bit_window(input, 16, 4),
                    (unsigned int)bit_window(input, 20, 4), code,
                    uic_message_meaning(code, type));
  return written;
}


x86 assembly (clang, -O0):
<databits_decode_uic>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x68,%rsp
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %edx,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116b <databits_decode_uic+0x2b>
movl   $0x0,-0xc(%rbp)
jmp    1277 <databits_decode_uic+0x137>
mov    -0x20(%rbp),%rdi
mov    $0x18,%esi
mov    $0x8,%edx
mov    $0x0,%al
call   1040 <bit_window@plt>
mov    %eax,%edi
mov    $0x8,%esi
mov    $0x0,%al
call   1030 <bit_reverse@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
mov    $0x0,%al
call   1040 <bit_window@plt>
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x4,%edx
mov    %edx,%esi
mov    $0x0,%al
call   1040 <bit_window@plt>
mov    %eax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x8,%esi
mov    $0x4,%edx
mov    $0x0,%al
call   1040 <bit_window@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0xc,%esi
mov    $0x4,%edx
mov    $0x0,%al
call   1040 <bit_window@plt>
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x10,%esi
mov    $0x4,%edx
mov    $0x0,%al
call   1040 <bit_window@plt>
mov    %eax,%ebx
mov    -0x20(%rbp),%rdi
mov    $0x14,%esi
mov    $0x4,%edx
mov    $0x0,%al
call   1040 <bit_window@plt>
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    $0x0,%al
call   1050 <uic_message_meaning@plt>
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%edx
mov    -0x40(%rbp),%ecx
mov    -0x3c(%rbp),%r8d
mov    -0x38(%rbp),%r9d
mov    -0x34(%rbp),%r11d
mov    -0x30(%rbp),%r10d
lea    0xdaa(%rip),%rsi
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %eax,0x18(%rsp)
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<databits_decode_uic>:
test   %rdi,%rdi
je     1251 <databits_decode_uic+0x111>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %rsi,%rbp
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x18,%esi
mov    $0x8,%edx
xor    %eax,%eax
call   1040 <bit_window@plt>
mov    %eax,%edi
mov    $0x8,%esi
xor    %eax,%eax
call   1030 <bit_reverse@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <bit_window@plt>
mov    %eax,0x14(%rsp)
mov    %rbp,%rdi
mov    $0x4,%esi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <bit_window@plt>
mov    %eax,0x10(%rsp)
mov    %rbp,%rdi
mov    $0x8,%esi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <bit_window@plt>
mov    %eax,0xc(%rsp)
mov    %rbp,%rdi
mov    $0xc,%esi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <bit_window@plt>
mov    %eax,%r13d
mov    %rbp,%rdi
mov    $0x10,%esi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <bit_window@plt>
mov    %eax,%r12d
mov    %rbp,%rdi
mov    $0x14,%esi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <bit_window@plt>
mov    %eax,%ebp
mov    %r15d,%edi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <uic_message_meaning@plt>
mov    %eax,%ebx
lea    0xdde(%rip),%rsi
mov    %r14,%rdi
mov    0x14(%rsp),%edx
mov    0x10(%rsp),%ecx
mov    0xc(%rsp),%r8d
mov    %r13d,%r9d
xor    %eax,%eax
push   %rbx
push   %r15
push   %rbp
push   %r12
call   1060 <sprintf@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [45 x i8] c"Train ID: %X%X%X%X%X%X - Message: %02X (%s)\0A\00"
define i32 @databits_decode_uic(i8* %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %3
store i32 0, i32* %4
br label %36
13: ; preds = %3
%14 = load i64, i64* %6
%15 = call i32 (i64, i32, i32, ...) bitcast (i32 (...)* @bit_window to i32 (i64, i32, i32, ...)*)(i64 %14, i32 24, i32 8)
%16 = call i32 (i32, i32, ...) bitcast (i32 (...)* @bit_reverse to i32 (i32, i32, ...)*)(i32 %15, i32 8)
store i32 %16, i32* %9
%17 = load i8*, i8** %5
%18 = load i64, i64* %6
%19 = call i32 (i64, i32, i32, ...) bitcast (i32 (...)* @bit_window to i32 (i64, i32, i32, ...)*)(i64 %18, i32 0, i32 4)
%20 = load i64, i64* %6
%21 = call i32 (i64, i32, i32, ...) bitcast (i32 (...)* @bit_window to i32 (i64, i32, i32, ...)*)(i64 %20, i32 4, i32 4)
%22 = load i64, i64* %6
%23 = call i32 (i64, i32, i32, ...) bitcast (i32 (...)* @bit_window to i32 (i64, i32, i32, ...)*)(i64 %22, i32 8, i32 4)
%24 = load i64, i64* %6
%25 = call i32 (i64, i32, i32, ...) bitcast (i32 (...)* @bit_window to i32 (i64, i32, i32, ...)*)(i64 %24, i32 12, i32 4)
%26 = load i64, i64* %6
%27 = call i32 (i64, i32, i32, ...) bitcast (i32 (...)* @bit_window to i32 (i64, i32, i32, ...)*)(i64 %26, i32 16, i32 4)
%28 = load i64, i64* %6
%29 = call i32 (i64, i32, i32, ...) bitcast (i32 (...)* @bit_window to i32 (i64, i32, i32, ...)*)(i64 %28, i32 20, i32 4)
%30 = load i32, i32* %9
%31 = load i32, i32* %9
%32 = load i32, i32* %7
%33 = call i32 (i32, i32, ...) bitcast (i32 (...)* @uic_message_meaning to i32 (i32, i32, ...)*)(i32 %31, i32 %32)
%34 = call i32 (i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %21, i32 %23, i32 %25, i32 %27, i32 %29, i32 %30, i32 %33)
store i32 %34, i32* %8
%35 = load i32, i32* %8
store i32 %35, i32* %4
br label %36
36: ; preds = %13, %12
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
@.str = [45 x i8] c"Train ID: %X%X%X%X%X%X - Message: %02X (%s)\0A\00"
define i32 @databits_decode_uic(i8* writeonly %0, i64 %1, i32 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %16, label %5
5: ; preds = %3
%6 = tail call i32 (i64, i32, i32, ...) bitcast (i32 (...)* @bit_window to i32 (i64, i32, i32, ...)*)(i64 %1, i32 24, i32 8)
%7 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @bit_reverse to i32 (i32, i32, ...)*)(i32 %6, i32 8)
%8 = tail call i32 (i64, i32, i32, ...) bitcast (i32 (...)* @bit_window to i32 (i64, i32, i32, ...)*)(i64 %1, i32 0, i32 4)
%9 = tail call i32 (i64, i32, i32, ...) bitcast (i32 (...)* @bit_window to i32 (i64, i32, i32, ...)*)(i64 %1, i32 4, i32 4)
%10 = tail call i32 (i64, i32, i32, ...) bitcast (i32 (...)* @bit_window to i32 (i64, i32, i32, ...)*)(i64 %1, i32 8, i32 4)
%11 = tail call i32 (i64, i32, i32, ...) bitcast (i32 (...)* @bit_window to i32 (i64, i32, i32, ...)*)(i64 %1, i32 12, i32 4)
%12 = tail call i32 (i64, i32, i32, ...) bitcast (i32 (...)* @bit_window to i32 (i64, i32, i32, ...)*)(i64 %1, i32 16, i32 4)
%13 = tail call i32 (i64, i32, i32, ...) bitcast (i32 (...)* @bit_window to i32 (i64, i32, i32, ...)*)(i64 %1, i32 20, i32 4)
%14 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @uic_message_meaning to i32 (i32, i32, ...)*)(i32 %7, i32 %2)
%15 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9, i32 %10, i32 %11, i32 %12, i32 %13, i32 %7, i32 %14)
br label %16
16: ; preds = %3, %5
%17 = phi i32 [ %15, %5 ], [ 0, %3 ]
ret i32 %17
}