#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*/ chrFill(char, char *, size_t);
size_t sprintf(char *, char *, size_t);
int /*<<< orphan*/ strcpy(char *, char *);
void chrSizetoc(size_t value, char *string, size_t string_length,
                size_t *nchar) {
  char buf[20];
  if (string && string_length > 0) {
    *nchar = sprintf(buf, "%-zu", value);
    if (*nchar < string_length) {
      strcpy(string, buf);
    } else {
      chrFill('*', string, string_length);
      *nchar = string_length - 1;
    }
  }
}


x86 assembly (clang, -O0):
<chrSizetoc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c5 <chrSizetoc+0x95>
cmpq   $0x0,-0x18(%rbp)
jbe    11c5 <chrSizetoc+0x95>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe93(%rip),%rsi
call   1050 <sprintf@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
cmp    -0x18(%rbp),%rax
jae    119f <chrSizetoc+0x6f>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11c0 <chrSizetoc+0x90>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x2a,%edi
call   1040 <chrFill@plt>
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
jmp    11c5 <chrSizetoc+0x95>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chrSizetoc>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
test   %rsi,%rsi
je     118a <chrSizetoc+0x5a>
mov    %rdx,%rbx
test   %rdx,%rdx
je     118a <chrSizetoc+0x5a>
mov    %rcx,%r14
mov    %rsi,%r15
mov    %rdi,%rdx
lea    0xeaa(%rip),%rsi
mov    %rsp,%rdi
call   1050 <sprintf@plt>
mov    %rax,(%r14)
cmp    %rbx,%rax
jae    1173 <chrSizetoc+0x43>
mov    %rsp,%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
jmp    118a <chrSizetoc+0x5a>
mov    $0x2a,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <chrFill@plt>
add    $0xffffffffffffffff,%rbx
mov    %rbx,(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%-zu\00"
define void @chrSizetoc(i64 %0, i8* %1, i64 %2, i64* %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64*
%9 = alloca [20 x i8]
store i64 %0, i64* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i64* %3, i64** %8
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %36
12: ; preds = %4
%13 = load i64, i64* %7
%14 = icmp ugt i64 %13, 0
br i1 %14, label %15, label %36
15: ; preds = %12
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%17 = load i64, i64* %5
%18 = call i64 @sprintf(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %17)
%19 = load i64*, i64** %8
store i64 %18, i64* %19
%20 = load i64*, i64** %8
%21 = load i64, i64* %20
%22 = load i64, i64* %7
%23 = icmp ult i64 %21, %22
br i1 %23, label %24, label %28
24: ; preds = %15
%25 = load i8*, i8** %6
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%27 = call i32 @strcpy(i8* %25, i8* %26)
br label %35
28: ; preds = %15
%29 = load i8*, i8** %6
%30 = load i64, i64* %7
%31 = call i32 @chrFill(i8 signext 42, i8* %29, i64 %30)
%32 = load i64, i64* %7
%33 = sub i64 %32, 1
%34 = load i64*, i64** %8
store i64 %33, i64* %34
br label %35
35: ; preds = %28, %24
br label %36
36: ; preds = %35, %12, %4
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%-zu\00"
define void @chrSizetoc(i64 %0, i8* %1, i64 %2, i64* nocapture writeonly %3) {
%5 = alloca [20 x i8]
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%7 = icmp ne i8* %1, null
%8 = icmp ne i64 %2, 0
%9 = and i1 %7, %8
br i1 %9, label %10, label %18
10: ; preds = %4
%11 = call i64 @sprintf(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %0)
store i64 %11, i64* %3
%12 = icmp ult i64 %11, %2
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @strcpy(i8* %1, i8* %6)
br label %18
15: ; preds = %10
%16 = call i32 @chrFill(i8 signext 42, i8* %1, i64 %2)
%17 = add i64 %2, -1
store i64 %17, i64* %3
br label %18
18: ; preds = %13, %15, %4
ret void
}