#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ LOG_DEBUG;
int /*<<< orphan*/ exit(int);
scalar_t__ isdigit(char const);
int /*<<< orphan*/ printf(char *, char const);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char const);
int scan_count(const char *fmt) {
  int count = 0;
  while (*fmt) {
    if (*fmt == '%') {
      if (*(++fmt) == '*')
        continue;
      while (isdigit(*fmt))
        fmt++;
      if (*fmt == 'd' || *fmt == 'i' || *fmt == 'u' || *fmt == 'f' ||
          *fmt == 'o' || *fmt == 'x' || *fmt == 'X' || *fmt == 'c' ||
          *fmt == 's' || *fmt == 'b') {
        count++;
      } else {
        printf("Error: unrecognized pattern type: `%%%c'\n", *fmt);
        syslog(LOG_DEBUG, "Error: unrecognized pattern type: `%%%c'\n", *fmt);
        exit(1);
      }
    }
    fmt++;
  }
  return count;
}


x86 assembly (clang, -O0):
<scan_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     12ba <scan_count+0x17a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    12a9 <scan_count+0x169>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl 0x1(%rax),%eax
cmp    $0x2a,%eax
jne    1191 <scan_count+0x51>
jmp    1153 <scan_count+0x13>
jmp    1196 <scan_count+0x56>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11bd <scan_count+0x7d>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1196 <scan_count+0x56>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x64,%eax
je     125d <scan_count+0x11d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x69,%eax
je     125d <scan_count+0x11d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x75,%eax
je     125d <scan_count+0x11d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x66,%eax
je     125d <scan_count+0x11d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6f,%eax
je     125d <scan_count+0x11d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x78,%eax
je     125d <scan_count+0x11d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x58,%eax
je     125d <scan_count+0x11d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x63,%eax
je     125d <scan_count+0x11d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x73,%eax
je     125d <scan_count+0x11d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x62,%eax
jne    126b <scan_count+0x12b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12a4 <scan_count+0x164>
mov    -0x8(%rbp),%rax
lea    0xd8a(%rip),%rdi
movsbl (%rax),%esi
call   1040 <printf@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
lea    0xd6e(%rip),%rsi
movsbl (%rax),%edx
call   1050 <syslog@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    12a9 <scan_count+0x169>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1153 <scan_count+0x13>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_count>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbp
xor    %r15d,%r15d
movabs $0x128825c01,%r14
mov    0x0(%rbp),%al
add    $0x1,%rbp
xchg   %ax,%ax
mov    %rbp,%rbx
cmp    $0x25,%al
jne    11b0 <scan_count+0x70>
movzbl (%rbx),%ecx
lea    0x1(%rbx),%rbp
mov    $0x2a,%al
cmp    $0x2a,%cl
je     1160 <scan_count+0x20>
movsbl %cl,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11ba <scan_count+0x7a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1190 <scan_count+0x50>
jmp    11c1 <scan_count+0x81>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %al,%al
je     11e4 <scan_count+0xa4>
add    $0xffffffffffffffff,%rbx
jmp    11d8 <scan_count+0x98>
add    $0xffffffffffffffff,%rbp
mov    %rbp,%rbx
mov    (%rbx),%al
lea    -0x58(%rax),%ecx
cmp    $0x20,%cl
ja     11f2 <scan_count+0xb2>
movzbl %cl,%ecx
bt     %rcx,%r14
jae    11f2 <scan_count+0xb2>
add    $0x1,%r15d
add    $0x1,%rbx
mov    %rbx,%rbp
jmp    1157 <scan_count+0x17>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
movsbl %al,%esi
lea    0xe04(%rip),%rbp
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
movsbl (%rbx),%edx
mov    %rbp,%rsi
call   1050 <syslog@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"Error: unrecognized pattern type: `%%%c'\0A\00"
@LOG_DEBUG = global i32 0
define i32 @scan_count(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %4
4: ; preds = %92, %19, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %8, label %95
8: ; preds = %4
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 37
br i1 %12, label %13, label %92
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %2
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 42
br i1 %18, label %19, label %20
19: ; preds = %13
br label %4
20: ; preds = %13
br label %21
21: ; preds = %26, %20
%22 = load i8*, i8** %2
%23 = load i8, i8* %22
%24 = call i64 @isdigit(i8 signext %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %2
br label %21
29: ; preds = %21
%30 = load i8*, i8** %2
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 100
br i1 %33, label %79, label %34
34: ; preds = %29
%35 = load i8*, i8** %2
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 105
br i1 %38, label %79, label %39
39: ; preds = %34
%40 = load i8*, i8** %2
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 117
br i1 %43, label %79, label %44
44: ; preds = %39
%45 = load i8*, i8** %2
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 102
br i1 %48, label %79, label %49
49: ; preds = %44
%50 = load i8*, i8** %2
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 111
br i1 %53, label %79, label %54
54: ; preds = %49
%55 = load i8*, i8** %2
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 120
br i1 %58, label %79, label %59
59: ; preds = %54
%60 = load i8*, i8** %2
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp eq i32 %62, 88
br i1 %63, label %79, label %64
64: ; preds = %59
%65 = load i8*, i8** %2
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = icmp eq i32 %67, 99
br i1 %68, label %79, label %69
69: ; preds = %64
%70 = load i8*, i8** %2
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 115
br i1 %73, label %79, label %74
74: ; preds = %69
%75 = load i8*, i8** %2
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = icmp eq i32 %77, 98
br i1 %78, label %79, label %82
79: ; preds = %74, %69, %64, %59, %54, %49, %44, %39, %34, %29
%80 = load i32, i32* %3
%81 = add nsw i32 %80, 1
store i32 %81, i32* %3
br label %91
82: ; preds = %74
%83 = load i8*, i8** %2
%84 = load i8, i8* %83
%85 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8 signext %84)
%86 = load i32, i32* @LOG_DEBUG
%87 = load i8*, i8** %2
%88 = load i8, i8* %87
%89 = call i32 @syslog(i32 %86, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8 signext %88)
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %79
br label %92
92: ; preds = %91, %8
%93 = load i8*, i8** %2
%94 = getelementptr inbounds i8, i8* %93, i32 1
store i8* %94, i8** %2
br label %4
95: ; preds = %4
%96 = load i32, i32* %3
ret i32 %96
}

