#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 countlength(unsigned long);
int /*<<< orphan*/ myitoaa(unsigned long, char *);
int mystrlen(char *);
int /*<<< orphan*/ write(int, char *, int);
void gethours(unsigned long hours) {
  int len = countlength(hours);
  char top[len + 1];
  myitoaa(hours, top);
  if (hours == 0) {
    write(1, "00", 2);
    return;
  }
  if (len == 1) {
    write(1, "0", 1);
  }
  write(1, top, mystrlen(top));
}


x86 assembly (clang, -O0):
<gethours>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <countlength@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x30(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <myitoaa@plt>
cmpq   $0x0,-0x8(%rbp)
jne    11b7 <gethours+0x77>
mov    $0x1,%edi
lea    0xe5f(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
movl   $0x1,-0x24(%rbp)
jmp    11f4 <gethours+0xb4>
cmpl   $0x1,-0xc(%rbp)
jne    11d4 <gethours+0x94>
mov    $0x1,%edx
lea    0xe34(%rip),%rsi
mov    %edx,%edi
call   1030 <write@plt>
mov    -0x30(%rbp),%rdi
call   1050 <mystrlen@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethours>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
call   1060 <countlength@plt>
mov    %eax,%r14d
lea    0x1(%r14),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <myitoaa@plt>
test   %r15,%r15
je     11aa <gethours+0x6a>
cmp    $0x1,%r14d
jne    1196 <gethours+0x56>
lea    0xe7a(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %rbx,%rdi
call   1050 <mystrlen@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
jmp    11bb <gethours+0x7b>
lea    0xe4f(%rip),%rsi
mov    $0x1,%edi
mov    $0x2,%edx
call   1030 <write@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"00\00"
@.str.1 = [2 x i8] c"0\00"
define void @gethours(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i64 %0, i64* %2
%7 = load i64, i64* %2
%8 = call i32 @countlength(i64 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 1
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %4
%13 = alloca i8, i64 %11
store i64 %11, i64* %5
%14 = load i64, i64* %2
%15 = call i32 @myitoaa(i64 %14, i8* %13)
%16 = load i64, i64* %2
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %1
%19 = call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
store i32 1, i32* %6
br label %28
20: ; preds = %1
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %25
25: ; preds = %23, %20
%26 = call i32 @mystrlen(i8* %13)
%27 = call i32 @write(i32 1, i8* %13, i32 %26)
store i32 0, i32* %6
br label %28
28: ; preds = %25, %18
%29 = load i8*, i8** %4
%30 = load i32, i32* %6
switch i32 %30, label %32 [
i32 0, label %31
i32 1, label %31
]
31: ; preds = %28, %28
ret void
32: ; preds = %28
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"00\00"
@.str.1 = [2 x i8] c"0\00"
define void @gethours(i64 %0) {
%2 = tail call i32 @countlength(i64 %0)
%3 = add nsw i32 %2, 1
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @myitoaa(i64 %0, i8* %5)
%7 = icmp eq i64 %0, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
br label %17
10: ; preds = %1
%11 = icmp eq i32 %2, 1
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %14
14: ; preds = %12, %10
%15 = call i32 @mystrlen(i8* %5)
%16 = call i32 @write(i32 1, i8* %5, i32 %15)
br label %17
17: ; preds = %14, %8
ret void
}