#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*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
char *time2str(char *timestr, int hour, int min, int sec) {
  char hourstr[3] = "";
  char minstr[3] = "";
  char secstr[3] = "";
  strcpy(timestr, "");
  if (hour < 0 || hour > 24)
    return NULL;
  if (min < 0 || min > 60)
    return NULL;
  if (sec < 0 || sec > 60)
    return NULL;
  if (hour < 10)
    sprintf(hourstr, "0%d", hour);
  else
    sprintf(hourstr, "%d", hour);
  if (min < 10)
    sprintf(minstr, "0%d", min);
  else
    sprintf(minstr, "%d", min);
  if (sec < 10)
    sprintf(secstr, "0%d", sec);
  else
    sprintf(secstr, "%d", sec);
  sprintf(timestr, "%s:%s:%s", hourstr, minstr, secstr);
  return timestr;
}


x86 assembly (clang, -O0):
<time2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x1f(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <memset@plt>
lea    -0x22(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <memset@plt>
lea    -0x25(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1030 <strcpy@plt>
cmpl   $0x0,-0x14(%rbp)
jl     1199 <time2str+0x69>
cmpl   $0x18,-0x14(%rbp)
jle    11a6 <time2str+0x76>
movq   $0x0,-0x8(%rbp)
jmp    12b9 <time2str+0x189>
cmpl   $0x0,-0x18(%rbp)
jl     11ba <time2str+0x8a>
cmpl   $0x3c,-0x18(%rbp)
jle    11c7 <time2str+0x97>
movq   $0x0,-0x8(%rbp)
jmp    12b9 <time2str+0x189>
cmpl   $0x0,-0x1c(%rbp)
jl     11db <time2str+0xab>
cmpl   $0x3c,-0x1c(%rbp)
jle    11e8 <time2str+0xb8>
movq   $0x0,-0x8(%rbp)
jmp    12b9 <time2str+0x189>
cmpl   $0xa,-0x14(%rbp)
jge    120c <time2str+0xdc>
lea    -0x1f(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1221 <time2str+0xf1>
lea    -0x1f(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xde7(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
cmpl   $0xa,-0x18(%rbp)
jge    1245 <time2str+0x115>
lea    -0x22(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xdc7(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    125a <time2str+0x12a>
lea    -0x22(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xdae(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
cmpl   $0xa,-0x1c(%rbp)
jge    127e <time2str+0x14e>
lea    -0x25(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xd8e(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1293 <time2str+0x163>
lea    -0x25(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xd75(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x1f(%rbp),%rdx
lea    -0x22(%rbp),%rcx
lea    -0x25(%rbp),%r8
lea    0xd5a(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time2str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r15d
mov    %edx,%r13d
mov    %esi,%ebp
mov    %rdi,%r14
movb   $0x0,0x12(%rsp)
movw   $0x0,0x10(%rsp)
movb   $0x0,0xe(%rsp)
movw   $0x0,0xc(%rsp)
movb   $0x0,0x16(%rsp)
movw   $0x0,0x14(%rsp)
lea    0xe9f(%rip),%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
cmp    $0x18,%ebp
ja     1202 <time2str+0xe2>
cmp    $0x3c,%r13d
ja     1202 <time2str+0xe2>
cmp    $0x3c,%r15d
ja     1202 <time2str+0xe2>
cmp    $0xa,%ebp
lea    0xe72(%rip),%r12
lea    0xe6c(%rip),%rbx
mov    %rbx,%rsi
cmovb  %r12,%rsi
lea    0x10(%rsp),%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
cmp    $0xa,%r13d
mov    %rbx,%rsi
cmovb  %r12,%rsi
lea    0xc(%rsp),%rdi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
cmp    $0xa,%r15d
cmovb  %r12,%rbx
lea    0x14(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xe1c(%rip),%rsi
mov    %r14,%rdi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbp,%r8
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [4 x i8] c"0%d\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [9 x i8] c"%s:%s:%s\00"
define i8* @time2str(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [3 x i8]
%11 = alloca [3 x i8]
%12 = alloca [3 x i8]
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = bitcast [3 x i8]* %10 to i8*
%14 = bitcast [3 x i8]* %11 to i8*
%15 = bitcast [3 x i8]* %12 to i8*
%16 = load i8*, i8** %6
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %4
%21 = load i32, i32* %7
%22 = icmp sgt i32 %21, 24
br i1 %22, label %23, label %24
23: ; preds = %20, %4
store i8* null, i8** %5
br label %78
24: ; preds = %20
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load i32, i32* %8
%29 = icmp sgt i32 %28, 60
br i1 %29, label %30, label %31
30: ; preds = %27, %24
store i8* null, i8** %5
br label %78
31: ; preds = %27
%32 = load i32, i32* %9
%33 = icmp slt i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = load i32, i32* %9
%36 = icmp sgt i32 %35, 60
br i1 %36, label %37, label %38
37: ; preds = %34, %31
store i8* null, i8** %5
br label %78
38: ; preds = %34
%39 = load i32, i32* %7
%40 = icmp slt i32 %39, 10
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%43 = load i32, i32* %7
%44 = call i32 (i8*, i8*, ...) @sprintf(i8* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %43)
br label %49
45: ; preds = %38
%46 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%47 = load i32, i32* %7
%48 = call i32 (i8*, i8*, ...) @sprintf(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %45, %41
%50 = load i32, i32* %8
%51 = icmp slt i32 %50, 10
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%54 = load i32, i32* %8
%55 = call i32 (i8*, i8*, ...) @sprintf(i8* %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %54)
br label %60
56: ; preds = %49
%57 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%58 = load i32, i32* %8
%59 = call i32 (i8*, i8*, ...) @sprintf(i8* %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %56, %52
%61 = load i32, i32* %9
%62 = icmp slt i32 %61, 10
br i1 %62, label %63, label %67
63: ; preds = %60
%64 = getelementptr inbounds [3 x i8], [3 x i8]* %12, i64 0, i64 0
%65 = load i32, i32* %9
%66 = call i32 (i8*, i8*, ...) @sprintf(i8* %64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %65)
br label %71
67: ; preds = %60
%68 = getelementptr inbounds [3 x i8], [3 x i8]* %12, i64 0, i64 0
%69 = load i32, i32* %9
%70 = call i32 (i8*, i8*, ...) @sprintf(i8* %68, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %69)
br label %71
71: ; preds = %67, %63
%72 = load i8*, i8** %6
%73 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%74 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%75 = getelementptr inbounds [3 x i8], [3 x i8]* %12, i64 0, i64 0
%76 = call i32 (i8*, i8*, ...) @sprintf(i8* %72, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %73, i8* %74, i8* %75)
%77 = load i8*, i8** %6
store i8* %77, i8** %5
br label %78
78: ; preds = %71, %37, %30, %23
%79 = load i8*, i8** %5
ret i8* %79
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [4 x i8] c"0%d\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [9 x i8] c"%s:%s:%s\00"
define i8* @time2str(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [3 x i8]
%6 = alloca [3 x i8]
%7 = alloca [3 x i8]
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%11 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%12 = icmp ugt i32 %1, 24
%13 = icmp ugt i32 %2, 60
%14 = or i1 %12, %13
%15 = icmp ugt i32 %3, 60
%16 = or i1 %14, %15
br i1 %16, label %28, label %17
17: ; preds = %4
%18 = icmp ult i32 %1, 10
%19 = select i1 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%20 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) %19, i32 %1)
%21 = icmp ult i32 %2, 10
%22 = select i1 %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%23 = call i32 (i8*, i8*, ...) @sprintf(i8* %9, i8* dereferenceable(1) %22, i32 %2)
%24 = icmp ult i32 %3, 10
%25 = select i1 %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%26 = call i32 (i8*, i8*, ...) @sprintf(i8* %10, i8* dereferenceable(1) %25, i32 %3)
%27 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %8, i8* %9, i8* %10)
br label %28
28: ; preds = %4, %17
%29 = phi i8* [ %0, %17 ], [ null, %4 ]
ret i8* %29
}