#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 *, ...);
void R_ScreenshotFilename(int lastNumber, char *fileName) {
  int a, b, c, d;
  if (lastNumber < 0 || lastNumber > 9999) {
    Com_sprintf(fileName, 256, "screenshots/shot9999.tga");
    return;
  }
  a = lastNumber / 1000;
  lastNumber -= a * 1000;
  b = lastNumber / 100;
  lastNumber -= b * 100;
  c = lastNumber / 10;
  lastNumber -= c * 10;
  d = lastNumber;
  Com_sprintf(fileName, 256, "screenshots/shot%i%i%i%i.tga", a, b, c, d);
}


x86 assembly (clang, -O0):
<R_ScreenshotFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     1136 <R_ScreenshotFilename+0x26>
cmpl   $0x270f,-0x4(%rbp)
jle    1152 <R_ScreenshotFilename+0x42>
mov    -0x10(%rbp),%rdi
mov    $0x100,%esi
lea    0xeba(%rip),%rdx
mov    $0x0,%al
call   1030 <Com_sprintf@plt>
jmp    11d1 <R_ScreenshotFilename+0xc1>
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    0xe52(%rip),%rdx
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <Com_sprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<R_ScreenshotFilename>:
cmp    $0x2710,%edi
jb     112e <R_ScreenshotFilename+0x1e>
lea    0xee1(%rip),%rdx
mov    %rsi,%rdi
mov    $0x100,%esi
xor    %eax,%eax
jmp    1030 <Com_sprintf@plt>
push   %rax
movzwl %di,%eax
shr    $0x3,%eax
imul   $0x20c5,%eax,%ecx
shr    $0x14,%ecx
imul   $0xfffffc18,%ecx,%eax
add    %edi,%eax
movswl %ax,%edx
imul   $0x147b,%edx,%r8d
mov    %r8d,%edx
shr    $0x1f,%edx
sar    $0x13,%r8d
add    %edx,%r8d
imul   $0xffffff9c,%r8d,%edx
add    %eax,%edx
movswl %dx,%eax
imul   $0x6667,%eax,%r9d
mov    %r9d,%eax
shr    $0x1f,%eax
sar    $0x12,%r9d
add    %eax,%r9d
lea    (%r9,%r9,1),%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
mov    %edx,(%rsp)
lea    0xe8c(%rip),%rdx
mov    %rsi,%rdi
mov    $0x100,%esi
xor    %eax,%eax
call   1030 <Com_sprintf@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [25 x i8] c"screenshots/shot9999.tga\00"
@.str.1 = [29 x i8] c"screenshots/shot%i%i%i%i.tga\00"
define void @R_ScreenshotFilename(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 %17
14: ; preds = %11, %2
%15 = load i8*, i8** %4
%16 = call i32 (i8*, i32, i8*, ...) @Com_sprintf(i8* %15, i32 256, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %43
17: ; preds = %11
%18 = load i32, i32* %3
%19 = sdiv i32 %18, 1000
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = mul nsw i32 %20, 1000
%22 = load i32, i32* %3
%23 = sub nsw i32 %22, %21
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = sdiv i32 %24, 100
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = mul nsw i32 %26, 100
%28 = load i32, i32* %3
%29 = sub nsw i32 %28, %27
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = sdiv i32 %30, 10
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = mul nsw i32 %32, 10
%34 = load i32, i32* %3
%35 = sub nsw i32 %34, %33
store i32 %35, i32* %3
%36 = load i32, i32* %3
store i32 %36, i32* %8
%37 = load i8*, i8** %4
%38 = load i32, i32* %5
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = load i32, i32* %8
%42 = call i32 (i8*, i32, i8*, ...) @Com_sprintf(i8* %37, i32 256, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %39, i32 %40, i32 %41)
br label %43
43: ; preds = %17, %14
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"screenshots/shot9999.tga\00"
@.str.1 = [29 x i8] c"screenshots/shot%i%i%i%i.tga\00"
define void @R_ScreenshotFilename(i32 %0, i8* %1) {
%3 = icmp ugt i32 %0, 9999
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (i8*, i32, i8*, ...) @Com_sprintf(i8* %1, i32 256, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %23
6: ; preds = %2
%7 = trunc i32 %0 to i16
%8 = udiv i16 %7, 1000
%9 = zext i16 %8 to i32
%10 = mul nsw i32 %9, -1000
%11 = add nsw i32 %10, %0
%12 = trunc i32 %11 to i16
%13 = sdiv i16 %12, 100
%14 = sext i16 %13 to i32
%15 = mul nsw i32 %14, -100
%16 = add nsw i32 %15, %11
%17 = trunc i32 %16 to i16
%18 = sdiv i16 %17, 10
%19 = sext i16 %18 to i32
%20 = mul nsw i32 %19, -10
%21 = add nsw i32 %20, %16
%22 = tail call i32 (i8*, i32, i8*, ...) @Com_sprintf(i8* %1, i32 256, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %14, i32 %19, i32 %21)
br label %23
23: ; preds = %6, %4
ret void
}