#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 */
struct katcl_parse {
  int dummy;
};

/* Variables and functions */
int after_add_parse_katcl(struct katcl_parse *, unsigned int,
                          int /*<<< orphan*/);
scalar_t__ before_add_parse_katcl(struct katcl_parse *, int);
int /*<<< orphan*/ memcpy(char *, char *, unsigned int);
char *request_space_parse_katcl(struct katcl_parse *, unsigned int);
unsigned int strlen(char *);
int add_unsafe_parse_katcl(struct katcl_parse *p, int flags, char *string) {
  unsigned int len;
  char *ptr;
  if (before_add_parse_katcl(p, flags) < 0) {
    return -1;
  }
  len = strlen(string);
  ptr = request_space_parse_katcl(p, len + 1);
  if (ptr == NULL) {
    return -1;
  }
  memcpy(ptr, string, len);
  return after_add_parse_katcl(p, len, 0);
}


x86 assembly (clang, -O0):
<add_unsafe_parse_katcl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <before_add_parse_katcl@plt>
cmp    $0x0,%rax
jge    1185 <add_unsafe_parse_katcl+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dc <add_unsafe_parse_katcl+0x8c>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
add    $0x1,%esi
call   1070 <request_space_parse_katcl@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11bb <add_unsafe_parse_katcl+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dc <add_unsafe_parse_katcl+0x8c>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
xor    %edx,%edx
call   1040 <after_add_parse_katcl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_unsafe_parse_katcl>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rdi,%rbx
call   1060 <before_add_parse_katcl@plt>
test   %rax,%rax
js     11a1 <add_unsafe_parse_katcl+0x51>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
lea    0x1(%r15),%esi
mov    %rbx,%rdi
call   1070 <request_space_parse_katcl@plt>
test   %rax,%rax
je     11a1 <add_unsafe_parse_katcl+0x51>
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1050 <memcpy@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
xor    %edx,%edx
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <after_add_parse_katcl@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.katcl_parse = type { i32 }
define i32 @add_unsafe_parse_katcl(%struct.katcl_parse* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.katcl_parse*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store %struct.katcl_parse* %0, %struct.katcl_parse** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%10 = load %struct.katcl_parse*, %struct.katcl_parse** %5
%11 = load i32, i32* %6
%12 = call i64 @before_add_parse_katcl(%struct.katcl_parse* %10, i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %33
15: ; preds = %3
%16 = load i8*, i8** %7
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %8
%18 = load %struct.katcl_parse*, %struct.katcl_parse** %5
%19 = load i32, i32* %8
%20 = add i32 %19, 1
%21 = call i8* @request_space_parse_katcl(%struct.katcl_parse* %18, i32 %20)
store i8* %21, i8** %9
%22 = load i8*, i8** %9
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %15
store i32 -1, i32* %4
br label %33
25: ; preds = %15
%26 = load i8*, i8** %9
%27 = load i8*, i8** %7
%28 = load i32, i32* %8
%29 = call i32 @memcpy(i8* %26, i8* %27, i32 %28)
%30 = load %struct.katcl_parse*, %struct.katcl_parse** %5
%31 = load i32, i32* %8
%32 = call i32 @after_add_parse_katcl(%struct.katcl_parse* %30, i32 %31, i32 0)
store i32 %32, i32* %4
br label %33
33: ; preds = %25, %24, %14
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
%struct.katcl_parse = type { i32 }
define i32 @add_unsafe_parse_katcl(%struct.katcl_parse* %0, i32 %1, i8* %2) {
%4 = tail call i64 @before_add_parse_katcl(%struct.katcl_parse* %0, i32 %1)
%5 = icmp slt i64 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %2)
%8 = add i32 %7, 1
%9 = tail call i8* @request_space_parse_katcl(%struct.katcl_parse* %0, i32 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = tail call i32 @memcpy(i8* %9, i8* %2, i32 %7)
%13 = tail call i32 @after_add_parse_katcl(%struct.katcl_parse* %0, i32 %7, i32 0)
br label %14
14: ; preds = %6, %3, %11
%15 = phi i32 [ %13, %11 ], [ -1, %3 ], [ -1, %6 ]
ret i32 %15
}