#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(char);
char *readargnumber(char *arg, int *numberaddr) {
  int argnumber = 0;
  if (*arg == '^') {
    *numberaddr = 1;
    return ++arg;
  }
  if (*arg == '$') {
    *numberaddr = -1;
    return ++arg;
  }
  if (isdigit(*arg)) {
    do
      argnumber = argnumber * 10 + (*arg++ - '0');
    while (isdigit(*arg));
    *numberaddr = argnumber;
  }
  return arg;
}


x86 assembly (clang, -O0):
<readargnumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5e,%eax
jne    1156 <readargnumber+0x46>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    %rax,-0x8(%rbp)
jmp    11e5 <readargnumber+0xd5>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x24,%eax
jne    1185 <readargnumber+0x75>
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    %rax,-0x8(%rbp)
jmp    11e5 <readargnumber+0xd5>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11dd <readargnumber+0xcd>
jmp    11a0 <readargnumber+0x90>
imul   $0xa,-0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
movsbl (%rcx),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    11a0 <readargnumber+0x90>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readargnumber>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%al
cmp    $0x24,%al
je     1132 <readargnumber+0x22>
cmp    $0x5e,%al
jne    113f <readargnumber+0x2f>
movl   $0x1,(%r14)
add    $0x1,%r15
jmp    1173 <readargnumber+0x63>
movl   $0xffffffff,(%r14)
add    $0x1,%r15
jmp    1173 <readargnumber+0x63>
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1173 <readargnumber+0x63>
xor    %ebx,%ebx
xchg   %ax,%ax
lea    (%rbx,%rbx,4),%eax
movsbl (%r15),%ecx
movsbl 0x1(%r15),%edi
add    $0x1,%r15
lea    (%rcx,%rax,2),%ebx
add    $0xffffffd0,%ebx
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1150 <readargnumber+0x40>
mov    %ebx,(%r14)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @readargnumber(i8* %0, i32* nocapture writeonly %1) {
%3 = load i8, i8* %0
switch i8 %3, label %8 [
i8 94, label %4
i8 36, label %6
]
4: ; preds = %2
store i32 1, i32* %1
%5 = getelementptr inbounds i8, i8* %0, i64 1
br label %24
6: ; preds = %2
store i32 -1, i32* %1
%7 = getelementptr inbounds i8, i8* %0, i64 1
br label %24
8: ; preds = %2
%9 = tail call i64 @isdigit(i8 signext %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %24, label %11
11: ; preds = %8, %11
%12 = phi i8* [ %15, %11 ], [ %0, %8 ]
%13 = phi i32 [ %19, %11 ], [ 0, %8 ]
%14 = mul nsw i32 %13, 10
%15 = getelementptr inbounds i8, i8* %12, i64 1
%16 = load i8, i8* %12
%17 = sext i8 %16 to i32
%18 = add i32 %14, -48
%19 = add i32 %18, %17
%20 = load i8, i8* %15
%21 = tail call i64 @isdigit(i8 signext %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %11
23: ; preds = %11
store i32 %19, i32* %1
br label %24
24: ; preds = %8, %23, %6, %4
%25 = phi i8* [ %5, %4 ], [ %7, %6 ], [ %15, %23 ], [ %0, %8 ]
ret i8* %25
}