#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;
};
struct katcl_line {
  int dummy;
};

/* Variables and functions */
int add_string_parse_katcl(struct katcl_parse *, int, char *);
int after_append_katcl(struct katcl_line *, int, int);
struct katcl_parse *before_append_katcl(struct katcl_line *, int);
int append_string_katcl(struct katcl_line *l, int flags, char *buffer) {
  struct katcl_parse *p;
  int result;
  p = before_append_katcl(l, flags);
  if (p == NULL) {
    return -1;
  }
  result = add_string_parse_katcl(p, flags, buffer);
  return after_append_katcl(l, flags, result);
}


x86 assembly (clang, -O0):
<append_string_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   1040 <before_append_katcl@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    116a <append_string_katcl+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    118f <append_string_katcl+0x5f>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1030 <add_string_parse_katcl@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1050 <after_append_katcl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_string_katcl>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%r14
call   1040 <before_append_katcl@plt>
test   %rax,%rax
je     1165 <append_string_katcl+0x35>
mov    %rax,%rdi
mov    %ebx,%esi
mov    %r15,%rdx
call   1030 <add_string_parse_katcl@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <after_append_katcl@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.katcl_line = type { i32 }
%struct.katcl_parse = type { i32 }
define i32 @append_string_katcl(%struct.katcl_line* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.katcl_line*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.katcl_parse*
%9 = alloca i32
store %struct.katcl_line* %0, %struct.katcl_line** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%10 = load %struct.katcl_line*, %struct.katcl_line** %5
%11 = load i32, i32* %6
%12 = call %struct.katcl_parse* @before_append_katcl(%struct.katcl_line* %10, i32 %11)
store %struct.katcl_parse* %12, %struct.katcl_parse** %8
%13 = load %struct.katcl_parse*, %struct.katcl_parse** %8
%14 = icmp eq %struct.katcl_parse* %13, null
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %25
16: ; preds = %3
%17 = load %struct.katcl_parse*, %struct.katcl_parse** %8
%18 = load i32, i32* %6
%19 = load i8*, i8** %7
%20 = call i32 @add_string_parse_katcl(%struct.katcl_parse* %17, i32 %18, i8* %19)
store i32 %20, i32* %9
%21 = load %struct.katcl_line*, %struct.katcl_line** %5
%22 = load i32, i32* %6
%23 = load i32, i32* %9
%24 = call i32 @after_append_katcl(%struct.katcl_line* %21, i32 %22, i32 %23)
store i32 %24, i32* %4
br label %25
25: ; preds = %16, %15
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
%struct.katcl_line = type { i32 }
%struct.katcl_parse = type { i32 }
define i32 @append_string_katcl(%struct.katcl_line* %0, i32 %1, i8* %2) {
%4 = tail call %struct.katcl_parse* @before_append_katcl(%struct.katcl_line* %0, i32 %1)
%5 = icmp eq %struct.katcl_parse* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i32 @add_string_parse_katcl(%struct.katcl_parse* %4, i32 %1, i8* %2)
%8 = tail call i32 @after_append_katcl(%struct.katcl_line* %0, i32 %1, i32 %7)
br label %9
9: ; preds = %3, %6
%10 = phi i32 [ %8, %6 ], [ -1, %3 ]
ret i32 %10
}