#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 strtol(char const *, char **, int);
int parse_songnum(const char *str, int *ret) {
  int song;
  char *endptr;
  if (!str)
    return 0;
  if (*str == '#')
    str++;
  song = strtol(str, &endptr, 10);
  if (str == endptr || (*endptr != ')' && *endptr != '\0') || song < 0)
    return 0;
  *ret = song;
  return 1;
}


x86 assembly (clang, -O0):
<parse_songnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1137 <parse_songnum+0x27>
movl   $0x0,-0x4(%rbp)
jmp    11bc <parse_songnum+0xac>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1153 <parse_songnum+0x43>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     11a0 <parse_songnum+0x90>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
je     1196 <parse_songnum+0x86>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a0 <parse_songnum+0x90>
cmpl   $0x0,-0x1c(%rbp)
jge    11ac <parse_songnum+0x9c>
movl   $0x0,-0x4(%rbp)
jmp    11bc <parse_songnum+0xac>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_songnum>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %ebp,%ebp
test   %rdi,%rdi
je     1160 <parse_songnum+0x50>
mov    %rsi,%r14
xor    %ebx,%ebx
cmpb   $0x23,(%rdi)
sete   %bl
add    %rdi,%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    0x8(%rsp),%rcx
cmp    %rcx,%rbx
je     1160 <parse_songnum+0x50>
mov    (%rcx),%cl
cmp    $0x29,%cl
je     1154 <parse_songnum+0x44>
test   %cl,%cl
jne    1160 <parse_songnum+0x50>
test   %eax,%eax
js     1160 <parse_songnum+0x50>
mov    %eax,(%r14)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @parse_songnum(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp eq i8* %0, null
br i1 %5, label %24, label %6
6: ; preds = %2
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 35
%9 = zext i1 %8 to i64
%10 = getelementptr i8, i8* %0, i64 %9
%11 = call i32 @strtol(i8* %10, i8** %3, i32 10)
%12 = load i8*, i8** %3
%13 = icmp eq i8* %10, %12
br i1 %13, label %24, label %14
14: ; preds = %6
%15 = load i8, i8* %12
%16 = icmp eq i8 %15, 41
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = icmp ne i8 %15, 0
%19 = icmp slt i32 %11, 0
%20 = select i1 %18, i1 true, i1 %19
br i1 %20, label %24, label %23
21: ; preds = %14
%22 = icmp slt i32 %11, 0
br i1 %22, label %24, label %23
23: ; preds = %17, %21
store i32 %11, i32* %1
br label %24
24: ; preds = %6, %17, %21, %2, %23
%25 = phi i32 [ 1, %23 ], [ 0, %2 ], [ 0, %21 ], [ 0, %17 ], [ 0, %6 ]
ret i32 %25
}