#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 add_nbr(char *, char *, int, int);
int /*<<< orphan*/ nbr_power(char *, int *);
int my_getnbr_base(char *str, char *base) {
  int nbr;
  int power;
  int base_nbr;
  int test;
  nbr = 0;
  power = 0;
  base_nbr = 0;
  test = 0;
  if (str[0] == '-') {
    test = 1;
    str = str + 1;
  }
  nbr_power(str, &power);
  power = power - 1;
  while (base[base_nbr] != '\0')
    base_nbr = base_nbr + 1;
  nbr = add_nbr(str, base, power, base_nbr);
  if (test == 1)
    nbr = -nbr;
  return (nbr);
}


x86 assembly (clang, -O0):
<my_getnbr_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    116f <my_getnbr_base+0x4f>
movl   $0x1,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <nbr_power@plt>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11a8 <my_getnbr_base+0x88>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1185 <my_getnbr_base+0x65>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1040 <add_nbr@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    11d0 <my_getnbr_base+0xb0>
xor    %eax,%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_getnbr_base>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movl   $0x0,0xc(%rsp)
mov    (%rdi),%bpl
xor    %r14d,%r14d
cmp    $0x2d,%bpl
sete   %r14b
add    %rdi,%r14
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
call   1030 <nbr_power@plt>
mov    0xc(%rsp),%edx
add    $0xffffffff,%edx
mov    %edx,0xc(%rsp)
xor    %ecx,%ecx
xchg   %ax,%ax
cmpb   $0x0,(%rbx,%rcx,1)
lea    0x1(%rcx),%rcx
jne    1160 <my_getnbr_base+0x40>
add    $0xffffffff,%ecx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <add_nbr@plt>
mov    %eax,%ecx
neg    %ecx
cmp    $0x2d,%bpl
cmove  %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @my_getnbr_base(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 45
%7 = zext i1 %6 to i64
%8 = getelementptr i8, i8* %0, i64 %7
%9 = call i32 @nbr_power(i8* %8, i32* %3)
%10 = load i32, i32* %3
%11 = add nsw i32 %10, -1
store i32 %11, i32* %3
br label %12
12: ; preds = %12, %2
%13 = phi i64 [ %17, %12 ], [ 0, %2 ]
%14 = getelementptr inbounds i8, i8* %1, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
%17 = add nuw i64 %13, 1
br i1 %16, label %18, label %12
18: ; preds = %12
%19 = trunc i64 %13 to i32
%20 = call i32 @add_nbr(i8* %8, i8* %1, i32 %11, i32 %19)
%21 = sub nsw i32 0, %20
%22 = select i1 %6, i32 %21, i32 %20
ret i32 %22
}