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

/* Variables and functions */
int append_string_katcl(struct katcl_line *, int, char *);
int append_vargs_katcl(struct katcl_line *, int, char *, int /*<<< orphan*/);
char *arg_copy_string_katcl(struct katcl_line *, int /*<<< orphan*/);
char *code_to_name_katcm(int);
int /*<<< orphan*/ free(char *);
int vector_sum(int *, int);
int vextra_response_katcl(struct katcl_line *cl, int code, char *fmt,
                          va_list args) {
  int result[3];
  char *name, *status;
  if (code > 0) {
    return -1;
  }
  name = arg_copy_string_katcl(cl, 0);
  if (name == NULL) {
    return -1;
  }
  name[0] = '!';
  status = code_to_name_katcm(code);
  if (status == NULL) {
    free(name);
    return -1;
  }
  result[0] = append_string_katcl(cl, 0x01, name);
  free(name);
  if (fmt == NULL) {
    result[1] = append_string_katcl(cl, 0x02, status);
    return vector_sum(result, 2);
  } else {
    result[1] = append_string_katcl(cl, 0, status);
    result[2] = append_vargs_katcl(cl, 0x02, fmt, args);
    return vector_sum(result, 3);
  }
}


x86 assembly (clang, -O0):
<vextra_response_katcl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    118c <vextra_response_katcl+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1274 <vextra_response_katcl+0x114>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <arg_copy_string_katcl@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11b2 <vextra_response_katcl+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    1274 <vextra_response_katcl+0x114>
mov    -0x38(%rbp),%rax
movb   $0x21,(%rax)
mov    -0x14(%rbp),%edi
call   1080 <code_to_name_katcm@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11e5 <vextra_response_katcl+0x85>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1274 <vextra_response_katcl+0x114>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x1,%esi
call   1050 <append_string_katcl@plt>
mov    %eax,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1239 <vextra_response_katcl+0xd9>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    $0x2,%esi
call   1050 <append_string_katcl@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x2,%esi
call   1070 <vector_sum@plt>
mov    %eax,-0x4(%rbp)
jmp    1274 <vextra_response_katcl+0x114>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rdx
xor    %esi,%esi
call   1050 <append_string_katcl@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    $0x2,%esi
call   1060 <append_vargs_katcl@plt>
mov    %eax,-0x28(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x3,%esi
call   1070 <vector_sum@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vextra_response_katcl>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0xffffffff,%ebx
test   %esi,%esi
jle    1188 <vextra_response_katcl+0x28>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%r13
xor    %esi,%esi
call   1040 <arg_copy_string_katcl@plt>
test   %rax,%rax
je     1177 <vextra_response_katcl+0x17>
mov    %rax,%r12
movb   $0x21,(%rax)
mov    %ebp,%edi
call   1080 <code_to_name_katcm@plt>
test   %rax,%rax
je     1209 <vextra_response_katcl+0xa9>
mov    %rax,%rbp
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
call   1050 <append_string_katcl@plt>
mov    %eax,0xc(%rsp)
mov    %r12,%rdi
call   1030 <free@plt>
test   %r15,%r15
je     1216 <vextra_response_katcl+0xb6>
mov    %r13,%rdi
xor    %esi,%esi
mov    %rbp,%rdx
call   1050 <append_string_katcl@plt>
mov    %eax,0x10(%rsp)
mov    %r13,%rdi
mov    $0x2,%esi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1060 <append_vargs_katcl@plt>
mov    %eax,0x14(%rsp)
lea    0xc(%rsp),%rdi
mov    $0x3,%esi
jmp    1234 <vextra_response_katcl+0xd4>
mov    %r12,%rdi
call   1030 <free@plt>
jmp    1177 <vextra_response_katcl+0x17>
mov    %r13,%rdi
mov    $0x2,%esi
mov    %rbp,%rdx
call   1050 <append_string_katcl@plt>
mov    %eax,0x10(%rsp)
lea    0xc(%rsp),%rdi
mov    $0x2,%esi
call   1070 <vector_sum@plt>
mov    %eax,%ebx
jmp    1177 <vextra_response_katcl+0x17>

LLVM IR (-O0):
%struct.katcl_line = type { i32 }
define i32 @vextra_response_katcl(%struct.katcl_line* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.katcl_line*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [3 x i32]
%11 = alloca i8*
%12 = alloca i8*
store %struct.katcl_line* %0, %struct.katcl_line** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%13 = load i32, i32* %7
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 -1, i32* %5
br label %60
16: ; preds = %4
%17 = load %struct.katcl_line*, %struct.katcl_line** %6
%18 = call i8* @arg_copy_string_katcl(%struct.katcl_line* %17, i32 0)
store i8* %18, i8** %11
%19 = load i8*, i8** %11
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 -1, i32* %5
br label %60
22: ; preds = %16
%23 = load i8*, i8** %11
%24 = getelementptr inbounds i8, i8* %23, i64 0
store i8 33, i8* %24
%25 = load i32, i32* %7
%26 = call i8* @code_to_name_katcm(i32 %25)
store i8* %26, i8** %12
%27 = load i8*, i8** %12
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i8*, i8** %11
%31 = call i32 @free(i8* %30)
store i32 -1, i32* %5
br label %60
32: ; preds = %22
%33 = load %struct.katcl_line*, %struct.katcl_line** %6
%34 = load i8*, i8** %11
%35 = call i32 @append_string_katcl(%struct.katcl_line* %33, i32 1, i8* %34)
%36 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 0
store i32 %35, i32* %36
%37 = load i8*, i8** %11
%38 = call i32 @free(i8* %37)
%39 = load i8*, i8** %8
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %48
41: ; preds = %32
%42 = load %struct.katcl_line*, %struct.katcl_line** %6
%43 = load i8*, i8** %12
%44 = call i32 @append_string_katcl(%struct.katcl_line* %42, i32 2, i8* %43)
%45 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 1
store i32 %44, i32* %45
%46 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 0
%47 = call i32 @vector_sum(i32* %46, i32 2)
store i32 %47, i32* %5
br label %60
48: ; preds = %32
%49 = load %struct.katcl_line*, %struct.katcl_line** %6
%50 = load i8*, i8** %12
%51 = call i32 @append_string_katcl(%struct.katcl_line* %49, i32 0, i8* %50)
%52 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 1
store i32 %51, i32* %52
%53 = load %struct.katcl_line*, %struct.katcl_line** %6
%54 = load i8*, i8** %8
%55 = load i32, i32* %9
%56 = call i32 @append_vargs_katcl(%struct.katcl_line* %53, i32 2, i8* %54, i32 %55)
%57 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 2
store i32 %56, i32* %57
%58 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 0
%59 = call i32 @vector_sum(i32* %58, i32 3)
store i32 %59, i32* %5
br label %60
60: ; preds = %48, %41, %29, %21, %15
%61 = load i32, i32* %5
ret i32 %61
}

LLVM IR (-O2):
%struct.katcl_line = type { i32 }
define i32 @vextra_response_katcl(%struct.katcl_line* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [3 x i32]
%6 = bitcast [3 x i32]* %5 to i8*
%7 = icmp sgt i32 %1, 0
br i1 %7, label %31, label %8
8: ; preds = %4
%9 = tail call i8* @arg_copy_string_katcl(%struct.katcl_line* %0, i32 0)
%10 = icmp eq i8* %9, null
br i1 %10, label %31, label %11
11: ; preds = %8
store i8 33, i8* %9
%12 = tail call i8* @code_to_name_katcm(i32 %1)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @free(i8* %9)
br label %31
16: ; preds = %11
%17 = tail call i32 @append_string_katcl(%struct.katcl_line* %0, i32 1, i8* %9)
%18 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
store i32 %17, i32* %18
%19 = tail call i32 @free(i8* %9)
%20 = icmp eq i8* %2, null
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = tail call i32 @append_string_katcl(%struct.katcl_line* %0, i32 2, i8* %12)
%23 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 1
store i32 %22, i32* %23
%24 = call i32 @vector_sum(i32* %18, i32 2)
br label %31
25: ; preds = %16
%26 = tail call i32 @append_string_katcl(%struct.katcl_line* %0, i32 0, i8* %12)
%27 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 1
store i32 %26, i32* %27
%28 = tail call i32 @append_vargs_katcl(%struct.katcl_line* %0, i32 2, i8* %2, i32 %3)
%29 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 2
store i32 %28, i32* %29
%30 = call i32 @vector_sum(i32* %18, i32 3)
br label %31
31: ; preds = %8, %4, %25, %21, %14
%32 = phi i32 [ -1, %14 ], [ %24, %21 ], [ %30, %25 ], [ -1, %4 ], [ -1, %8 ]
ret i32 %32
}