#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 */
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char const *, size_t const);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
size_t json_parse_literal(const char *str, const char *literal, char *buf,
                          size_t size) {
  const size_t len = strlen(literal);
  if (strncmp(str, literal, len) != 0)
    return 0;
  if (buf) {
    strncpy(buf, literal, size);
    if (buf[size - 1] != '\0')
      return 0;
  }
  return len;
}


x86 assembly (clang, -O0):
<json_parse_literal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     117d <json_parse_literal+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    11cc <json_parse_literal+0x9c>
cmpq   $0x0,-0x20(%rbp)
je     11c4 <json_parse_literal+0x94>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11bf <json_parse_literal+0x8f>
movq   $0x0,-0x8(%rbp)
jmp    11cc <json_parse_literal+0x9c>
jmp    11c4 <json_parse_literal+0x94>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<json_parse_literal>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r13
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %rax,%r12
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1173 <json_parse_literal+0x43>
xor    %r12d,%r12d
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
test   %r15,%r15
je     1166 <json_parse_literal+0x36>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <strncpy@plt>
cmpb   $0x0,-0x1(%r14,%r15,1)
jne    1163 <json_parse_literal+0x33>
jmp    1166 <json_parse_literal+0x36>

LLVM IR (-O0):
define i64 @json_parse_literal(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%11 = load i8*, i8** %7
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %10
%13 = load i8*, i8** %6
%14 = load i8*, i8** %7
%15 = load i64, i64* %10
%16 = call i64 @strncmp(i8* %13, i8* %14, i64 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %4
store i64 0, i64* %5
br label %38
19: ; preds = %4
%20 = load i8*, i8** %8
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %36
22: ; preds = %19
%23 = load i8*, i8** %8
%24 = load i8*, i8** %7
%25 = load i64, i64* %9
%26 = call i32 @strncpy(i8* %23, i8* %24, i64 %25)
%27 = load i8*, i8** %8
%28 = load i64, i64* %9
%29 = sub i64 %28, 1
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %22
store i64 0, i64* %5
br label %38
35: ; preds = %22
br label %36
36: ; preds = %35, %19
%37 = load i64, i64* %10
store i64 %37, i64* %5
br label %38
38: ; preds = %36, %34, %18
%39 = load i64, i64* %5
ret i64 %39
}

LLVM IR (-O2):
define i64 @json_parse_literal(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = tail call i64 @strncmp(i8* %0, i8* %1, i64 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %4
%9 = icmp eq i8* %2, null
br i1 %9, label %16, label %10
10: ; preds = %8
%11 = tail call i32 @strncpy(i8* %2, i8* %1, i64 %3)
%12 = add i64 %3, -1
%13 = getelementptr inbounds i8, i8* %2, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10, %8
br label %17
17: ; preds = %10, %4, %16
%18 = phi i64 [ %5, %16 ], [ 0, %4 ], [ 0, %10 ]
ret i64 %18
}