#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 const);
scalar_t__ isxdigit(char const);
char *malloc(unsigned int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void findconst(const char **str, const char **val) {
  const char *p;
  char *tmp;
  int size;
  p = *str;
  if (*p == '0' && *(p + 1) == 'x') {
    p++;
    do {
      p++;
    } while (isxdigit(*p));
  } else {
    do {
      p++;
    } while (isdigit(*p));
  }
  size = p - *str;
  tmp = malloc((unsigned)(size + 1));
  strncpy(tmp, *str, size);
  tmp[size] = 0;
  *val = tmp;
  *str = p;
}


x86 assembly (clang, -O0):
<findconst>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    11af <findconst+0x6f>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
jne    11af <findconst+0x6f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isxdigit@plt>
cmp    $0x0,%rax
jne    1188 <findconst+0x48>
jmp    11db <findconst+0x9b>
jmp    11b4 <findconst+0x74>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
jne    11b4 <findconst+0x74>
jmp    11db <findconst+0x9b>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findconst>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rbp
cmpb   $0x30,0x0(%rbp)
jne    1190 <findconst+0x50>
cmpb   $0x78,0x1(%rbp)
jne    1190 <findconst+0x50>
add    $0x1,%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl 0x1(%rbp),%edi
add    $0x1,%rbp
call   1060 <isxdigit@plt>
test   %rax,%rax
jne    1170 <findconst+0x30>
jmp    11a2 <findconst+0x62>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl 0x1(%rbp),%edi
add    $0x1,%rbp
call   1040 <isdigit@plt>
test   %rax,%rax
jne    1190 <findconst+0x50>
mov    (%r15),%r12
mov    %rbp,%rbx
sub    %r12,%rbx
lea    0x1(%rbx),%edi
call   1050 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movslq %ebx,%rax
movb   $0x0,0x0(%r13,%rax,1)
mov    %r13,(%r14)
mov    %rbp,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @findconst(i8** %0, i8** %1) {
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8** %0, i8*** %3
store i8** %1, i8*** %4
%8 = load i8**, i8*** %3
%9 = load i8*, i8** %8
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 48
br i1 %13, label %14, label %32
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 120
br i1 %19, label %20, label %32
20: ; preds = %14
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %5
br label %23
23: ; preds = %26, %20
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %5
br label %26
26: ; preds = %23
%27 = load i8*, i8** %5
%28 = load i8, i8* %27
%29 = call i64 @isxdigit(i8 signext %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %23, label %31
31: ; preds = %26
br label %42
32: ; preds = %14, %2
br label %33
33: ; preds = %36, %32
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %5
br label %36
36: ; preds = %33
%37 = load i8*, i8** %5
%38 = load i8, i8* %37
%39 = call i64 @isdigit(i8 signext %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %33, label %41
41: ; preds = %36
br label %42
42: ; preds = %41, %31
%43 = load i8*, i8** %5
%44 = load i8**, i8*** %3
%45 = load i8*, i8** %44
%46 = ptrtoint i8* %43 to i64
%47 = ptrtoint i8* %45 to i64
%48 = sub i64 %46, %47
%49 = trunc i64 %48 to i32
store i32 %49, i32* %7
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
%52 = call i8* @malloc(i32 %51)
store i8* %52, i8** %6
%53 = load i8*, i8** %6
%54 = load i8**, i8*** %3
%55 = load i8*, i8** %54
%56 = load i32, i32* %7
%57 = call i32 @strncpy(i8* %53, i8* %55, i32 %56)
%58 = load i8*, i8** %6
%59 = load i32, i32* %7
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
store i8 0, i8* %61
%62 = load i8*, i8** %6
%63 = load i8**, i8*** %4
store i8* %62, i8** %63
%64 = load i8*, i8** %5
%65 = load i8**, i8*** %3
store i8* %64, i8** %65
ret void
}

LLVM IR (-O2):
define void @findconst(i8** nocapture %0, i8** nocapture writeonly %1) {
%3 = load i8*, i8** %0
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 48
br i1 %5, label %7, label %6
6: ; preds = %7, %2
br label %17
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %3, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 120
br i1 %10, label %11, label %6
11: ; preds = %7, %11
%12 = phi i8* [ %13, %11 ], [ %8, %7 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %13
%15 = tail call i64 @isxdigit(i8 signext %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %23, label %11
17: ; preds = %6, %17
%18 = phi i8* [ %19, %17 ], [ %3, %6 ]
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = tail call i64 @isdigit(i8 signext %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %17
23: ; preds = %17, %11
%24 = phi i8* [ %13, %11 ], [ %19, %17 ]
%25 = load i8*, i8** %0
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = trunc i64 %28 to i32
%30 = add nsw i32 %29, 1
%31 = tail call i8* @malloc(i32 %30)
%32 = tail call i32 @strncpy(i8* %31, i8* %25, i32 %29)
%33 = shl i64 %28, 32
%34 = ashr exact i64 %33, 32
%35 = getelementptr inbounds i8, i8* %31, i64 %34
store i8 0, i8* %35
store i8* %31, i8** %1
store i8* %24, i8** %0
ret void
}