void tempname(tname) char *tname;
{
  static int inc;
  register char *cp, *lp;
  for (cp = tname, lp = "/tmp/shtm"; (*cp = *lp++) != '\0'; cp++)
    ;
  lp = putn(getpid() * 1000 + inc++);
  for (; (*cp = *lp++) != '\0'; cp++)
    ;
}


x86 assembly (clang, -O0):
<tempname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    0xec5(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    -0x10(%rbp),%rcx
mov    %al,(%rcx)
movsbl %al,%eax
cmp    $0x0,%eax
je     1178 <tempname+0x58>
jmp    1167 <tempname+0x47>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    113f <tempname+0x1f>
mov    $0x0,%al
call   1040 <getpid@plt>
imul   $0x3e8,%eax,%edi
mov    0x2ea9(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x2e9e(%rip)
add    %eax,%edi
mov    $0x0,%al
call   1030 <putn@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    -0x10(%rbp),%rcx
mov    %al,(%rcx)
movsbl %al,%eax
cmp    $0x0,%eax
je     11de <tempname+0xbe>
jmp    11cd <tempname+0xad>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11a5 <tempname+0x85>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tempname>:
push   %rbx
mov    %rdi,%rbx
movabs $0x7468732f706d742f,%rax
73 68 74
mov    %rax,(%rdi)
movw   $0x6d,0x8(%rdi)
xor    %eax,%eax
call   1040 <getpid@plt>
imul   $0x3e8,%eax,%edi
mov    0x2eea(%rip),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x2ee1(%rip)
add    %eax,%edi
xor    %eax,%eax
call   1030 <putn@plt>
cltq
mov    (%rax),%cl
mov    %cl,0x9(%rbx)
test   %cl,%cl
je     1181 <tempname+0x61>
xor    %ecx,%ecx
nopl   0x0(%rax)
movzbl 0x1(%rax,%rcx,1),%edx
mov    %dl,0xa(%rbx,%rcx,1)
add    $0x1,%rcx
test   %dl,%dl
jne    1170 <tempname+0x50>
pop    %rbx
ret

LLVM IR (-O0):
@tempname.inc = internal global i32 0
@.str = [10 x i8] c"/tmp/shtm\00"
define void @tempname(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %3
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %4
br label %6
6: ; preds = %14, %1
%7 = load i8*, i8** %4
%8 = getelementptr inbounds i8, i8* %7, i32 1
store i8* %8, i8** %4
%9 = load i8, i8* %7
%10 = load i8*, i8** %3
store i8 %9, i8* %10
%11 = sext i8 %9 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %6
br label %14
14: ; preds = %13
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %3
br label %6
17: ; preds = %6
%18 = call i32 (...) @getpid()
%19 = mul nsw i32 %18, 1000
%20 = load i32, i32* @tempname.inc
%21 = add nsw i32 %20, 1
store i32 %21, i32* @tempname.inc
%22 = add nsw i32 %19, %20
%23 = call i32 (i32, ...) bitcast (i32 (...)* @putn to i32 (i32, ...)*)(i32 %22)
%24 = sext i32 %23 to i64
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %4
br label %26
26: ; preds = %34, %17
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %4
%29 = load i8, i8* %27
%30 = load i8*, i8** %3
store i8 %29, i8* %30
%31 = sext i8 %29 to i32
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %26
br label %34
34: ; preds = %33
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %3
br label %26
37: ; preds = %26
ret void
}

LLVM IR (-O2):
@tempname.inc = internal unnamed_addr global i32 0
define void @tempname(i8* nocapture writeonly %0) {
store i8 47, i8* %0
%2 = getelementptr inbounds i8, i8* %0, i64 1
store i8 116, i8* %2
%3 = getelementptr inbounds i8, i8* %0, i64 2
store i8 109, i8* %3
%4 = getelementptr inbounds i8, i8* %0, i64 3
store i8 112, i8* %4
%5 = getelementptr inbounds i8, i8* %0, i64 4
store i8 47, i8* %5
%6 = getelementptr inbounds i8, i8* %0, i64 5
store i8 115, i8* %6
%7 = getelementptr inbounds i8, i8* %0, i64 6
store i8 104, i8* %7
%8 = getelementptr inbounds i8, i8* %0, i64 7
store i8 116, i8* %8
%9 = getelementptr inbounds i8, i8* %0, i64 8
store i8 109, i8* %9
%10 = getelementptr inbounds i8, i8* %0, i64 9
store i8 0, i8* %10
%11 = tail call i32 (...) @getpid()
%12 = mul nsw i32 %11, 1000
%13 = load i32, i32* @tempname.inc
%14 = add nsw i32 %13, 1
store i32 %14, i32* @tempname.inc
%15 = add nsw i32 %12, %13
%16 = tail call i32 (i32, ...) bitcast (i32 (...)* @putn to i32 (i32, ...)*)(i32 %15)
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i8*
%19 = load i8, i8* %18
store i8 %19, i8* %10
%20 = icmp eq i8 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %1, %21
%22 = phi i8* [ %24, %21 ], [ %18, %1 ]
%23 = phi i8* [ %25, %21 ], [ %10, %1 ]
%24 = getelementptr inbounds i8, i8* %22, i64 1
%25 = getelementptr inbounds i8, i8* %23, i64 1
%26 = load i8, i8* %24
store i8 %26, i8* %25
%27 = icmp eq i8 %26, 0
br i1 %27, label %28, label %21
28: ; preds = %21, %1
ret void
}