mktempname(nm) char nm[];
{
  register i;
  int pid = getpid();
  nm[0] = '/';
  nm[1] = 'c';
  nm[2] = 'e';
  nm[3] = 'm';
  for (i = 9; i > 3; i--) {
    nm[i] = (pid % 10) + '0';
    pid /= 10;
  }
  nm[10] = '\0';
}


x86 assembly (clang, -O0):
<mktempname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x63,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0x65,0x2(%rax)
mov    -0x10(%rbp),%rax
movb   $0x6d,0x3(%rax)
movl   $0x9,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jle    118b <mktempname+0x7b>
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    114c <mktempname+0x3c>
mov    -0x10(%rbp),%rax
movb   $0x0,0xa(%rax)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mktempname>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <getpid@plt>
movl   $0x6d65632f,(%r14)
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
lea    (%rax,%rax,1),%edx
lea    (%rdx,%rdx,4),%r8d
imul   $0x51eb851f,%rcx,%r9
imul   $0x10624dd3,%rcx,%rdi
imul   $0x68db8bad,%rcx,%rdx
imul   $0x14f8b589,%rcx,%rbx
sub    %r8d,%ecx
add    $0x30,%cl
mov    %cl,0x9(%r14)
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
shr    $0x22,%rcx
add    %esi,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
add    $0x30,%al
mov    %al,0x8(%r14)
mov    %r9,%rax
shr    $0x3f,%rax
sar    $0x25,%r9
add    %eax,%r9d
movslq %r9d,%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
shr    $0x22,%rcx
add    %esi,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
add    $0x30,%al
mov    %al,0x7(%r14)
mov    %rdi,%rax
shr    $0x3f,%rax
sar    $0x26,%rdi
add    %eax,%edi
movslq %edi,%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
shr    $0x22,%rcx
add    %esi,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
add    $0x30,%al
mov    %al,0x6(%r14)
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2c,%rdx
add    %eax,%edx
movslq %edx,%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
add    $0x30,%al
mov    %al,0x5(%r14)
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x2d,%rbx
add    %eax,%ebx
movswl %bx,%eax
imul   $0x6667,%eax,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
shr    $0x12,%eax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
add    $0x30,%bl
mov    %bl,0x4(%r14)
movb   $0x0,0xa(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @mktempname(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = call i32 (...) @getpid()
store i32 %6, i32* %5
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 0
store i8 47, i8* %8
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 1
store i8 99, i8* %10
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 2
store i8 101, i8* %12
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 3
store i8 109, i8* %14
store i32 9, i32* %4
br label %15
15: ; preds = %29, %1
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 3
br i1 %17, label %18, label %32
18: ; preds = %15
%19 = load i32, i32* %5
%20 = srem i32 %19, 10
%21 = add nsw i32 %20, 48
%22 = trunc i32 %21 to i8
%23 = load i8*, i8** %3
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 %22, i8* %26
%27 = load i32, i32* %5
%28 = sdiv i32 %27, 10
store i32 %28, i32* %5
br label %29
29: ; preds = %18
%30 = load i32, i32* %4
%31 = add nsw i32 %30, -1
store i32 %31, i32* %4
br label %15
32: ; preds = %15
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 10
store i8 0, i8* %34
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
define i32 @mktempname(i8* nocapture writeonly %0) {
%2 = tail call i32 (...) @getpid()
store i8 47, i8* %0
%3 = getelementptr inbounds i8, i8* %0, i64 1
store i8 99, i8* %3
%4 = getelementptr inbounds i8, i8* %0, i64 2
store i8 101, i8* %4
%5 = getelementptr inbounds i8, i8* %0, i64 3
store i8 109, i8* %5
%6 = srem i32 %2, 10
%7 = trunc i32 %6 to i8
%8 = add nsw i8 %7, 48
%9 = getelementptr inbounds i8, i8* %0, i64 9
store i8 %8, i8* %9
%10 = sdiv i32 %2, 10
%11 = srem i32 %10, 10
%12 = trunc i32 %11 to i8
%13 = add nsw i8 %12, 48
%14 = getelementptr inbounds i8, i8* %0, i64 8
store i8 %13, i8* %14
%15 = sdiv i32 %2, 100
%16 = srem i32 %15, 10
%17 = trunc i32 %16 to i8
%18 = add nsw i8 %17, 48
%19 = getelementptr inbounds i8, i8* %0, i64 7
store i8 %18, i8* %19
%20 = sdiv i32 %2, 1000
%21 = srem i32 %20, 10
%22 = trunc i32 %21 to i8
%23 = add nsw i8 %22, 48
%24 = getelementptr inbounds i8, i8* %0, i64 6
store i8 %23, i8* %24
%25 = sdiv i32 %2, 10000
%26 = srem i32 %25, 10
%27 = trunc i32 %26 to i8
%28 = add nsw i8 %27, 48
%29 = getelementptr inbounds i8, i8* %0, i64 5
store i8 %28, i8* %29
%30 = sdiv i32 %2, 100000
%31 = trunc i32 %30 to i16
%32 = srem i16 %31, 10
%33 = trunc i16 %32 to i8
%34 = add nsw i8 %33, 48
%35 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %34, i8* %35
%36 = getelementptr inbounds i8, i8* %0, i64 10
store i8 0, i8* %36
ret i32 undef
}