#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 *, long long);
int /*<<< orphan*/ strncpy(char *, char *, int);
void output_4digit_value(char *pos, long long n) {
  char buf[6];
  n = n % 10000;
  sprintf(buf, "%lld", n);
  if (n < 10)
    strncpy(pos + 3, buf, 1);
  else if (n < 100)
    strncpy(pos + 2, buf, 2);
  else if (n < 1000)
    strncpy(pos + 1, buf, 3);
  else
    strncpy(pos, buf, 4);
}


x86 assembly (clang, -O0):
<output_4digit_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x2710,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x10(%rbp)
lea    -0x16(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xeaf(%rip),%rsi
call   1040 <sprintf@plt>
cmpq   $0xa,-0x10(%rbp)
jge    117c <output_4digit_value+0x5c>
mov    -0x8(%rbp),%rdi
add    $0x3,%rdi
lea    -0x16(%rbp),%rsi
mov    $0x1,%edx
call   1030 <strncpy@plt>
jmp    11e7 <output_4digit_value+0xc7>
cmpq   $0x64,-0x10(%rbp)
jge    11a2 <output_4digit_value+0x82>
mov    -0x8(%rbp),%rdi
add    $0x2,%rdi
lea    -0x16(%rbp),%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
jmp    11e2 <output_4digit_value+0xc2>
cmpq   $0x3e8,-0x10(%rbp)
jge    11cb <output_4digit_value+0xab>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    -0x16(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
jmp    11dd <output_4digit_value+0xbd>
mov    -0x8(%rbp),%rdi
lea    -0x16(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
jmp    11e2 <output_4digit_value+0xc2>
jmp    11e7 <output_4digit_value+0xc7>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_4digit_value>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movabs $0x346dc5d63886594b,%rcx
c5 6d 34
mov    %rsi,%rax
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0xb,%rdx
add    %rax,%rdx
imul   $0x2710,%rdx,%rax
sub    %rax,%rbx
lea    0xea7(%rip),%rsi
lea    0x2(%rsp),%rdi
mov    %rbx,%rdx
call   1040 <sprintf@plt>
cmp    $0x9,%rbx
jg     117f <output_4digit_value+0x5f>
add    $0x3,%r14
lea    0x2(%rsp),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
jmp    11c1 <output_4digit_value+0xa1>
cmp    $0x63,%rbx
ja     1198 <output_4digit_value+0x78>
add    $0x2,%r14
lea    0x2(%rsp),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
jmp    11c1 <output_4digit_value+0xa1>
cmp    $0x3e7,%rbx
ja     11b4 <output_4digit_value+0x94>
add    $0x1,%r14
lea    0x2(%rsp),%rsi
mov    %r14,%rdi
mov    $0x3,%edx
jmp    11c1 <output_4digit_value+0xa1>
lea    0x2(%rsp),%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1030 <strncpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%lld\00"
define void @output_4digit_value(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [6 x i8]
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = srem i64 %6, 10000
store i64 %7, i64* %4
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%9 = load i64, i64* %4
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %9)
%11 = load i64, i64* %4
%12 = icmp slt i64 %11, 10
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 3
%16 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%17 = call i32 @strncpy(i8* %15, i8* %16, i32 1)
br label %40
18: ; preds = %2
%19 = load i64, i64* %4
%20 = icmp slt i64 %19, 100
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 2
%24 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%25 = call i32 @strncpy(i8* %23, i8* %24, i32 2)
br label %39
26: ; preds = %18
%27 = load i64, i64* %4
%28 = icmp slt i64 %27, 1000
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%33 = call i32 @strncpy(i8* %31, i8* %32, i32 3)
br label %38
34: ; preds = %26
%35 = load i8*, i8** %3
%36 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%37 = call i32 @strncpy(i8* %35, i8* %36, i32 4)
br label %38
38: ; preds = %34, %29
br label %39
39: ; preds = %38, %21
br label %40
40: ; preds = %39, %13
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%lld\00"
define void @output_4digit_value(i8* %0, i64 %1) {
%3 = alloca [6 x i8]
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%5 = srem i64 %1, 10000
%6 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %5)
%7 = icmp slt i64 %5, 10
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = getelementptr inbounds i8, i8* %0, i64 3
%10 = call i32 @strncpy(i8* %9, i8* %4, i32 1)
br label %23
11: ; preds = %2
%12 = icmp ult i64 %5, 100
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = getelementptr inbounds i8, i8* %0, i64 2
%15 = call i32 @strncpy(i8* %14, i8* %4, i32 2)
br label %23
16: ; preds = %11
%17 = icmp ult i64 %5, 1000
br i1 %17, label %18, label %21
18: ; preds = %16
%19 = getelementptr inbounds i8, i8* %0, i64 1
%20 = call i32 @strncpy(i8* %19, i8* %4, i32 3)
br label %23
21: ; preds = %16
%22 = call i32 @strncpy(i8* %0, i8* %4, i32 4)
br label %23
23: ; preds = %13, %21, %18, %8
ret void
}