#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 */
char *_copy_string(char const *, char **);
int _scan_pattern(const char *format, char *temp) {
  int n = 0;
  for (;;) {
    format = _copy_string(format, &temp);
    if (format[0] == '\0')
      return 0;
    ++n;
    format = _copy_string(format, &temp);
    if (format[0] == '\0')
      return n;
  }
}


x86 assembly (clang, -O0):
<_scan_pattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <_copy_string@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1154 <_scan_pattern+0x44>
movl   $0x0,-0x4(%rbp)
jmp    118e <_scan_pattern+0x7e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <_copy_string@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1189 <_scan_pattern+0x79>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118e <_scan_pattern+0x7e>
jmp    1127 <_scan_pattern+0x17>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_scan_pattern>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rax
mov    %rsi,(%rsp)
xor    %ebx,%ebx
mov    %rsp,%r14
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <_copy_string@plt>
cmpb   $0x0,(%rax)
je     1145 <_scan_pattern+0x35>
add    $0x1,%ebx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <_copy_string@plt>
cmpb   $0x0,(%rax)
jne    1120 <_scan_pattern+0x10>
jmp    1147 <_scan_pattern+0x37>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @_scan_pattern(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
br label %7
7: ; preds = %28, %2
%8 = load i8*, i8** %4
%9 = call i8* @_copy_string(i8* %8, i8** %5)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %7
store i32 0, i32* %3
br label %29
16: ; preds = %7
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
store i32 %18, i32* %6
%19 = load i8*, i8** %4
%20 = call i8* @_copy_string(i8* %19, i8** %5)
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %16
%27 = load i32, i32* %6
store i32 %27, i32* %3
br label %29
28: ; preds = %16
br label %7
29: ; preds = %26, %15
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @_scan_pattern(i8* %0, i8* %1) {
%3 = alloca i8*
store i8* %1, i8** %3
br label %4
4: ; preds = %10, %2
%5 = phi i8* [ %0, %2 ], [ %12, %10 ]
%6 = phi i32 [ 0, %2 ], [ %11, %10 ]
%7 = call i8* @_copy_string(i8* %5, i8** %3)
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %4
%11 = add nuw nsw i32 %6, 1
%12 = call i8* @_copy_string(i8* %7, i8** %3)
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %4
15: ; preds = %10, %4
%16 = phi i32 [ 0, %4 ], [ %11, %10 ]
ret i32 %16
}