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,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xec5(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%al
mov    -0x18(%rbp),%rcx
mov    %al,(%rcx)
movsbl %al,%eax
cmp    $0x0,%eax
je     1178 <tempname+0x58>
jmp    1167 <tempname+0x47>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%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,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%al
mov    -0x18(%rbp),%rcx
mov    %al,(%rcx)
movsbl %al,%eax
cmp    $0x0,%eax
je     11de <tempname+0xbe>
jmp    11cd <tempname+0xad>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11a5 <tempname+0x85>
mov    -0x4(%rbp),%eax
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 i32 @tempname(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
store i8* %6, i8** %4
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %5
br label %7
7: ; preds = %15, %1
%8 = load i8*, i8** %5
%9 = getelementptr inbounds i8, i8* %8, i32 1
store i8* %9, i8** %5
%10 = load i8, i8* %8
%11 = load i8*, i8** %4
store i8 %10, i8* %11
%12 = sext i8 %10 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %7
br label %15
15: ; preds = %14
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %4
br label %7
18: ; preds = %7
%19 = call i32 (...) @getpid()
%20 = mul nsw i32 %19, 1000
%21 = load i32, i32* @tempname.inc
%22 = add nsw i32 %21, 1
store i32 %22, i32* @tempname.inc
%23 = add nsw i32 %20, %21
%24 = call i32 (i32, ...) bitcast (i32 (...)* @putn to i32 (i32, ...)*)(i32 %23)
%25 = sext i32 %24 to i64
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %5
br label %27
27: ; preds = %35, %18
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %5
%30 = load i8, i8* %28
%31 = load i8*, i8** %4
store i8 %30, i8* %31
%32 = sext i8 %30 to i32
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %27
br label %35
35: ; preds = %34
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %4
br label %27
38: ; preds = %27
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
@tempname.inc = internal unnamed_addr global i32 0
define i32 @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 i32 undef
}