#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 */
scalar_t__ allDigits(char *);
char *strrchr(char *, char);
int strtol(char *, int /*<<< orphan*/ *, int);
int countOccurrences(char *name) {
  char *underscore;
  int number;
  if (allDigits(name)) {
    number = strtol(name, NULL, 10);
  } else {
    underscore = strrchr(name, '_');
    if (underscore == NULL || underscore[1] != 'x') {
      number = 1;
    } else if (allDigits(underscore + 2)) {
      number = strtol(underscore + 2, NULL, 10);
    } else {
      number = 1;
    }
  }
  return number;
}


x86 assembly (clang, -O0):
<countOccurrences>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <allDigits@plt>
cmp    $0x0,%rax
je     1169 <countOccurrences+0x39>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x14(%rbp)
jmp    11e9 <countOccurrences+0xb9>
mov    -0x8(%rbp),%rdi
mov    $0x5f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1197 <countOccurrences+0x67>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
je     11a3 <countOccurrences+0x73>
movl   $0x1,-0x14(%rbp)
jmp    11e4 <countOccurrences+0xb4>
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
call   1050 <allDigits@plt>
cmp    $0x0,%rax
je     11d8 <countOccurrences+0xa8>
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x14(%rbp)
jmp    11df <countOccurrences+0xaf>
movl   $0x1,-0x14(%rbp)
jmp    11e4 <countOccurrences+0xb4>
jmp    11e9 <countOccurrences+0xb9>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countOccurrences>:
push   %rbx
mov    %rdi,%rbx
call   1050 <allDigits@plt>
test   %rax,%rax
je     114e <countOccurrences+0x1e>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
pop    %rbx
jmp    1040 <strtol@plt>
mov    %rbx,%rdi
mov    $0x5f,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     117a <countOccurrences+0x4a>
mov    %rax,%rbx
cmpb   $0x78,0x1(%rax)
jne    117a <countOccurrences+0x4a>
add    $0x2,%rbx
mov    %rbx,%rdi
call   1050 <allDigits@plt>
test   %rax,%rax
jne    113e <countOccurrences+0xe>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @countOccurrences(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @allDigits(i8* %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i32 @strtol(i8* %9, i32* null, i32 10)
store i32 %10, i32* %4
br label %35
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = call i8* @strrchr(i8* %12, i8 signext 95)
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = icmp eq i8* %14, null
br i1 %15, label %22, label %16
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 120
br i1 %21, label %22, label %23
22: ; preds = %16, %11
store i32 1, i32* %4
br label %34
23: ; preds = %16
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 2
%26 = call i64 @allDigits(i8* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i64 2
%31 = call i32 @strtol(i8* %30, i32* null, i32 10)
store i32 %31, i32* %4
br label %33
32: ; preds = %23
store i32 1, i32* %4
br label %33
33: ; preds = %32, %28
br label %34
34: ; preds = %33, %22
br label %35
35: ; preds = %34, %8
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
define i32 @countOccurrences(i8* %0) {
%2 = tail call i64 @allDigits(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @strtol(i8* nocapture %0, i32* null, i32 10)
br label %19
6: ; preds = %1
%7 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 95)
%8 = icmp eq i8* %7, null
br i1 %8, label %19, label %9
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 120
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %7, i64 2
%15 = tail call i64 @allDigits(i8* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = tail call i32 @strtol(i8* nocapture %14, i32* null, i32 10)
br label %19
19: ; preds = %13, %6, %9, %17, %4
%20 = phi i32 [ %5, %4 ], [ %18, %17 ], [ 1, %9 ], [ 1, %6 ], [ 1, %13 ]
ret i32 %20
}