#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*/ _(char *);
int /*<<< orphan*/ error(int /*<<< orphan*/);
char *malloc(unsigned int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void findchrconst(const char **str, const char **val) {
  const char *p;
  char *tmp;
  int size;
  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 = malloc((unsigned)(size + 1));
  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,-0x25(%rbp)
je     118c <findchrconst+0x4c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    115b <findchrconst+0x1b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11ba <findchrconst+0x7a>
lea    0xe52(%rip),%rdi
call   1050 <_@plt>
mov    %eax,%edi
call   1060 <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,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
je     11f4 <findchrconst+0xb4>
lea    0xe35(%rip),%rdi
call   1050 <_@plt>
mov    %eax,%edi
call   1060 <error@plt>
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1040 <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):
<findchrconst>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,0x20(%rsp)
mov    %rdi,%r12
movabs $0xffffffff00000000,%r14
ff ff ff
mov    (%rdi),%rbx
mov    %rbx,%rax
shl    $0x20,%rax
mov    %r14,%rbp
sub    %rax,%rbp
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x1(%rbx,%r15,1),%eax
add    $0x1,%r15
add    %r14,%rbp
cmp    $0x27,%al
je     11b1 <findchrconst+0x71>
test   %al,%al
jne    1180 <findchrconst+0x40>
lea    0xe64(%rip),%rdi
call   1050 <_@plt>
mov    %eax,%edi
call   1060 <error@plt>
mov    %r12,%rax
mov    (%r12),%r13
jmp    11b7 <findchrconst+0x77>
mov    %r12,%rax
mov    %rbx,%r13
mov    %rax,0x8(%rsp)
lea    (%rbx,%r15,1),%rax
add    $0x1,%rax
mov    %rax,0x18(%rsp)
mov    %r13d,%eax
neg    %eax
add    %rbx,%rax
lea    (%r15,%rax,1),%rcx
add    $0x1,%rcx
mov    %rcx,0x10(%rsp)
add    %r15,%rax
mov    %r13,%r12
cmp    $0x2,%eax
je     1204 <findchrconst+0xc4>
lea    0xe2d(%rip),%rdi
call   1050 <_@plt>
mov    %eax,%edi
call   1060 <error@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%r12
sub    %r13d,%ebx
lea    (%rbx,%r15,1),%edi
add    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    0x10(%rsp),%rdx
call   1030 <strncpy@plt>
imul   %r13,%r14
sub    %rbp,%r14
sar    $0x20,%r14
movb   $0x0,(%rbx,%r14,1)
mov    0x20(%rsp),%rax
mov    %rbx,(%rax)
mov    0x18(%rsp),%rax
mov    0x8(%rsp),%rcx
mov    %rax,(%rcx)
add    $0x28,%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 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
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 %33
30: ; preds = %25
%31 = call i32 @_(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @error(i32 %31)
br label %33
33: ; preds = %30, %25
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %5
%36 = load i8*, i8** %5
%37 = load i8**, i8*** %3
%38 = load i8*, i8** %37
%39 = ptrtoint i8* %36 to i64
%40 = ptrtoint i8* %38 to i64
%41 = sub i64 %39, %40
%42 = trunc i64 %41 to i32
store i32 %42, i32* %7
%43 = load i32, i32* %7
%44 = icmp ne i32 %43, 3
br i1 %44, label %45, label %48
45: ; preds = %33
%46 = call i32 @_(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%47 = call i32 @error(i32 %46)
br label %48
48: ; preds = %45, %33
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
%51 = call i8* @malloc(i32 %50)
store i8* %51, i8** %6
%52 = load i8*, i8** %6
%53 = load i8**, i8*** %3
%54 = load i8*, i8** %53
%55 = load i32, i32* %7
%56 = call i32 @strncpy(i8* %52, i8* %54, i32 %55)
%57 = load i8*, i8** %6
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
store i8 0, i8* %60
%61 = load i8*, i8** %6
%62 = load i8**, i8*** %4
store i8* %61, i8** %62
%63 = load i8*, i8** %5
%64 = load i8**, i8*** %3
store i8* %63, i8** %64
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 %12
]
8: ; preds = %4
%9 = tail call i32 @_(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @error(i32 %9)
%11 = load i8*, i8** %0
br label %12
12: ; preds = %4, %8
%13 = phi i8* [ %11, %8 ], [ %3, %4 ]
%14 = getelementptr inbounds i8, i8* %5, i64 2
%15 = ptrtoint i8* %14 to i64
%16 = ptrtoint i8* %13 to i64
%17 = sub i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = icmp eq i32 %18, 3
br i1 %19, label %24, label %20
20: ; preds = %12
%21 = tail call i32 @_(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 @error(i32 %21)
%23 = load i8*, i8** %0
br label %24
24: ; preds = %20, %12
%25 = phi i8* [ %23, %20 ], [ %13, %12 ]
%26 = add nsw i32 %18, 1
%27 = tail call i8* @malloc(i32 %26)
%28 = tail call i32 @strncpy(i8* %27, i8* %25, i32 %18)
%29 = shl i64 %17, 32
%30 = ashr exact i64 %29, 32
%31 = getelementptr inbounds i8, i8* %27, i64 %30
store i8 0, i8* %31
store i8* %27, i8** %1
store i8* %14, i8** %0
ret void
}