#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 /*<<< orphan*/ error(char *);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ strncpy(char *, char *, int);
void findchrconst(char **str, const char **val) {
  char *p;
  int size;
  char *tmp;
  p = *str;
  do {
    p++;
  } while (*p && *p != '\'');
  if (*p == 0) {
    error("unterminated string constant");
  }
  p++;
  size = p - *str;
  if (size != 3) {
    error("empty char string");
  }
  tmp = (void *)malloc((unsigned)(size + 1));
  (void)strncpy(tmp, *str, size);
  tmp[size] = 0;
  *val = tmp;
  *str = p;
}


x86 assembly (clang, -O0):
<findchrconst>:
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
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     117c <findchrconst+0x4c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    114b <findchrconst+0x1b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a3 <findchrconst+0x73>
lea    0xe62(%rip),%rdi
call   1050 <error@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
je     11d6 <findchrconst+0xa6>
lea    0xe4c(%rip),%rdi
call   1050 <error@plt>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1040 <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):
<findchrconst>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
mov    %rdi,%r12
movabs $0xffffffff00000000,%r14
ff ff ff
mov    (%rdi),%r13
mov    %r13,%rax
shl    $0x20,%rax
mov    %r14,%rbp
sub    %rax,%rbp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0x1(%r13,%rbx,1),%eax
add    $0x1,%rbx
add    %r14,%rbp
cmp    $0x27,%al
je     1197 <findchrconst+0x67>
test   %al,%al
jne    1170 <findchrconst+0x40>
lea    0xe74(%rip),%rdi
call   1050 <error@plt>
mov    (%r12),%r15
jmp    119a <findchrconst+0x6a>
mov    %r13,%r15
lea    (%rbx,%r13,1),%rax
add    $0x1,%rax
mov    %rax,0x8(%rsp)
mov    %r15d,%eax
neg    %eax
add    %r13,%rax
lea    (%rbx,%rax,1),%rcx
add    $0x1,%rcx
mov    %rcx,(%rsp)
add    %rbx,%rax
cmp    $0x2,%eax
je     11cf <findchrconst+0x9f>
lea    0xe53(%rip),%rdi
call   1050 <error@plt>
sub    %r15d,%r13d
lea    (%rbx,%r13,1),%edi
add    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,%r13
mov    (%r12),%rsi
mov    %rax,%rdi
mov    (%rsp),%rdx
call   1030 <strncpy@plt>
imul   %r15,%r14
sub    %rbp,%r14
sar    $0x20,%r14
movb   $0x0,0x0(%r13,%r14,1)
mov    0x10(%rsp),%rax
mov    %r13,(%rax)
mov    0x8(%rsp),%rax
mov    %rax,(%r12)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"unterminated string constant\00"
@.str.1 = [18 x i8] c"empty char string\00"
define void @findchrconst(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
br label %10
10: ; preds = %23, %2
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %5
br label %13
13: ; preds = %10
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %13
%19 = load i8*, i8** %5
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 39
br label %23
23: ; preds = %18, %13
%24 = phi i1 [ false, %13 ], [ %22, %18 ]
br i1 %24, label %10, label %25
25: ; preds = %23
%26 = load i8*, i8** %5
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 @error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %30, %25
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %5
%35 = load i8*, i8** %5
%36 = load i8**, i8*** %3
%37 = load i8*, i8** %36
%38 = ptrtoint i8* %35 to i64
%39 = ptrtoint i8* %37 to i64
%40 = sub i64 %38, %39
%41 = trunc i64 %40 to i32
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = icmp ne i32 %42, 3
br i1 %43, label %44, label %46
44: ; preds = %32
%45 = call i32 @error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %46
46: ; preds = %44, %32
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
%49 = call i64 @malloc(i32 %48)
%50 = inttoptr i64 %49 to i8*
store i8* %50, i8** %7
%51 = load i8*, i8** %7
%52 = load i8**, i8*** %3
%53 = load i8*, i8** %52
%54 = load i32, i32* %6
%55 = call i32 @strncpy(i8* %51, i8* %53, i32 %54)
%56 = load i8*, i8** %7
%57 = load i32, i32* %6
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
store i8 0, i8* %59
%60 = load i8*, i8** %7
%61 = load i8**, i8*** %4
store i8* %60, i8** %61
%62 = load i8*, i8** %5
%63 = load i8**, i8*** %3
store i8* %62, i8** %63
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"unterminated string constant\00"
@.str.1 = [18 x i8] c"empty char string\00"
define void @findchrconst(i8** nocapture %0, i8** nocapture writeonly %1) {
%3 = load i8*, i8** %0
br label %4
4: ; preds = %4, %2
%5 = phi i8* [ %3, %2 ], [ %6, %4 ]
%6 = getelementptr inbounds i8, i8* %5, i64 1
%7 = load i8, i8* %6
switch i8 %7, label %4 [
i8 0, label %8
i8 39, label %11
]
8: ; preds = %4
%9 = tail call i32 @error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%10 = load i8*, i8** %0
br label %11
11: ; preds = %4, %8
%12 = phi i8* [ %10, %8 ], [ %3, %4 ]
%13 = getelementptr inbounds i8, i8* %5, i64 2
%14 = ptrtoint i8* %13 to i64
%15 = ptrtoint i8* %12 to i64
%16 = sub i64 %14, %15
%17 = trunc i64 %16 to i32
%18 = icmp eq i32 %17, 3
br i1 %18, label %21, label %19
19: ; preds = %11
%20 = tail call i32 @error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %11
%22 = add nsw i32 %17, 1
%23 = tail call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i8*
%25 = load i8*, i8** %0
%26 = tail call i32 @strncpy(i8* %24, i8* %25, i32 %17)
%27 = shl i64 %16, 32
%28 = ashr exact i64 %27, 32
%29 = getelementptr inbounds i8, i8* %24, i64 %28
store i8 0, i8* %29
store i8* %24, i8** %1
store i8* %13, i8** %0
ret void
}