#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*/ log_print(char *, unsigned int);
int /*<<< orphan*/ memcpy(char *, char *, unsigned int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, unsigned int);
int dq_string_get(char *word_buf, unsigned int word_buf_len, char *input_buf,
                  unsigned int *offset) {
  unsigned int cur_offset = *offset;
  memset(word_buf, 0, word_buf_len);
  if (input_buf[cur_offset] == '"') {
    unsigned int dq_str_len;
    cur_offset++;
    while (input_buf[cur_offset] != '"')
      cur_offset++;
    dq_str_len = cur_offset - (*offset) - 1;
    if (dq_str_len >= word_buf_len) {
      log_print("asn_dq_string_get::string len %d > max len\r\n", dq_str_len);
      return -1;
    }
    memcpy(word_buf, input_buf + (*offset) + 1, dq_str_len);
    *offset = ++cur_offset;
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<dq_string_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x22,%eax
jne    120b <dq_string_get+0xdb>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x22,%eax
je     119d <dq_string_get+0x6d>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    117b <dq_string_get+0x4b>
mov    -0x2c(%rbp),%eax
mov    -0x28(%rbp),%rcx
sub    (%rcx),%eax
sub    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jb     11d3 <dq_string_get+0xa3>
mov    -0x30(%rbp),%esi
lea    0xe3e(%rip),%rdi
call   1030 <log_print@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1212 <dq_string_get+0xe2>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
add    %rax,%rsi
add    $0x1,%rsi
mov    -0x30(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1212 <dq_string_get+0xe2>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dq_string_get>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%rbp
mov    %esi,%r13d
mov    %rdi,%r15
mov    (%rcx),%ebx
xor    %esi,%esi
mov    %r13d,%edx
call   1040 <memset@plt>
mov    $0xffffffff,%r14d
cmpb   $0x22,0x0(%rbp,%rbx,1)
jne    11b3 <dq_string_get+0x83>
add    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%eax
add    $0x1,%ebx
cmpb   $0x22,0x0(%rbp,%rax,1)
jne    1170 <dq_string_get+0x40>
mov    (%r12),%eax
mov    %ebx,%edx
sub    %eax,%edx
add    $0xfffffffe,%edx
cmp    %r13d,%edx
jae    11a5 <dq_string_get+0x75>
lea    (%rax,%rbp,1),%rsi
add    $0x1,%rsi
mov    %r15,%rdi
call   1050 <memcpy@plt>
mov    %ebx,(%r12)
xor    %r14d,%r14d
jmp    11b3 <dq_string_get+0x83>
lea    0xe54(%rip),%rdi
mov    %edx,%esi
call   1030 <log_print@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"asn_dq_string_get::string len %d > max len\0D\0A\00"
define i32 @dq_string_get(i8* %0, i32 %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32* %3, i32** %9
%12 = load i32*, i32** %9
%13 = load i32, i32* %12
store i32 %13, i32* %10
%14 = load i8*, i8** %6
%15 = load i32, i32* %7
%16 = call i32 @memset(i8* %14, i32 0, i32 %15)
%17 = load i8*, i8** %8
%18 = load i32, i32* %10
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 34
br i1 %23, label %24, label %63
24: ; preds = %4
%25 = load i32, i32* %10
%26 = add i32 %25, 1
store i32 %26, i32* %10
br label %27
27: ; preds = %35, %24
%28 = load i8*, i8** %8
%29 = load i32, i32* %10
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 34
br i1 %34, label %35, label %38
35: ; preds = %27
%36 = load i32, i32* %10
%37 = add i32 %36, 1
store i32 %37, i32* %10
br label %27
38: ; preds = %27
%39 = load i32, i32* %10
%40 = load i32*, i32** %9
%41 = load i32, i32* %40
%42 = sub i32 %39, %41
%43 = sub i32 %42, 1
store i32 %43, i32* %11
%44 = load i32, i32* %11
%45 = load i32, i32* %7
%46 = icmp uge i32 %44, %45
br i1 %46, label %47, label %50
47: ; preds = %38
%48 = load i32, i32* %11
%49 = call i32 @log_print(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %48)
store i32 -1, i32* %5
br label %64
50: ; preds = %38
%51 = load i8*, i8** %6
%52 = load i8*, i8** %8
%53 = load i32*, i32** %9
%54 = load i32, i32* %53
%55 = zext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %52, i64 %55
%57 = getelementptr inbounds i8, i8* %56, i64 1
%58 = load i32, i32* %11
%59 = call i32 @memcpy(i8* %51, i8* %57, i32 %58)
%60 = load i32, i32* %10
%61 = add i32 %60, 1
store i32 %61, i32* %10
%62 = load i32*, i32** %9
store i32 %61, i32* %62
store i32 0, i32* %5
br label %64
63: ; preds = %4
store i32 -1, i32* %5
br label %64
64: ; preds = %63, %50, %47
%65 = load i32, i32* %5
ret i32 %65
}

LLVM IR (-O2):
@.str = [45 x i8] c"asn_dq_string_get::string len %d > max len\0D\0A\00"
define i32 @dq_string_get(i8* %0, i32 %1, i8* %2, i32* nocapture %3) {
%5 = load i32, i32* %3
%6 = tail call i32 @memset(i8* %0, i32 0, i32 %1)
%7 = zext i32 %5 to i64
%8 = getelementptr inbounds i8, i8* %2, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 34
br i1 %10, label %11, label %30
11: ; preds = %4, %11
%12 = phi i32 [ %13, %11 ], [ %5, %4 ]
%13 = add i32 %12, 1
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %2, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 34
br i1 %17, label %18, label %11
18: ; preds = %11
%19 = load i32, i32* %3
%20 = sub i32 %12, %19
%21 = icmp ult i32 %20, %1
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = tail call i32 @log_print(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %30
24: ; preds = %18
%25 = zext i32 %19 to i64
%26 = getelementptr inbounds i8, i8* %2, i64 %25
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = tail call i32 @memcpy(i8* %0, i8* %27, i32 %20)
%29 = add i32 %12, 2
store i32 %29, i32* %3
br label %30
30: ; preds = %4, %22, %24
%31 = phi i32 [ -1, %22 ], [ 0, %24 ], [ -1, %4 ]
ret i32 %31
}