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 = xmalloc(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),%edi
add    $0x1,%edi
mov    $0x0,%al
call   1040 <xmalloc@plt>
movslq %eax,%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,%r14
mov    %rdi,%r15
movabs $0x100000000,%rax
mov    (%rdi),%r13
lea    0x1(%r13),%rbx
mov    %r13,%r12
shl    $0x20,%r12
add    %rax,%r12
lea    0x2(%r13),%ebp
movzbl (%rbx),%ecx
add    $0x1,%rbx
add    %rax,%r12
add    $0x1,%ebp
cmp    $0x22,%cl
je     1187 <findstrconst+0x57>
test   %cl,%cl
jne    1160 <findstrconst+0x30>
lea    0xe83(%rip),%rdi
xor    %eax,%eax
call   1050 <error@plt>
mov    (%r15),%r13
sub    %r13d,%ebp
mov    %ebp,%edi
xor    %eax,%eax
call   1040 <xmalloc@plt>
movslq %eax,%rdi
mov    %rdi,(%r14)
mov    (%r15),%rsi
shl    $0x20,%r13
sub    %r13,%r12
sar    $0x20,%r12
mov    %r12,%rdx
call   1030 <strncpy@plt>
mov    (%r14),%rax
movb   $0x0,(%rax,%r12,1)
mov    %rbx,(%r15)
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 = call i32 (i32, ...) bitcast (i32 (...)* @xmalloc to i32 (i32, ...)*)(i32 %42)
%44 = sext i32 %43 to i64
%45 = inttoptr i64 %44 to i8*
%46 = load i8**, i8*** %4
store i8* %45, i8** %46
%47 = load i8**, i8*** %4
%48 = load i8*, i8** %47
%49 = load i8**, i8*** %3
%50 = load i8*, i8** %49
%51 = load i32, i32* %6
%52 = sext i32 %51 to i64
%53 = call i8* @strncpy(i8* %48, i8* %50, i64 %52)
%54 = load i8**, i8*** %4
%55 = load i8*, i8** %54
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
store i8 0, i8* %58
%59 = load i8*, i8** %5
%60 = load i8**, i8*** %3
store i8* %59, i8** %60
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"unterminated string constant\00"
define void @findstrconst(i8** nocapture %0, i8** nocapture %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 = trunc i64 %16 to i32
%18 = add nsw i32 %17, 1
%19 = tail call i32 (i32, ...) bitcast (i32 (...)* @xmalloc to i32 (i32, ...)*)(i32 %18)
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %1
%22 = load i8*, i8** %0
%23 = shl i64 %16, 32
%24 = ashr exact i64 %23, 32
%25 = tail call i8* @strncpy(i8* dereferenceable(1) %21, i8* %22, i64 %24)
%26 = load i8*, i8** %1
%27 = getelementptr inbounds i8, i8* %26, i64 %24
store i8 0, i8* %27
store i8* %13, i8** %0
ret void
}