void findstrconst(str, val) char **str;
char **val;
{
  char *p;
  int size;
  p = *str;
  do {
    p++;
  } while (*p && *p != '"');
  if (*p == 0) {
    error("unterminated string constant");
  }
  p++;
  size = p - *str;
  *val = malloc((unsigned)(size + 1));
  (void)strncpy(*val, *str, size);
  (*val)[size] = 0;
  *str = p;
}


x86 assembly (clang, -O0):
<findstrconst>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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,-0x1d(%rbp)
je     117c <findstrconst+0x4c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    114b <findstrconst+0x1b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a5 <findstrconst+0x75>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
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)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
movslq -0x1c(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findstrconst>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
movabs $0x100000000,%rax
mov    (%rdi),%rbp
lea    0x1(%rbp),%r13
mov    %rbp,%r12
shl    $0x20,%r12
add    %rax,%r12
lea    0x2(%rbp),%rbx
movzbl 0x0(%r13),%ecx
add    $0x1,%r13
add    %rax,%r12
add    $0x1,%rbx
cmp    $0x22,%cl
je     118a <findstrconst+0x5a>
test   %cl,%cl
jne    1160 <findstrconst+0x30>
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1050 <error@plt>
mov    (%r14),%rbp
sub    %ebp,%ebx
mov    %rbx,%rdi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,(%r15)
mov    (%r14),%rsi
shl    $0x20,%rbp
sub    %rbp,%r12
sar    $0x20,%r12
mov    %rax,%rdi
mov    %r12,%rdx
call   1030 <strncpy@plt>
movb   $0x0,(%rbx,%r12,1)
mov    %r13,(%r14)
add    $0x8,%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"
define void @findstrconst(i8** %0, i8** %1) {
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
store i8** %0, i8*** %3
store i8** %1, i8*** %4
%7 = load i8**, i8*** %3
%8 = load i8*, i8** %7
store i8* %8, i8** %5
br label %9
9: ; preds = %22, %2
%10 = load i8*, i8** %5
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %5
br label %12
12: ; preds = %9
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i8*, i8** %5
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 34
br label %22
22: ; preds = %17, %12
%23 = phi i1 [ false, %12 ], [ %21, %17 ]
br i1 %23, label %9, label %24
24: ; preds = %22
%25 = load i8*, i8** %5
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 (i8*, ...) bitcast (i32 (...)* @error to i32 (i8*, ...)*)(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %29, %24
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %5
%34 = load i8*, i8** %5
%35 = load i8**, i8*** %3
%36 = load i8*, i8** %35
%37 = ptrtoint i8* %34 to i64
%38 = ptrtoint i8* %36 to i64
%39 = sub i64 %37, %38
%40 = trunc i64 %39 to i32
store i32 %40, i32* %6
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
%43 = zext i32 %42 to i64
%44 = call i8* @malloc(i64 %43)
%45 = load i8**, i8*** %4
store i8* %44, i8** %45
%46 = load i8**, i8*** %4
%47 = load i8*, i8** %46
%48 = load i8**, i8*** %3
%49 = load i8*, i8** %48
%50 = load i32, i32* %6
%51 = sext i32 %50 to i64
%52 = call i8* @strncpy(i8* %47, i8* %49, i64 %51)
%53 = load i8**, i8*** %4
%54 = load i8*, i8** %53
%55 = load i32, i32* %6
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
store i8 0, i8* %57
%58 = load i8*, i8** %5
%59 = load i8**, i8*** %3
store i8* %58, i8** %59
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"unterminated string constant\00"
define void @findstrconst(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 34, label %11
]
8: ; preds = %4
%9 = tail call i32 (i8*, ...) bitcast (i32 (...)* @error to i32 (i8*, ...)*)(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 = add i64 %16, 1
%18 = and i64 %17, 4294967295
%19 = tail call i8* @malloc(i64 %18)
store i8* %19, i8** %1
%20 = load i8*, i8** %0
%21 = shl i64 %16, 32
%22 = ashr exact i64 %21, 32
%23 = tail call i8* @strncpy(i8* dereferenceable(1) %19, i8* %20, i64 %22)
%24 = getelementptr inbounds i8, i8* %19, i64 %22
store i8 0, i8* %24
store i8* %13, i8** %0
ret void
}