#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 my_char_num(char);
scalar_t__ my_num_neg(char *);
int my_getnbr(char *str) {
  int i;
  int res;
  i = 0;
  res = 0;
  while (my_char_num(*(str + i)) == 'R')
    i++;
  while (my_char_num(*(str + i)) != 'R') {
    if (my_num_neg(str) < 0)
      res = ((res * 10) - (my_char_num(*(str + i)) - 48));
    else
      res = ((res * 10) + (my_char_num(*(str + i)) - 48));
    i++;
  }
  return (res);
}


x86 assembly (clang, -O0):
<my_getnbr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <my_char_num@plt>
cmp    $0x52,%eax
jne    1162 <my_getnbr+0x42>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113a <my_getnbr+0x1a>
jmp    1167 <my_getnbr+0x47>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <my_char_num@plt>
cmp    $0x52,%eax
je     11f1 <my_getnbr+0xd1>
mov    -0x8(%rbp),%rdi
call   1030 <my_num_neg@plt>
cmp    $0x0,%rax
jge    11be <my_getnbr+0x9e>
imul   $0xa,-0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <my_char_num@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
sub    $0x30,%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
jmp    11e3 <my_getnbr+0xc3>
imul   $0xa,-0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <my_char_num@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1167 <my_getnbr+0x47>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_getnbr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0xffffffffffffffff,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl 0x1(%r14,%r15,1),%edi
call   1040 <my_char_num@plt>
add    $0x1,%r15
cmp    $0x52,%eax
je     1140 <my_getnbr+0x20>
mov    %r15d,%eax
movsbl (%r14,%rax,1),%edi
call   1040 <my_char_num@plt>
xor    %ebx,%ebx
cmp    $0x52,%eax
je     11bf <my_getnbr+0x9f>
mov    %r15d,%eax
lea    (%r14,%rax,1),%r12
add    $0x1,%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1030 <my_num_neg@plt>
mov    %rax,%r15
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%ebx
movsbl -0x1(%r12),%edi
call   1040 <my_char_num@plt>
mov    %ebx,%ecx
sub    %eax,%ecx
add    $0x30,%ecx
test   %r15,%r15
lea    -0x30(%rax,%rbx,1),%ebx
cmovs  %ecx,%ebx
movsbl (%r12),%edi
call   1040 <my_char_num@plt>
add    $0x1,%r12
cmp    $0x52,%eax
jne    1180 <my_getnbr+0x60>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @my_getnbr(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ %8, %2 ], [ 0, %1 ]
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
%6 = tail call i32 @my_char_num(i8 signext %5)
%7 = icmp eq i32 %6, 82
%8 = add nuw i64 %3, 1
br i1 %7, label %2, label %9
9: ; preds = %2
%10 = and i64 %3, 4294967295
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = tail call i32 @my_char_num(i8 signext %12)
%14 = icmp eq i32 %13, 82
br i1 %14, label %34, label %15
15: ; preds = %9, %15
%16 = phi i64 [ %29, %15 ], [ %10, %9 ]
%17 = phi i8* [ %30, %15 ], [ %11, %9 ]
%18 = phi i32 [ %28, %15 ], [ 0, %9 ]
%19 = tail call i64 @my_num_neg(i8* %0)
%20 = icmp slt i64 %19, 0
%21 = mul nsw i32 %18, 10
%22 = load i8, i8* %17
%23 = tail call i32 @my_char_num(i8 signext %22)
%24 = add i32 %21, 48
%25 = sub i32 %24, %23
%26 = add i32 %21, -48
%27 = add i32 %26, %23
%28 = select i1 %20, i32 %25, i32 %27
%29 = add nuw i64 %16, 1
%30 = getelementptr inbounds i8, i8* %0, i64 %29
%31 = load i8, i8* %30
%32 = tail call i32 @my_char_num(i8 signext %31)
%33 = icmp eq i32 %32, 82
br i1 %33, label %34, label %15
34: ; preds = %15, %9
%35 = phi i32 [ 0, %9 ], [ %28, %15 ]
ret i32 %35
}