#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*/ lcd_putstr(char *);
void lcd_disp_3(unsigned int x) {
  char s[4];
  unsigned int y;
  if (x < 1000) {
    y = x / 100;
    s[0] = (char)(y + 0x30);
    x -= (y * 100);
    y = x / 10;
    s[1] = (char)(y + 0x30);
    x -= (y * 10);
    s[2] = (char)(x + 0x30);
    s[3] = '\0';
    if (s[0] == '0') {
      s[0] = ' ';
      if (s[1] == '0') {
        s[1] = ' ';
      }
    }
    lcd_putstr(s);
  } else {
    lcd_putstr("XXX");
  }
}


x86 assembly (clang, -O0):
<lcd_disp_3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x3e8,-0x4(%rbp)
jae    11b2 <lcd_disp_3+0xa2>
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x8(%rbp)
imul   $0x64,-0xc(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x7(%rbp)
imul   $0xa,-0xc(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x6(%rbp)
movb   $0x0,-0x5(%rbp)
movsbl -0x8(%rbp),%eax
cmp    $0x30,%eax
jne    11a4 <lcd_disp_3+0x94>
movb   $0x20,-0x8(%rbp)
movsbl -0x7(%rbp),%eax
cmp    $0x30,%eax
jne    119f <lcd_disp_3+0x8f>
movb   $0x20,-0x7(%rbp)
jmp    11a4 <lcd_disp_3+0x94>
lea    -0x8(%rbp),%rdi
call   1030 <lcd_putstr@plt>
jmp    11be <lcd_disp_3+0xae>
lea    0xe47(%rip),%rdi
call   1030 <lcd_putstr@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lcd_disp_3>:
cmp    $0x3e7,%edi
ja     117b <lcd_disp_3+0x6b>
push   %rax
movzwl %di,%eax
shr    $0x2,%eax
imul   $0x147b,%eax,%eax
shr    $0x11,%eax
lea    0x30(%rax),%ecx
mov    %cl,0x4(%rsp)
imul   $0xffffff9c,%eax,%edx
add    %edi,%edx
mov    $0xcccccccd,%ecx
imul   %rdx,%rcx
shr    $0x23,%rcx
lea    0x30(%rcx),%esi
mov    %sil,0x5(%rsp)
lea    (%rcx,%rcx,1),%esi
lea    (%rsi,%rsi,4),%esi
sub    %esi,%edx
add    $0x30,%dl
mov    %dl,0x6(%rsp)
movb   $0x0,0x7(%rsp)
test   %al,%al
jne    116f <lcd_disp_3+0x5f>
movb   $0x20,0x4(%rsp)
test   %cl,%cl
jne    116f <lcd_disp_3+0x5f>
movb   $0x20,0x5(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <lcd_putstr@plt>
pop    %rax
ret
lea    0xe7e(%rip),%rdi
jmp    1030 <lcd_putstr@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"XXX\00"
define void @lcd_disp_3(i32 %0) {
%2 = alloca i32
%3 = alloca [4 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = icmp ult i32 %5, 1000
br i1 %6, label %7, label %49
7: ; preds = %1
%8 = load i32, i32* %2
%9 = udiv i32 %8, 100
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = add i32 %10, 48
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
store i8 %12, i8* %13
%14 = load i32, i32* %4
%15 = mul i32 %14, 100
%16 = load i32, i32* %2
%17 = sub i32 %16, %15
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = udiv i32 %18, 10
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = add i32 %20, 48
%22 = trunc i32 %21 to i8
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
store i8 %22, i8* %23
%24 = load i32, i32* %4
%25 = mul i32 %24, 10
%26 = load i32, i32* %2
%27 = sub i32 %26, %25
store i32 %27, i32* %2
%28 = load i32, i32* %2
%29 = add i32 %28, 48
%30 = trunc i32 %29 to i8
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
store i8 %30, i8* %31
%32 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
store i8 0, i8* %32
%33 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 48
br i1 %36, label %37, label %46
37: ; preds = %7
%38 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
store i8 32, i8* %38
%39 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 48
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
store i8 32, i8* %44
br label %45
45: ; preds = %43, %37
br label %46
46: ; preds = %45, %7
%47 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%48 = call i32 @lcd_putstr(i8* %47)
br label %51
49: ; preds = %1
%50 = call i32 @lcd_putstr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %51
51: ; preds = %49, %46
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"XXX\00"
define void @lcd_disp_3(i32 %0) {
%2 = alloca [4 x i8]
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%4 = icmp ult i32 %0, 1000
br i1 %4, label %5, label %29
5: ; preds = %1
%6 = trunc i32 %0 to i16
%7 = udiv i16 %6, 100
%8 = zext i16 %7 to i32
%9 = trunc i16 %7 to i8
%10 = add nuw nsw i8 %9, 48
store i8 %10, i8* %3
%11 = mul nsw i32 %8, -100
%12 = add nsw i32 %11, %0
%13 = udiv i32 %12, 10
%14 = trunc i32 %13 to i8
%15 = add i8 %14, 48
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 1
store i8 %15, i8* %16
%17 = mul i32 %13, -10
%18 = add i32 %17, %12
%19 = trunc i32 %18 to i8
%20 = add i8 %19, 48
%21 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 2
store i8 %20, i8* %21
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 3
store i8 0, i8* %22
%23 = icmp eq i8 %9, 0
br i1 %23, label %24, label %27
24: ; preds = %5
store i8 32, i8* %3
%25 = icmp eq i8 %14, 0
br i1 %25, label %26, label %27
26: ; preds = %24
store i8 32, i8* %16
br label %27
27: ; preds = %24, %26, %5
%28 = call i32 @lcd_putstr(i8* %3)
br label %31
29: ; preds = %1
%30 = tail call i32 @lcd_putstr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %29, %27
ret void
}