#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*/ assert(int);
int /*<<< orphan*/ ocr_log(int, char *, int, char *, ...);
const char *read_string(char *buffer, size_t buffer_size, const char *text) {
  assert(text[0] == '"');
  ++text;
  size_t count = 0;
  while (text && text[0] != '"' && count < buffer_size) {
    char c = text[0];
    ++text;
    buffer[count++] = c;
  }
  buffer[count] = 0;
  ocr_log(2,
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/oblivionsoftware/ocr/refs/heads/master/"
          "src/json.c",
          76, "read string: %s", buffer);
  if (text[0] != '"') {
    ocr_log(3,
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/oblivionsoftware/ocr/refs/heads/master/"
            "src/json.c",
            79, "expected text to be quote, but was %c", text[0]);
  }
  ++text;
  return text;
}


x86 assembly (clang, -O0):
<read_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x22(%rbp)
je     1192 <read_string+0x72>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x22,%ecx
mov    %al,-0x22(%rbp)
je     1192 <read_string+0x72>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
setb   %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    11a2 <read_string+0x82>
jmp    11d5 <read_string+0xb5>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x21(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x21(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x20(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    115f <read_string+0x3f>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%r8
mov    $0x2,%edi
lea    0xe0f(%rip),%rsi
mov    $0x4c,%edx
lea    0xe8f(%rip),%rcx
mov    $0x0,%al
call   1040 <ocr_log@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
je     123b <read_string+0x11b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%r8d
mov    $0x3,%edi
lea    0xdd8(%rip),%rsi
mov    $0x4f,%edx
lea    0xe68(%rip),%rcx
mov    $0x0,%al
call   1040 <ocr_log@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
xor    %edi,%edi
cmpb   $0x22,(%rdx)
sete   %dil
call   1030 <assert@plt>
lea    0x1(%r14),%rbx
mov    0x1(%r14),%cl
xor    %eax,%eax
cmp    $0x22,%cl
je     117e <read_string+0x5e>
test   %r12,%r12
je     117e <read_string+0x5e>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
mov    %cl,(%r15,%rax,1)
add    $0x1,%rax
movzbl 0x1(%rbx),%ecx
add    $0x1,%rbx
cmp    $0x22,%cl
je     117a <read_string+0x5a>
cmp    %r12,%rax
jb     1160 <read_string+0x40>
lea    -0x1(%rbx),%r14
movb   $0x0,(%r15,%rax,1)
lea    0xe76(%rip),%rsi
lea    0xefb(%rip),%rcx
mov    $0x2,%edi
mov    $0x4c,%edx
mov    %r15,%r8
xor    %eax,%eax
call   1040 <ocr_log@plt>
movsbl (%rbx),%r8d
cmp    $0x22,%r8d
je     11ce <read_string+0xae>
lea    0xe4a(%rip),%rsi
lea    0xedf(%rip),%rcx
mov    $0x3,%edi
mov    $0x4f,%edx
xor    %eax,%eax
call   1040 <ocr_log@plt>
add    $0x2,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/oblivionsoftware/ocr/refs/heads/master/src/json.c\00"
@.str.1 = [16 x i8] c"read string: %s\00"
@.str.2 = [38 x i8] c"expected text to be quote, but was %c\00"
define i8* @read_string(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 34
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8*, i8** %6
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %6
store i64 0, i64* %7
br label %18
18: ; preds = %33, %3
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 34
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i64, i64* %7
%29 = load i64, i64* %5
%30 = icmp ult i64 %28, %29
br label %31
31: ; preds = %27, %21, %18
%32 = phi i1 [ false, %21 ], [ false, %18 ], [ %30, %27 ]
br i1 %32, label %33, label %44
33: ; preds = %31
%34 = load i8*, i8** %6
%35 = getelementptr inbounds i8, i8* %34, i64 0
%36 = load i8, i8* %35
store i8 %36, i8* %8
%37 = load i8*, i8** %6
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %6
%39 = load i8, i8* %8
%40 = load i8*, i8** %4
%41 = load i64, i64* %7
%42 = add i64 %41, 1
store i64 %42, i64* %7
%43 = getelementptr inbounds i8, i8* %40, i64 %41
store i8 %39, i8* %43
br label %18
44: ; preds = %31
%45 = load i8*, i8** %4
%46 = load i64, i64* %7
%47 = getelementptr inbounds i8, i8* %45, i64 %46
store i8 0, i8* %47
%48 = load i8*, i8** %4
%49 = call i32 (i32, i8*, i32, i8*, ...) @ocr_log(i32 2, i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str, i64 0, i64 0), i32 76, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %48)
%50 = load i8*, i8** %6
%51 = getelementptr inbounds i8, i8* %50, i64 0
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 34
br i1 %54, label %55, label %61
55: ; preds = %44
%56 = load i8*, i8** %6
%57 = getelementptr inbounds i8, i8* %56, i64 0
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = call i32 (i32, i8*, i32, i8*, ...) @ocr_log(i32 3, i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str, i64 0, i64 0), i32 79, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %55, %44
%62 = load i8*, i8** %6
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %6
%64 = load i8*, i8** %6
ret i8* %64
}

LLVM IR (-O2):
@.str = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/oblivionsoftware/ocr/refs/heads/master/src/json.c\00"
@.str.1 = [16 x i8] c"read string: %s\00"
@.str.2 = [38 x i8] c"expected text to be quote, but was %c\00"
define i8* @read_string(i8* %0, i64 %1, i8* %2) {
%4 = load i8, i8* %2
%5 = icmp eq i8 %4, 34
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = getelementptr inbounds i8, i8* %2, i64 1
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 34
%11 = icmp ne i64 %1, 0
%12 = and i1 %10, %11
br i1 %12, label %13, label %24
13: ; preds = %3, %13
%14 = phi i8 [ %20, %13 ], [ %9, %3 ]
%15 = phi i8* [ %19, %13 ], [ %8, %3 ]
%16 = phi i64 [ %17, %13 ], [ 0, %3 ]
%17 = add nuw i64 %16, 1
%18 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 %14, i8* %18
%19 = getelementptr inbounds i8, i8* %15, i64 1
%20 = load i8, i8* %19
%21 = icmp ne i8 %20, 34
%22 = icmp ult i64 %17, %1
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %13, label %24
24: ; preds = %13, %3
%25 = phi i64 [ 0, %3 ], [ %17, %13 ]
%26 = phi i8* [ %2, %3 ], [ %15, %13 ]
%27 = phi i8* [ %8, %3 ], [ %19, %13 ]
%28 = getelementptr inbounds i8, i8* %0, i64 %25
store i8 0, i8* %28
%29 = tail call i32 (i32, i8*, i32, i8*, ...) @ocr_log(i32 2, i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str, i64 0, i64 0), i32 76, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%30 = load i8, i8* %27
%31 = icmp eq i8 %30, 34
br i1 %31, label %35, label %32
32: ; preds = %24
%33 = sext i8 %30 to i32
%34 = tail call i32 (i32, i8*, i32, i8*, ...) @ocr_log(i32 3, i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str, i64 0, i64 0), i32 79, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %32, %24
%36 = getelementptr inbounds i8, i8* %26, i64 2
ret i8* %36
}