#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*/ mkdir(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int, ...);
void diskname(char *buf, int n) {
  sprintf(buf, "cache/%.3d", n / 1000);
  mkdir(buf, 0755);
  sprintf(buf, "cache/%.3d/%.3d.dat", n / 1000, n % 1000);
}


x86 assembly (clang, -O0):
<diskname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0xeb9(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x10(%rbp),%edx
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diskname>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xed1(%rip),%rax
movslq %esi,%r15
imul   $0x10624dd3,%r15,%rbx
mov    %rbx,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rbx
add    %ecx,%ebx
mov    %rax,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %r14,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
imul   $0x3e8,%ebx,%eax
sub    %eax,%r15d
lea    0xe9c(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
mov    %r15d,%ecx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <sprintf@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"cache/%.3d\00"
@.str.1 = [20 x i8] c"cache/%.3d/%.3d.dat\00"
define void @diskname(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i8*, i8** %3
%6 = load i32, i32* %4
%7 = sdiv i32 %6, 1000
%8 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i8*, i8** %3
%10 = call i32 @mkdir(i8* %9, i32 493)
%11 = load i8*, i8** %3
%12 = load i32, i32* %4
%13 = sdiv i32 %12, 1000
%14 = load i32, i32* %4
%15 = srem i32 %14, 1000
%16 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %15)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"cache/%.3d\00"
@.str.1 = [20 x i8] c"cache/%.3d/%.3d.dat\00"
define void @diskname(i8* nocapture %0, i32 %1) {
%3 = sdiv i32 %1, 1000
%4 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 @mkdir(i8* %0, i32 493)
%6 = srem i32 %1, 1000
%7 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %3, i32 %6)
ret void
}