#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__ isdigit(unsigned char);
scalar_t__ isspace(char const);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int GetLeafNo(const char **tree_str) {
  char no[3];
  int a = 0;
  while (isspace(*(*tree_str))) {
    *(*tree_str)++;
  }
  while (isdigit((unsigned char)*(*tree_str)) != 0)
    no[a++] = *(*tree_str)++;
  no[a] = '\0';
  (void)sscanf(no, "%d", &a);
  return (a - 1);
}


x86 assembly (clang, -O0):
<GetLeafNo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     116f <GetLeafNo+0x3f>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1143 <GetLeafNo+0x13>
jmp    1174 <GetLeafNo+0x44>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movzbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11b6 <GetLeafNo+0x86>
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,(%rcx)
mov    (%rax),%cl
mov    -0x10(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
cltq
mov    %cl,-0xb(%rbp,%rax,1)
jmp    1174 <GetLeafNo+0x44>
movslq -0x10(%rbp),%rax
movb   $0x0,-0xb(%rbp,%rax,1)
lea    -0xb(%rbp),%rdi
lea    0xe36(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetLeafNo>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movl   $0x0,(%rsp)
mov    (%rdi),%rax
movsbl (%rax),%edi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1040 <isspace@plt>
test   %rax,%rax
je     116a <GetLeafNo+0x3a>
mov    (%r14),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%r14)
movsbl 0x1(%rax),%edi
jmp    1150 <GetLeafNo+0x20>
mov    (%r14),%rax
movzbl (%rax),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11ab <GetLeafNo+0x7b>
xor    %ecx,%ecx
nopl   0x0(%rax)
mov    (%r14),%rax
lea    0x1(%rax),%rdx
mov    %rdx,(%r14)
movzbl (%rax),%edx
lea    0x1(%rcx),%rbx
mov    %ebx,(%rsp)
mov    %dl,0x5(%rsp,%rcx,1)
movzbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
mov    %rbx,%rcx
test   %rax,%rax
jne    1180 <GetLeafNo+0x50>
jmp    11ad <GetLeafNo+0x7d>
xor    %ebx,%ebx
movb   $0x0,0x5(%rsp,%rbx,1)
lea    0xe47(%rip),%rsi
lea    0x5(%rsp),%rdi
mov    %rsp,%rdx
call   1050 <sscanf@plt>
mov    (%rsp),%eax
add    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @GetLeafNo(i8** %0) {
%2 = alloca i8**
%3 = alloca [3 x i8]
%4 = alloca i32
store i8** %0, i8*** %2
store i32 0, i32* %4
br label %5
5: ; preds = %11, %1
%6 = load i8**, i8*** %2
%7 = load i8*, i8** %6
%8 = load i8, i8* %7
%9 = call i64 @isspace(i8 signext %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %5
%12 = load i8**, i8*** %2
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %12
%15 = load i8, i8* %13
br label %5
16: ; preds = %5
br label %17
17: ; preds = %23, %16
%18 = load i8**, i8*** %2
%19 = load i8*, i8** %18
%20 = load i8, i8* %19
%21 = call i64 @isdigit(i8 zeroext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %17
%24 = load i8**, i8*** %2
%25 = load i8*, i8** %24
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %24
%27 = load i8, i8* %25
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 %30
store i8 %27, i8* %31
br label %17
32: ; preds = %17
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 %34
store i8 0, i8* %35
%36 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%37 = call i32 @sscanf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%38 = load i32, i32* %4
%39 = sub nsw i32 %38, 1
ret i32 %39
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @GetLeafNo(i8** nocapture %0) {
%2 = alloca [3 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = load i8*, i8** %0
%7 = load i8, i8* %6
%8 = tail call i64 @isspace(i8 signext %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %15, %1
%11 = load i8*, i8** %0
%12 = load i8, i8* %11
%13 = tail call i64 @isdigit(i8 zeroext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %34, label %21
15: ; preds = %1, %15
%16 = load i8*, i8** %0
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8* %17, i8** %0
%18 = load i8, i8* %17
%19 = tail call i64 @isspace(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %10, label %15
21: ; preds = %10, %21
%22 = phi i32 [ %26, %21 ], [ 0, %10 ]
%23 = load i8*, i8** %0
%24 = getelementptr inbounds i8, i8* %23, i64 1
store i8* %24, i8** %0
%25 = load i8, i8* %23
%26 = add nuw nsw i32 %22, 1
store i32 %26, i32* %3
%27 = zext i32 %22 to i64
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 %27
store i8 %25, i8* %28
%29 = load i8, i8* %24
%30 = tail call i64 @isdigit(i8 zeroext %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %21
32: ; preds = %21
%33 = zext i32 %26 to i64
br label %34
34: ; preds = %32, %10
%35 = phi i64 [ %33, %32 ], [ 0, %10 ]
%36 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 %35
store i8 0, i8* %36
%37 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%38 = load i32, i32* %3
%39 = add nsw i32 %38, -1
ret i32 %39
}