#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 *);
scalar_t__ m_parse_number(unsigned long long *, char *, int, int);
char *strchr(char *, char);
unsigned long long m_cvt_arbitrary(char *str) {
  unsigned long long ret;
  char *baseptr;
  int base;
  baseptr = strchr(str, '@');
  base = atoi(baseptr + 1);
  if (m_parse_number(&ret, str, baseptr - str, base) != 0) {
    return 0;
  }
  return ret;
}


x86 assembly (clang, -O0):
<m_cvt_arbitrary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x40,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1050 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    -0x24(%rbp),%ecx
lea    -0x18(%rbp),%rdi
call   1040 <m_parse_number@plt>
cmp    $0x0,%rax
je     1192 <m_cvt_arbitrary+0x62>
movq   $0x0,-0x8(%rbp)
jmp    119a <m_cvt_arbitrary+0x6a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m_cvt_arbitrary>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x40,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
lea    0x1(%rax),%rdi
call   1050 <atoi@plt>
sub    %r14d,%ebx
mov    %rsp,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
mov    %eax,%ecx
call   1040 <m_parse_number@plt>
test   %rax,%rax
jne    116a <m_cvt_arbitrary+0x3a>
mov    (%rsp),%rax
jmp    116c <m_cvt_arbitrary+0x3c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @m_cvt_arbitrary(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @strchr(i8* %7, i8 signext 64)
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = call i32 @atoi(i8* %10)
store i32 %11, i32* %6
%12 = load i8*, i8** %3
%13 = load i8*, i8** %5
%14 = load i8*, i8** %3
%15 = ptrtoint i8* %13 to i64
%16 = ptrtoint i8* %14 to i64
%17 = sub i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = load i32, i32* %6
%20 = call i64 @m_parse_number(i64* %4, i8* %12, i32 %18, i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %1
store i64 0, i64* %2
br label %25
23: ; preds = %1
%24 = load i64, i64* %4
store i64 %24, i64* %2
br label %25
25: ; preds = %23, %22
%26 = load i64, i64* %2
ret i64 %26
}

LLVM IR (-O2):
define i64 @m_cvt_arbitrary(i8* %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 64)
%5 = getelementptr inbounds i8, i8* %4, i64 1
%6 = tail call i32 @atoi(i8* %5)
%7 = ptrtoint i8* %4 to i64
%8 = ptrtoint i8* %0 to i64
%9 = sub i64 %7, %8
%10 = trunc i64 %9 to i32
%11 = call i64 @m_parse_number(i64* %2, i8* %0, i32 %10, i32 %6)
%12 = icmp eq i64 %11, 0
%13 = load i64, i64* %2
%14 = select i1 %12, i64 %13, i64 0
ret i64 %14
}