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


x86 assembly (clang, -O0):
<chrItoc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c3 <chrItoc+0x93>
cmpq   $0x0,-0x18(%rbp)
jbe    11c3 <chrItoc+0x93>
lea    -0x40(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe95(%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    119d <chrItoc+0x6d>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11be <chrItoc+0x8e>
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    11c3 <chrItoc+0x93>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chrItoc>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
test   %rsi,%rsi
je     1189 <chrItoc+0x59>
mov    %rdx,%rbx
test   %rdx,%rdx
je     1189 <chrItoc+0x59>
mov    %rcx,%r14
mov    %rsi,%r15
mov    %edi,%edx
lea    0xeab(%rip),%rsi
mov    %rsp,%rdi
call   1050 <sprintf@plt>
mov    %rax,(%r14)
cmp    %rbx,%rax
jae    1172 <chrItoc+0x42>
mov    %rsp,%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
jmp    1189 <chrItoc+0x59>
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 = [4 x i8] c"%-d\00"
define void @chrItoc(i32 %0, i8* %1, i64 %2, i64* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64*
%9 = alloca [20 x i8]
store i32 %0, i32* %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 i32, i32* %5
%18 = call i64 @sprintf(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %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 = [4 x i8] c"%-d\00"
define void @chrItoc(i32 %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 ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %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
}