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

/* Variables and functions */
int /*<<< orphan*/ add_plain_parse_katcl(struct katcl_parse *, int, char *);
int /*<<< orphan*/ add_string_parse_katcl(struct katcl_parse *, int, char *);
int /*<<< orphan*/ add_vargs_parse_katcl(struct katcl_parse *, int, char *,
                                         int /*<<< orphan*/);
char *code_to_name_katcm(int);
char *copy_string_parse_katcl(struct katcl_parse *, int /*<<< orphan*/);
int /*<<< orphan*/ destroy_parse_katcl(struct katcl_parse *);
int /*<<< orphan*/ free(char *);
struct katcl_parse *reuse_parse_katcl(struct katcl_parse *);
struct katcl_parse *vturnaround_extra_parse_katcl(struct katcl_parse *p,
                                                  int code, char *fmt,
                                                  va_list args) {
  char *string;
  struct katcl_parse *px;
  string = copy_string_parse_katcl(p, 0);
  if (string == NULL) {
    return NULL;
  }
  px = reuse_parse_katcl(p);
  if (px == NULL) {
    destroy_parse_katcl(p);
    return NULL;
  }
  string[0] = '!';
  add_string_parse_katcl(px, 0x01 | 0x10, string);
  free(string);
  string = code_to_name_katcm(code);
  if (fmt) {
    add_plain_parse_katcl(px, 0x10, string ? string : "fail");
    add_vargs_parse_katcl(px, 0x02 | 0x10, fmt, args);
  } else {
    add_plain_parse_katcl(px, 0x02 | 0x10, string ? string : "fail");
  }
  return px;
}


