putf(cp) register char *cp;
{
  char *ttyn, *slash;
  char datebuffer[60];
  extern char editedhost[];
  extern char *ttyname(), *rindex();
  while (*cp) {
    if (*cp != '%') {
      putchr(*cp++);
      continue;
    }
    switch (*++cp) {
    case 't':
      ttyn = ttyname(0);
      slash = rindex(ttyn, '/');
      if (slash == (char *)0)
        putstr(ttyn);
      else
        putstr(&slash[1]);
      break;
    case 'h':
      putstr(editedhost);
      break;
    case 'd':
      get_date(datebuffer);
      putstr(datebuffer);
      break;
    case '%':
      putchr('%');
      break;
    }
    cp++;
  }
}


x86 assembly (clang, -O0):
<putf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1287 <putf+0x137>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
je     1197 <putf+0x47>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
mov    $0x0,%al
call   1050 <putchr@plt>
jmp    115c <putf+0xc>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl 0x1(%rax),%eax
mov    %eax,-0x64(%rbp)
sub    $0x25,%eax
je     126a <putf+0x11a>
jmp    11bb <putf+0x6b>
mov    -0x64(%rbp),%eax
sub    $0x64,%eax
je     124f <putf+0xff>
jmp    11cc <putf+0x7c>
mov    -0x64(%rbp),%eax
sub    $0x68,%eax
je     123c <putf+0xec>
jmp    11dd <putf+0x8d>
mov    -0x64(%rbp),%eax
sub    $0x74,%eax
jne    1276 <putf+0x126>
jmp    11ee <putf+0x9e>
xor    %edi,%edi
mov    $0x0,%al
call   1030 <ttyname@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <rindex@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1228 <putf+0xd8>
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1040 <putstr@plt>
jmp    1237 <putf+0xe7>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x0,%al
call   1040 <putstr@plt>
jmp    1276 <putf+0x126>
mov    0x2da5(%rip),%rdi
mov    $0x0,%al
call   1040 <putstr@plt>
jmp    1276 <putf+0x126>
lea    -0x60(%rbp),%rdi
mov    $0x0,%al
call   1070 <get_date@plt>
lea    -0x60(%rbp),%rdi
mov    $0x0,%al
call   1040 <putstr@plt>
jmp    1276 <putf+0x126>
mov    $0x25,%edi
mov    $0x0,%al
call   1050 <putchr@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    115c <putf+0xc>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putf>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%rbx
mov    %rsp,%r14
mov    0x2e80(%rip),%r15
jmp    1178 <putf+0x28>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <putstr@plt>
add    $0x2,%rbx
movsbl (%rbx),%edi
cmp    $0x25,%edi
je     11a0 <putf+0x50>
test   %dil,%dil
je     1221 <putf+0xd1>
add    $0x1,%rbx
xor    %eax,%eax
call   1050 <putchr@plt>
jmp    1178 <putf+0x28>
cs nopw 0x0(%rax,%rax,1)
movsbl 0x1(%rbx),%eax
cmp    $0x67,%eax
jg     11d0 <putf+0x80>
cmp    $0x25,%eax
je     1204 <putf+0xb4>
cmp    $0x64,%eax
jne    1210 <putf+0xc0>
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <get_date@plt>
mov    %r14,%rdi
jmp    116d <putf+0x1d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x68,%eax
je     116a <putf+0x1a>
cmp    $0x74,%eax
jne    1210 <putf+0xc0>
xor    %edi,%edi
xor    %eax,%eax
call   1030 <ttyname@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x2f,%esi
call   1060 <rindex@plt>
test   %rax,%rax
je     1219 <putf+0xc9>
add    $0x1,%rax
mov    %rax,%rdi
jmp    116d <putf+0x1d>
mov    $0x25,%edi
xor    %eax,%eax
call   1050 <putchr@plt>
add    $0x2,%rbx
jmp    1178 <putf+0x28>
mov    %r12,%rdi
jmp    116d <putf+0x1d>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@editedhost = external global [0 x i8]
define i32 @putf(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [60 x i8]
store i8* %0, i8** %3
br label %7
7: ; preds = %50, %16, %1
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %53
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 37
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %3
%19 = load i8, i8* %17
%20 = sext i8 %19 to i32
%21 = call i32 (i32, ...) bitcast (i32 (...)* @putchr to i32 (i32, ...)*)(i32 %20)
br label %7
22: ; preds = %11
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %3
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
switch i32 %26, label %50 [
i32 116, label %27
i32 104, label %41
i32 100, label %43
i32 37, label %48
]
27: ; preds = %22
%28 = call i8* (i32, ...) bitcast (i8* (...)* @ttyname to i8* (i32, ...)*)(i32 0)
store i8* %28, i8** %4
%29 = load i8*, i8** %4
%30 = call i8* @rindex(i8* %29, i32 47)
store i8* %30, i8** %5
%31 = load i8*, i8** %5
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = load i8*, i8** %4
%35 = call i32 (i8*, ...) bitcast (i32 (...)* @putstr to i32 (i8*, ...)*)(i8* %34)
br label %40
36: ; preds = %27
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = call i32 (i8*, ...) bitcast (i32 (...)* @putstr to i32 (i8*, ...)*)(i8* %38)
br label %40
40: ; preds = %36, %33
br label %50
41: ; preds = %22
%42 = call i32 (i8*, ...) bitcast (i32 (...)* @putstr to i32 (i8*, ...)*)(i8* getelementptr inbounds ([0 x i8], [0 x i8]* @editedhost, i64 0, i64 0))
br label %50
43: ; preds = %22
%44 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i64 0, i64 0
%45 = call i32 (i8*, ...) bitcast (i32 (...)* @get_date to i32 (i8*, ...)*)(i8* %44)
%46 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i64 0, i64 0
%47 = call i32 (i8*, ...) bitcast (i32 (...)* @putstr to i32 (i8*, ...)*)(i8* %46)
br label %50
48: ; preds = %22
%49 = call i32 (i32, ...) bitcast (i32 (...)* @putchr to i32 (i32, ...)*)(i32 37)
br label %50
50: ; preds = %22, %48, %43, %41, %40
%51 = load i8*, i8** %3
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %3
br label %7
53: ; preds = %7
%54 = load i32, i32* %2
ret i32 %54
}

