#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 atoi(char *);
int strspn(char *, char *);
int get_num(char *str) {
  int n, num;
  char *tmp = str;
  if ((n = strspn(tmp, "0")) != 0 && tmp[n] != '\0')
    num = atoi(&tmp[n]);
  else
    num = atoi(tmp);
  return num;
}


x86 assembly (clang, -O0):
<get_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xec1(%rip),%rsi
call   1030 <strspn@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     117d <get_num+0x5d>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     117d <get_num+0x5d>
mov    -0x18(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
call   1040 <atoi@plt>
mov    %eax,-0x10(%rbp)
jmp    1189 <get_num+0x69>
mov    -0x18(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_num>:
push   %rbx
mov    %rdi,%rbx
lea    0xed5(%rip),%rsi
call   1030 <strspn@plt>
test   %eax,%eax
je     113f <get_num+0x1f>
cltq
cmpb   $0x0,(%rbx,%rax,1)
je     113f <get_num+0x1f>
add    %rax,%rbx
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <atoi@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
define i32 @get_num(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
store i8* %6, i8** %5
%7 = load i8*, i8** %5
%8 = call i32 @strspn(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %8, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %24
10: ; preds = %1
%11 = load i8*, i8** %5
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %10
%19 = load i8*, i8** %5
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %4
br label %27
24: ; preds = %10, %1
%25 = load i8*, i8** %5
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %4
br label %27
27: ; preds = %24, %18
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
define i32 @get_num(i8* nocapture %0) {
%2 = tail call i32 @strspn(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32 %2, 0
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = sext i32 %2 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = tail call i32 @atoi(i8* %6)
br label %13
11: ; preds = %4, %1
%12 = tail call i32 @atoi(i8* %0)
br label %13
13: ; preds = %11, %9
%14 = phi i32 [ %10, %9 ], [ %12, %11 ]
ret i32 %14
}