char *scan_printf_spec(spec)
register char *spec;
{
  register unsigned char c;
  while ((c = *spec++) == '-')
    continue;
  while (ISDIGIT(c))
    c = *spec++;
  if (c == '.')
    while (ISDIGIT(c = *spec++))
      continue;
  switch (c) {
  case 'c':
  case 'd':
  case 'o':
  case 'x':
  case 'X':
    return spec;
  default:
    return 0;
  }
}


x86 assembly (clang, -O0):
<scan_printf_spec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movzbl %al,%eax
cmp    $0x2d,%eax
jne    1141 <scan_printf_spec+0x31>
jmp    111c <scan_printf_spec+0xc>
jmp    1146 <scan_printf_spec+0x36>
movzbl -0x11(%rbp),%edi
mov    $0x0,%al
call   1030 <ISDIGIT@plt>
cmp    $0x0,%eax
je     1173 <scan_printf_spec+0x63>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
jmp    1146 <scan_printf_spec+0x36>
movzbl -0x11(%rbp),%eax
cmp    $0x2e,%eax
jne    11b6 <scan_printf_spec+0xa6>
jmp    1185 <scan_printf_spec+0x75>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movzbl %al,%edi
mov    $0x0,%al
call   1030 <ISDIGIT@plt>
cmp    $0x0,%eax
je     11b1 <scan_printf_spec+0xa1>
jmp    1185 <scan_printf_spec+0x75>
jmp    11b6 <scan_printf_spec+0xa6>
movzbl -0x11(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x58,%eax
je     1201 <scan_printf_spec+0xf1>
jmp    11cb <scan_printf_spec+0xbb>
mov    -0x18(%rbp),%eax
add    $0xffffff9d,%eax
sub    $0x2,%eax
jb     1201 <scan_printf_spec+0xf1>
jmp    11df <scan_printf_spec+0xcf>
mov    -0x18(%rbp),%eax
sub    $0x6f,%eax
je     1201 <scan_printf_spec+0xf1>
jmp    11f0 <scan_printf_spec+0xe0>
mov    -0x18(%rbp),%eax
sub    $0x78,%eax
jne    120e <scan_printf_spec+0xfe>
jmp    1201 <scan_printf_spec+0xf1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1216 <scan_printf_spec+0x106>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_printf_spec>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
movzbl (%rbx),%ebp
add    $0x1,%rbx
cmp    $0x2d,%ebp
je     1120 <scan_printf_spec+0x10>
mov    %ebp,%edi
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <ISDIGIT@plt>
test   %eax,%eax
je     1148 <scan_printf_spec+0x38>
movzbl (%rbx),%ebp
add    $0x1,%rbx
movzbl %bpl,%edi
jmp    1130 <scan_printf_spec+0x20>
cmp    $0x2e,%bpl
jne    1166 <scan_printf_spec+0x56>
xchg   %ax,%ax
movzbl (%rbx),%ebp
add    $0x1,%rbx
movzbl %bpl,%edi
xor    %eax,%eax
call   1030 <ISDIGIT@plt>
test   %eax,%eax
jne    1150 <scan_printf_spec+0x40>
add    $0xa8,%bpl
cmp    $0x20,%bpl
ja     118e <scan_printf_spec+0x7e>
movzbl %bpl,%eax
movabs $0x100801801,%rcx
bt     %rax,%rcx
jae    118e <scan_printf_spec+0x7e>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %ebx,%ebx
jmp    1184 <scan_printf_spec+0x74>

LLVM IR (-O0):
define i8* @scan_printf_spec(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8
store i8* %0, i8** %3
br label %5
5: ; preds = %11, %1
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i32 1
store i8* %7, i8** %3
%8 = load i8, i8* %6
store i8 %8, i8* %4
%9 = zext i8 %8 to i32
%10 = icmp eq i32 %9, 45
br i1 %10, label %11, label %12
11: ; preds = %5
br label %5
12: ; preds = %5
br label %13
13: ; preds = %18, %12
%14 = load i8, i8* %4
%15 = zext i8 %14 to i32
%16 = call i32 (i32, ...) bitcast (i32 (...)* @ISDIGIT to i32 (i32, ...)*)(i32 %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
%21 = load i8, i8* %19
store i8 %21, i8* %4
br label %13
22: ; preds = %13
%23 = load i8, i8* %4
%24 = zext i8 %23 to i32
%25 = icmp eq i32 %24, 46
br i1 %25, label %26, label %36
26: ; preds = %22
br label %27
27: ; preds = %34, %26
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %3
%30 = load i8, i8* %28
store i8 %30, i8* %4
%31 = zext i8 %30 to i32
%32 = call i32 (i32, ...) bitcast (i32 (...)* @ISDIGIT to i32 (i32, ...)*)(i32 %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %27
br label %27
35: ; preds = %27
br label %36
36: ; preds = %35, %22
%37 = load i8, i8* %4
%38 = zext i8 %37 to i32
switch i32 %38, label %41 [
i32 99, label %39
i32 100, label %39
i32 111, label %39
i32 120, label %39
i32 88, label %39
]
39: ; preds = %36, %36, %36, %36, %36
%40 = load i8*, i8** %3
store i8* %40, i8** %2
br label %42
41: ; preds = %36
store i8* null, i8** %2
br label %42
42: ; preds = %41, %39
%43 = load i8*, i8** %2
ret i8* %43
}

LLVM IR (-O2):
define i8* @scan_printf_spec(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %4, %2 ]
%4 = getelementptr inbounds i8, i8* %3, i64 1
%5 = load i8, i8* %3
%6 = icmp eq i8 %5, 45
br i1 %6, label %2, label %7
7: ; preds = %2
%8 = zext i8 %5 to i32
%9 = tail call i32 (i32, ...) bitcast (i32 (...)* @ISDIGIT to i32 (i32, ...)*)(i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %7, %11
%12 = phi i8* [ %13, %11 ], [ %4, %7 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %12
%15 = zext i8 %14 to i32
%16 = tail call i32 (i32, ...) bitcast (i32 (...)* @ISDIGIT to i32 (i32, ...)*)(i32 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %11
18: ; preds = %11, %7
%19 = phi i8* [ %4, %7 ], [ %13, %11 ]
%20 = phi i8 [ %5, %7 ], [ %14, %11 ]
%21 = icmp eq i8 %20, 46
br i1 %21, label %22, label %29
22: ; preds = %18, %22
%23 = phi i8* [ %24, %22 ], [ %19, %18 ]
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %23
%26 = zext i8 %25 to i32
%27 = tail call i32 (i32, ...) bitcast (i32 (...)* @ISDIGIT to i32 (i32, ...)*)(i32 %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %22
29: ; preds = %22, %18
%30 = phi i8* [ %19, %18 ], [ %24, %22 ]
%31 = phi i8 [ %20, %18 ], [ %25, %22 ]
switch i8 %31, label %32 [
i8 99, label %33
i8 100, label %33
i8 111, label %33
i8 120, label %33
i8 88, label %33
]
32: ; preds = %29
br label %33
33: ; preds = %29, %29, %29, %29, %29, %32
%34 = phi i8* [ null, %32 ], [ %30, %29 ], [ %30, %29 ], [ %30, %29 ], [ %30, %29 ], [ %30, %29 ]
ret i8* %34
}