LLVM IR (-O2):
@editedhost = external global [0 x i8]
define i32 @putf(i8* nocapture %0) {
%2 = alloca [60 x i8]
%3 = getelementptr inbounds [60 x i8], [60 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %11, %1
%5 = phi i8* [ %0, %1 ], [ %12, %11 ]
%6 = load i8, i8* %5
switch i8 %6, label %7 [
i8 0, label %35
i8 37, label %13
]
7: ; preds = %4
%8 = sext i8 %6 to i32
%9 = getelementptr inbounds i8, i8* %5, i64 1
%10 = call i32 (i32, ...) bitcast (i32 (...)* @putchr to i32 (i32, ...)*)(i32 %8)
br label %11
11: ; preds = %7, %33
%12 = phi i8* [ %9, %7 ], [ %34, %33 ]
br label %4
13: ; preds = %4
%14 = getelementptr inbounds i8, i8* %5, i64 1
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
switch i32 %16, label %33 [
i32 116, label %17
i32 104, label %26
i32 100, label %28
i32 37, label %31
]
17: ; preds = %13
%18 = call i8* (i32, ...) bitcast (i8* (...)* @ttyname to i8* (i32, ...)*)(i32 0)
%19 = call i8* @rindex(i8* %18, i32 47)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 (i8*, ...) bitcast (i32 (...)* @putstr to i32 (i8*, ...)*)(i8* %18)
br label %33
23: ; preds = %17
%24 = getelementptr inbounds i8, i8* %19, i64 1
%25 = call i32 (i8*, ...) bitcast (i32 (...)* @putstr to i32 (i8*, ...)*)(i8* %24)
br label %33
26: ; preds = %13
%27 = call i32 (i8*, ...) bitcast (i32 (...)* @putstr to i32 (i8*, ...)*)(i8* getelementptr inbounds ([0 x i8], [0 x i8]* @editedhost, i64 0, i64 0))
br label %33
28: ; preds = %13
%29 = call i32 (i8*, ...) bitcast (i32 (...)* @get_date to i32 (i8*, ...)*)(i8* %3)
%30 = call i32 (i8*, ...) bitcast (i32 (...)* @putstr to i32 (i8*, ...)*)(i8* %3)
br label %33
31: ; preds = %13
%32 = call i32 (i32, ...) bitcast (i32 (...)* @putchr to i32 (i32, ...)*)(i32 37)
br label %33
33: ; preds = %21, %23, %13, %31, %28, %26
%34 = getelementptr inbounds i8, i8* %5, i64 2
br label %11
35: ; preds = %4
ret i32 undef
}