x86 assembly (clang, -O0):
<vturnaround_extra_parse_katcl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   10a0 <copy_string_parse_katcl@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11bd <vturnaround_extra_parse_katcl+0x3d>
movq   $0x0,-0x8(%rbp)
jmp    12ca <vturnaround_extra_parse_katcl+0x14a>
mov    -0x10(%rbp),%rdi
call   1050 <reuse_parse_katcl@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11eb <vturnaround_extra_parse_katcl+0x6b>
mov    -0x10(%rbp),%rdi
call   1090 <destroy_parse_katcl@plt>
movq   $0x0,-0x8(%rbp)
jmp    12ca <vturnaround_extra_parse_katcl+0x14a>
mov    -0x30(%rbp),%rax
movb   $0x21,(%rax)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x11,%esi
call   1040 <add_string_parse_katcl@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%edi
call   1080 <code_to_name_katcm@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1280 <vturnaround_extra_parse_katcl+0x100>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1244 <vturnaround_extra_parse_katcl+0xc4>
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1254 <vturnaround_extra_parse_katcl+0xd4>
lea    0xdb5(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    1254 <vturnaround_extra_parse_katcl+0xd4>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    $0x10,%esi
call   1070 <add_plain_parse_katcl@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    $0x12,%esi
call   1060 <add_vargs_parse_katcl@plt>
jmp    12c2 <vturnaround_extra_parse_katcl+0x142>
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12a0 <vturnaround_extra_parse_katcl+0x120>
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
jmp    12b0 <vturnaround_extra_parse_katcl+0x130>
lea    0xd59(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    12b0 <vturnaround_extra_parse_katcl+0x130>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    $0x12,%esi
call   1070 <add_plain_parse_katcl@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vturnaround_extra_parse_katcl>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%r12d
mov    %rdi,%rbx
xor    %r13d,%r13d
xor    %esi,%esi
call   10a0 <copy_string_parse_katcl@plt>
test   %rax,%rax
je     122d <vturnaround_extra_parse_katcl+0xad>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1050 <reuse_parse_katcl@plt>
test   %rax,%rax
je     1216 <vturnaround_extra_parse_katcl+0x96>
mov    %rax,%r13
movb   $0x21,0x0(%rbp)
mov    %rax,%rdi
mov    $0x11,%esi
mov    %rbp,%rdx
call   1040 <add_string_parse_katcl@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r12d,%edi
call   1080 <code_to_name_katcm@plt>
test   %rax,%rax
lea    0xe15(%rip),%rdx
cmovne %rax,%rdx
mov    %r13,%rdi
test   %r15,%r15
je     1223 <vturnaround_extra_parse_katcl+0xa3>
mov    $0x10,%esi
call   1070 <add_plain_parse_katcl@plt>
mov    %r13,%rdi
mov    $0x12,%esi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1060 <add_vargs_parse_katcl@plt>
jmp    122d <vturnaround_extra_parse_katcl+0xad>
mov    %rbx,%rdi
call   1090 <destroy_parse_katcl@plt>
xor    %r13d,%r13d
jmp    122d <vturnaround_extra_parse_katcl+0xad>
mov    $0x12,%esi
call   1070 <add_plain_parse_katcl@plt>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.katcl_parse = type { i32 }
@.str = [5 x i8] c"fail\00"
define %struct.katcl_parse* @vturnaround_extra_parse_katcl(%struct.katcl_parse* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca %struct.katcl_parse*
%6 = alloca %struct.katcl_parse*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca %struct.katcl_parse*
store %struct.katcl_parse* %0, %struct.katcl_parse** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%12 = load %struct.katcl_parse*, %struct.katcl_parse** %6
%13 = call i8* @copy_string_parse_katcl(%struct.katcl_parse* %12, i32 0)
store i8* %13, i8** %10
%14 = load i8*, i8** %10
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %4
store %struct.katcl_parse* null, %struct.katcl_parse** %5
br label %63
17: ; preds = %4
%18 = load %struct.katcl_parse*, %struct.katcl_parse** %6
%19 = call %struct.katcl_parse* @reuse_parse_katcl(%struct.katcl_parse* %18)
store %struct.katcl_parse* %19, %struct.katcl_parse** %11
%20 = load %struct.katcl_parse*, %struct.katcl_parse** %11
%21 = icmp eq %struct.katcl_parse* %20, null
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load %struct.katcl_parse*, %struct.katcl_parse** %6
%24 = call i32 @destroy_parse_katcl(%struct.katcl_parse* %23)
store %struct.katcl_parse* null, %struct.katcl_parse** %5
br label %63
25: ; preds = %17
%26 = load i8*, i8** %10
%27 = getelementptr inbounds i8, i8* %26, i64 0
store i8 33, i8* %27
%28 = load %struct.katcl_parse*, %struct.katcl_parse** %11
%29 = load i8*, i8** %10
%30 = call i32 @add_string_parse_katcl(%struct.katcl_parse* %28, i32 17, i8* %29)
%31 = load i8*, i8** %10
%32 = call i32 @free(i8* %31)
%33 = load i32, i32* %7
%34 = call i8* @code_to_name_katcm(i32 %33)
store i8* %34, i8** %10
%35 = load i8*, i8** %8
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %51
37: ; preds = %25
%38 = load %struct.katcl_parse*, %struct.katcl_parse** %11
%39 = load i8*, i8** %10
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = load i8*, i8** %10
br label %44
43: ; preds = %37
br label %44
44: ; preds = %43, %41
%45 = phi i8* [ %42, %41 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %43 ]
%46 = call i32 @add_plain_parse_katcl(%struct.katcl_parse* %38, i32 16, i8* %45)
%47 = load %struct.katcl_parse*, %struct.katcl_parse** %11
%48 = load i8*, i8** %8
%49 = load i32, i32* %9
%50 = call i32 @add_vargs_parse_katcl(%struct.katcl_parse* %47, i32 18, i8* %48, i32 %49)
br label %61
51: ; preds = %25
%52 = load %struct.katcl_parse*, %struct.katcl_parse** %11
%53 = load i8*, i8** %10
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %57
55: ; preds = %51
%56 = load i8*, i8** %10
br label %58
57: ; preds = %51
br label %58
58: ; preds = %57, %55
%59 = phi i8* [ %56, %55 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %57 ]
%60 = call i32 @add_plain_parse_katcl(%struct.katcl_parse* %52, i32 18, i8* %59)
br label %61
61: ; preds = %58, %44
%62 = load %struct.katcl_parse*, %struct.katcl_parse** %11
store %struct.katcl_parse* %62, %struct.katcl_parse** %5
br label %63
63: ; preds = %61, %22, %16
%64 = load %struct.katcl_parse*, %struct.katcl_parse** %5
ret %struct.katcl_parse* %64
}

LLVM IR (-O2):
%struct.katcl_parse = type { i32 }
@.str = [5 x i8] c"fail\00"
define %struct.katcl_parse* @vturnaround_extra_parse_katcl(%struct.katcl_parse* %0, i32 %1, i8* %2, i32 %3) {
%5 = tail call i8* @copy_string_parse_katcl(%struct.katcl_parse* %0, i32 0)
%6 = icmp eq i8* %5, null
br i1 %6, label %24, label %7
7: ; preds = %4
%8 = tail call %struct.katcl_parse* @reuse_parse_katcl(%struct.katcl_parse* %0)
%9 = icmp eq %struct.katcl_parse* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @destroy_parse_katcl(%struct.katcl_parse* %0)
br label %24
12: ; preds = %7
store i8 33, i8* %5
%13 = tail call i32 @add_string_parse_katcl(%struct.katcl_parse* %8, i32 17, i8* %5)
%14 = tail call i32 @free(i8* %5)
%15 = tail call i8* @code_to_name_katcm(i32 %1)
%16 = icmp eq i8* %2, null
%17 = icmp eq i8* %15, null
%18 = select i1 %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %15
br i1 %16, label %22, label %19
19: ; preds = %12
%20 = tail call i32 @add_plain_parse_katcl(%struct.katcl_parse* %8, i32 16, i8* %18)
%21 = tail call i32 @add_vargs_parse_katcl(%struct.katcl_parse* %8, i32 18, i8* %2, i32 %3)
br label %24
22: ; preds = %12
%23 = tail call i32 @add_plain_parse_katcl(%struct.katcl_parse* %8, i32 18, i8* %18)
br label %24
24: ; preds = %19, %22, %4, %10
%25 = phi %struct.katcl_parse* [ null, %10 ], [ null, %4 ], [ %8, %22 ], [ %8, %19 ]
ret %struct.katcl_parse* %25
}