#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;

/* Variables and functions */
int get_num_bytes(int);
int /*<<< orphan*/ printf(char *, int);
void print_dek(uint32_t utf16) {
  int n = (get_num_bytes(utf16) <= 2) ? 2 : 4;
  for (int i = n - 1; i >= 0; i--) {
    printf("%03d", (utf16 >> i * 8) & 0xff);
  }
}


x86 assembly (clang, -O0):
<print_dek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <get_num_bytes@plt>
mov    %eax,%edx
mov    $0x4,%eax
mov    $0x2,%ecx
cmp    $0x2,%edx
cmovle %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1186 <print_dek+0x66>
mov    -0x4(%rbp),%esi
mov    -0xc(%rbp),%ecx
shl    $0x3,%ecx
sar    %cl,%esi
and    $0xff,%esi
lea    0xe8d(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1151 <print_dek+0x31>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_dek>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
call   1030 <get_num_bytes@plt>
xor    %ebp,%ebp
cmp    $0x3,%eax
setge  %bpl
shl    $0x4,%ebp
or     $0x8,%ebp
lea    0xebf(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
mov    %ebp,%ecx
sar    %cl,%eax
movzbl %al,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0xfffffff8,%ebp
cmp    $0xfffffff8,%ebp
jne    1150 <print_dek+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%03d\00"
define void @print_dek(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @get_num_bytes(i32 %5)
%7 = icmp sle i32 %6, 2
%8 = zext i1 %7 to i64
%9 = select i1 %7, i32 2, i32 4
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = sub nsw i32 %10, 1
store i32 %11, i32* %4
br label %12
12: ; preds = %22, %1
%13 = load i32, i32* %4
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = load i32, i32* %2
%17 = load i32, i32* %4
%18 = mul nsw i32 %17, 8
%19 = ashr i32 %16, %18
%20 = and i32 %19, 255
%21 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %15
%23 = load i32, i32* %4
%24 = add nsw i32 %23, -1
store i32 %24, i32* %4
br label %12
25: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%03d\00"
define void @print_dek(i32 %0) {
%2 = tail call i32 @get_num_bytes(i32 %0)
%3 = icmp slt i32 %2, 3
%4 = select i1 %3, i32 1, i32 3
br label %6
5: ; preds = %6
ret void
6: ; preds = %1, %6
%7 = phi i32 [ %4, %1 ], [ %12, %6 ]
%8 = shl nsw i32 %7, 3
%9 = ashr i32 %0, %8
%10 = and i32 %9, 255
%11 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = add nsw i32 %7, -1
%13 = icmp eq i32 %7, 0
br i1 %13, label %5, label %6
}