LLVM IR (-O2):
@.str = [42 x i8] c"Error: unrecognized pattern type: `%%%c'\0A\00"
@LOG_DEBUG = global i32 0
define i32 @scan_count(i8* nocapture %0) {
br label %2
2: ; preds = %1, %35
%3 = phi i8* [ %38, %35 ], [ %0, %1 ]
%4 = phi i32 [ %37, %35 ], [ 0, %1 ]
%5 = load i8, i8* %3
br label %6
6: ; preds = %2, %9
%7 = phi i8 [ %5, %2 ], [ 42, %9 ]
%8 = phi i8* [ %3, %2 ], [ %10, %9 ]
switch i8 %7, label %35 [
i8 0, label %39
i8 37, label %9
]
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %8, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 42
br i1 %12, label %6, label %13
13: ; preds = %9
%14 = tail call i64 @isdigit(i8 signext %11)
%15 = icmp eq i64 %14, 0
br i1 %15, label %24, label %16
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %8, i64 2
br label %18
18: ; preds = %16, %18
%19 = phi i8* [ %17, %16 ], [ %23, %18 ]
%20 = load i8, i8* %19
%21 = tail call i64 @isdigit(i8 signext %20)
%22 = icmp eq i64 %21, 0
%23 = getelementptr inbounds i8, i8* %19, i64 1
br i1 %22, label %24, label %18
24: ; preds = %18, %13
%25 = phi i8* [ %10, %13 ], [ %19, %18 ]
%26 = load i8, i8* %25
switch i8 %26, label %29 [
i8 100, label %27
i8 105, label %27
i8 117, label %27
i8 102, label %27
i8 111, label %27
i8 120, label %27
i8 88, label %27
i8 99, label %27
i8 115, label %27
i8 98, label %27
]
27: ; preds = %24, %24, %24, %24, %24, %24, %24, %24, %24, %24
%28 = add nsw i32 %4, 1
br label %35
29: ; preds = %24
%30 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8 signext %26)
%31 = load i32, i32* @LOG_DEBUG
%32 = load i8, i8* %25
%33 = tail call i32 @syslog(i32 %31, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8 signext %32)
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %6, %27
%36 = phi i8* [ %25, %27 ], [ %8, %6 ]
%37 = phi i32 [ %28, %27 ], [ %4, %6 ]
%38 = getelementptr inbounds i8, i8* %36, i64 1
br label %2
39: ; preds = %6
ret i32 %4
}