#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 *strchr(char const *, char);
unsigned long strtoul(char *, int /*<<< orphan*/ *, int);
unsigned long calculate_num_lines(const char *atatline, char which) {
  char *p = strchr(atatline, which);
  if (!p)
    return 1;
  while (*p && *p != ',' && *p != ' ')
    p++;
  if (!*p || *p == ' ')
    return 1;
  return strtoul(p + 1, NULL, 10);
}


x86 assembly (clang, -O0):
<calculate_num_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    115b <calculate_num_lines+0x3b>
movq   $0x1,-0x8(%rbp)
jmp    11ff <calculate_num_lines+0xdf>
jmp    1160 <calculate_num_lines+0x40>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     119a <calculate_num_lines+0x7a>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2c,%ecx
mov    %al,-0x21(%rbp)
je     119a <calculate_num_lines+0x7a>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11aa <calculate_num_lines+0x8a>
jmp    11bb <calculate_num_lines+0x9b>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1160 <calculate_num_lines+0x40>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d8 <calculate_num_lines+0xb8>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    11e5 <calculate_num_lines+0xc5>
movq   $0x1,-0x8(%rbp)
jmp    11ff <calculate_num_lines+0xdf>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_num_lines>:
push   %rax
call   1030 <strchr@plt>
test   %rax,%rax
je     1156 <calculate_num_lines+0x36>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rax
movzbl -0x1(%rax),%ecx
test   %cl,%cl
je     1156 <calculate_num_lines+0x36>
cmp    $0x20,%cl
je     1156 <calculate_num_lines+0x36>
cmp    $0x2c,%cl
jne    1130 <calculate_num_lines+0x10>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
pop    %rax
jmp    1040 <strtoul@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i64 @calculate_num_lines(i8* %0, i8 signext %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8*
store i8* %0, i8** %4
store i8 %1, i8* %5
%7 = load i8*, i8** %4
%8 = load i8, i8* %5
%9 = call i8* @strchr(i8* %7, i8 signext %8)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
store i64 1, i64* %3
br label %48
13: ; preds = %2
br label %14
14: ; preds = %31, %13
%15 = load i8*, i8** %6
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %29
19: ; preds = %14
%20 = load i8*, i8** %6
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 44
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load i8*, i8** %6
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 32
br label %29
29: ; preds = %24, %19, %14
%30 = phi i1 [ false, %19 ], [ false, %14 ], [ %28, %24 ]
br i1 %30, label %31, label %34
31: ; preds = %29
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %6
br label %14
34: ; preds = %29
%35 = load i8*, i8** %6
%36 = load i8, i8* %35
%37 = icmp ne i8 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = load i8*, i8** %6
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 32
br i1 %42, label %43, label %44
43: ; preds = %38, %34
store i64 1, i64* %3
br label %48
44: ; preds = %38
%45 = load i8*, i8** %6
%46 = getelementptr inbounds i8, i8* %45, i64 1
%47 = call i64 @strtoul(i8* %46, i32* null, i32 10)
store i64 %47, i64* %3
br label %48
48: ; preds = %44, %43, %12
%49 = load i64, i64* %3
ret i64 %49
}

LLVM IR (-O2):
define i64 @calculate_num_lines(i8* %0, i8 signext %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %13, label %5
5: ; preds = %2, %8
%6 = phi i8* [ %9, %8 ], [ %3, %2 ]
%7 = load i8, i8* %6
switch i8 %7, label %8 [
i8 0, label %13
i8 32, label %13
i8 44, label %10
]
8: ; preds = %5
%9 = getelementptr inbounds i8, i8* %6, i64 1
br label %5
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %6, i64 1
%12 = tail call i64 @strtoul(i8* nocapture %11, i32* null, i32 10)
br label %13
13: ; preds = %5, %5, %2, %10
%14 = phi i64 [ %12, %10 ], [ 1, %2 ], [ 1, %5 ], [ 1, %5 ]
ret i64 %14
}