#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*/ Com_sprintf(char *, int, char *, int, int, int, int);
void CL_DemoFilename(int number, char *fileName) {
  int a, b, c, d;
  if (number < 0 || number > 9999)
    number = 9999;
  a = number / 1000;
  number -= a * 1000;
  b = number / 100;
  number -= b * 100;
  c = number / 10;
  number -= c * 10;
  d = number;
  Com_sprintf(fileName, 256, "demo%i%i%i%i", a, b, c, d);
}


x86 assembly (clang, -O0):
<CL_DemoFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     1136 <CL_DemoFilename+0x26>
cmpl   $0x270f,-0x4(%rbp)
jle    113d <CL_DemoFilename+0x2d>
movl   $0x270f,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
imul   $0x3e8,-0x14(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
imul   $0x64,-0x18(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
imul   $0xa,-0x1c(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    -0x20(%rbp),%eax
mov    $0x100,%esi
lea    0xe4e(%rip),%rdx
mov    %eax,(%rsp)
call   1030 <Com_sprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CL_DemoFilename>:
push   %rax
cmp    $0x270f,%edi
mov    $0x270f,%eax
cmovb  %edi,%eax
movzwl %ax,%ecx
shr    $0x3,%ecx
imul   $0x20c5,%ecx,%ecx
shr    $0x14,%ecx
imul   $0xfffffc18,%ecx,%edx
add    %eax,%edx
movswl %dx,%eax
imul   $0x147b,%eax,%r8d
mov    %r8d,%eax
shr    $0x1f,%eax
sar    $0x13,%r8d
add    %eax,%r8d
imul   $0xffffff9c,%r8d,%eax
add    %edx,%eax
movswl %ax,%edx
imul   $0x6667,%edx,%r9d
mov    %r9d,%edx
shr    $0x1f,%edx
sar    $0x12,%r9d
add    %edx,%r9d
lea    (%r9,%r9,1),%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%eax
mov    %eax,(%rsp)
lea    0xe83(%rip),%rdx
mov    %rsi,%rdi
mov    $0x100,%esi
call   1030 <Com_sprintf@plt>
pop    %rax
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"demo%i%i%i%i\00"
define void @CL_DemoFilename(i32 %0, i8* %1) {
%3 = icmp ult i32 %0, 9999
%4 = select i1 %3, i32 %0, i32 9999
%5 = trunc i32 %4 to i16
%6 = udiv i16 %5, 1000
%7 = zext i16 %6 to i32
%8 = mul nsw i32 %7, -1000
%9 = add nsw i32 %8, %4
%10 = trunc i32 %9 to i16
%11 = sdiv i16 %10, 100
%12 = sext i16 %11 to i32
%13 = mul nsw i32 %12, -100
%14 = add nsw i32 %13, %9
%15 = trunc i32 %14 to i16
%16 = sdiv i16 %15, 10
%17 = sext i16 %16 to i32
%18 = mul nsw i32 %17, -10
%19 = add nsw i32 %18, %14
%20 = tail call i32 @Com_sprintf(i8* %1, i32 256, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %12, i32 %17, i32 %19)
ret void
}