#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 *, char);
void print_ch(int n) {
  int buffer[4];
  for (int i = 0; i < 4; ++i) {
    buffer[i] = n & 255;
    n >>= 8;
  }
  for (int i = 3; i >= 0; ++i)
    printf("%c", (char)buffer[i]);
}


x86 assembly (clang, -O0):
<print_ch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    1154 <print_ch+0x44>
mov    -0x4(%rbp),%ecx
and    $0xff,%ecx
movslq -0x24(%rbp),%rax
mov    %ecx,-0x20(%rbp,%rax,4)
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x4(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1122 <print_ch+0x12>
movl   $0x3,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     118a <print_ch+0x7a>
movslq -0x28(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%eax
lea    0xe8c(%rip),%rdi
movsbl %al,%esi
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    115b <print_ch+0x4b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_ch>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%eax
movzbl %al,%ecx
mov    %ecx,(%rsp)
movzbl %ah,%ecx
mov    %ecx,0x4(%rsp)
mov    %edi,%ecx
shr    $0x10,%ecx
movzbl %cl,%ecx
mov    %ecx,0x8(%rsp)
shr    $0x18,%eax
mov    %eax,0xc(%rsp)
lea    0x10(%rsp),%rbx
lea    0xebb(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %al,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    (%rbx),%eax
add    $0x4,%rbx
jmp    1150 <print_ch+0x40>

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define void @print_ch(i32 %0) {
%2 = alloca i32
%3 = alloca [4 x i32]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
br label %6
6: ; preds = %17, %1
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 4
br i1 %8, label %9, label %20
9: ; preds = %6
%10 = load i32, i32* %2
%11 = and i32 %10, 255
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %13
store i32 %11, i32* %14
%15 = load i32, i32* %2
%16 = ashr i32 %15, 8
store i32 %16, i32* %2
br label %17
17: ; preds = %9
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %6
20: ; preds = %6
store i32 3, i32* %5
br label %21
21: ; preds = %31, %20
%22 = load i32, i32* %5
%23 = icmp sge i32 %22, 0
br i1 %23, label %24, label %34
24: ; preds = %21
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = trunc i32 %28 to i8
%30 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %29)
br label %31
31: ; preds = %24
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %21
34: ; preds = %21
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define void @print_ch(i32 %0) {
%2 = alloca [4 x i32]
%3 = bitcast [4 x i32]* %2 to i8*
%4 = and i32 %0, 255
%5 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
store i32 %4, i32* %5
%6 = lshr i32 %0, 8
%7 = and i32 %6, 255
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
store i32 %7, i32* %8
%9 = lshr i32 %0, 16
%10 = and i32 %9, 255
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
store i32 %10, i32* %11
%12 = lshr i32 %0, 24
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
store i32 %12, i32* %13
br label %14
14: ; preds = %1, %14
%15 = phi i32 [ %12, %1 ], [ %21, %14 ]
%16 = phi i64 [ 3, %1 ], [ %19, %14 ]
%17 = trunc i32 %15 to i8
%18 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %17)
%19 = add nuw i64 %16, 1
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %19
%21 = load i32, i32* %20
br label %14
}