#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*/ putchar(char);
int putnumber(int num) {
  char *digits;
  int counter = 0;
  if (num < 0) {
    putchar('-');
    num = -num;
  }
  digits = (char *)(&num);
  digits -= 4;
  while (*digits++ == '0' && counter < 6) {
    counter += 1;
  }
  if (counter >= 5) {
    putchar('0');
  } else {
    digits -= 1;
    while ((5 - counter) > 0) {
      putchar(*digits++);
      counter++;
    }
  }
}


x86 assembly (clang, -O0):
<putnumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    113e <putnumber+0x2e>
mov    $0x2d,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x15(%rbp)
jne    117c <putnumber+0x6c>
cmpl   $0x6,-0x14(%rbp)
setl   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    118c <putnumber+0x7c>
jmp    119a <putnumber+0x8a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1152 <putnumber+0x42>
cmpl   $0x5,-0x14(%rbp)
jl     11b3 <putnumber+0xa3>
mov    $0x30,%edi
call   1030 <putchar@plt>
jmp    11fa <putnumber+0xea>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    $0x5,%eax
sub    -0x14(%rbp),%eax
cmp    $0x0,%eax
jle    11f5 <putnumber+0xe5>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11bf <putnumber+0xaf>
jmp    11fa <putnumber+0xea>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putnumber>:
push   %rax
mov    $0x2d,%edi
call   1030 <putchar@plt>

LLVM IR (-O0):
define i32 @putnumber(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %5
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = call i32 @putchar(i8 signext 45)
%10 = load i32, i32* %3
%11 = sub nsw i32 0, %10
store i32 %11, i32* %3
br label %12
12: ; preds = %8, %1
%13 = bitcast i32* %3 to i8*
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 -4
store i8* %15, i8** %4
br label %16
16: ; preds = %27, %12
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %4
%19 = load i8, i8* %17
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 48
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i32, i32* %5
%24 = icmp slt i32 %23, 6
br label %25
25: ; preds = %22, %16
%26 = phi i1 [ false, %16 ], [ %24, %22 ]
br i1 %26, label %27, label %30
27: ; preds = %25
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %16
30: ; preds = %25
%31 = load i32, i32* %5
%32 = icmp sge i32 %31, 5
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @putchar(i8 signext 48)
br label %50
35: ; preds = %30
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i64 -1
store i8* %37, i8** %4
br label %38
38: ; preds = %42, %35
%39 = load i32, i32* %5
%40 = sub nsw i32 5, %39
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %38
%43 = load i8*, i8** %4
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %4
%45 = load i8, i8* %43
%46 = call i32 @putchar(i8 signext %45)
%47 = load i32, i32* %5
%48 = add nsw i32 %47, 1
store i32 %48, i32* %5
br label %38
49: ; preds = %38
br label %50
50: ; preds = %49, %33
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
define i32 @putnumber(i32 %0) {
%2 = icmp slt i32 %0, 0
%3 = tail call i32 @putchar(i8 signext 45)
unreachable
}