#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(unsigned char);
scalar_t__ isxdigit(unsigned char);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ strncpy(char *, char *, int);
void findconst(char **str, const char **val) {
  char *p;
  int size;
  char *tmp;
  p = *str;
  if (*p == '0' && *(p + 1) == 'x') {
    p++;
    do {
      p++;
    } while (isxdigit((unsigned char)*p));
  } else {
    do {
      p++;
    } while (isdigit((unsigned char)*p));
  }
  size = p - *str;
  tmp = (void *)malloc((unsigned)(size + 1));
  (void)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
movzbl (%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
movzbl (%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,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%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   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rbx
cmpb   $0x30,(%rbx)
jne    1190 <findconst+0x50>
cmpb   $0x78,0x1(%rbx)
jne    1190 <findconst+0x50>
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1060 <isxdigit@plt>
test   %rax,%rax
jne    1170 <findconst+0x30>
jmp    11a2 <findconst+0x62>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1040 <isdigit@plt>
test   %rax,%rax
jne    1190 <findconst+0x50>
mov    %rbx,%r13
sub    (%r15),%r13
lea    0x1(%r13),%edi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    (%r15),%rsi
mov    %rax,%rdi
mov    %r13d,%edx
call   1030 <strncpy@plt>
movslq %r13d,%rax
movb   $0x0,(%r12,%rax,1)
mov    %r12,(%r14)
mov    %rbx,(%r15)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @findconst(i8** %0, i8** %1) {
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
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 zeroext %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 zeroext %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* %6
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
%52 = call i64 @malloc(i32 %51)
%53 = inttoptr i64 %52 to i8*
store i8* %53, i8** %7
%54 = load i8*, i8** %7
%55 = load i8**, i8*** %3
%56 = load i8*, i8** %55
%57 = load i32, i32* %6
%58 = call i32 @strncpy(i8* %54, i8* %56, i32 %57)
%59 = load i8*, i8** %7
%60 = load i32, i32* %6
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
store i8 0, i8* %62
%63 = load i8*, i8** %7
%64 = load i8**, i8*** %4
store i8* %63, i8** %64
%65 = load i8*, i8** %5
%66 = load i8**, i8*** %3
store i8* %65, i8** %66
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 zeroext %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 zeroext %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 i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i8*
%33 = load i8*, i8** %0
%34 = tail call i32 @strncpy(i8* %32, i8* %33, i32 %29)
%35 = shl i64 %28, 32
%36 = ashr exact i64 %35, 32
%37 = getelementptr inbounds i8, i8* %32, i64 %36
store i8 0, i8* %37
store i8* %32, i8** %1
store i8* %24, i8** %0
ret void
}