#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 add_string_parse_katcl(struct katcl_parse *, int, char *);
int add_timestamp_parse_katcl(struct katcl_parse *, int /*<<< orphan*/,
                              int /*<<< orphan*/ *);
int add_vargs_parse_katcl(struct katcl_parse *, int, char *,
                          int /*<<< orphan*/);
char *log_to_string_katcl(int);
int vector_sum(int *, int);
int vlog_parse_katcl(struct katcl_parse *px, int level, char *name, char *fmt,
                     va_list args) {
  int result[5];
  char *subsystem, *logstring;
  if ((level >= 6) || (level < 0)) {
    return -1;
  }
  logstring = log_to_string_katcl(level);
  if (logstring == NULL) {
    return -1;
  }
  subsystem = name ? name : "unknown";
  result[0] = add_string_parse_katcl(px, 0x01, "#log");
  result[1] = add_string_parse_katcl(px, 0, logstring);
  result[2] = add_timestamp_parse_katcl(px, 0, NULL);
  result[3] = add_string_parse_katcl(px, 0, subsystem);
  result[4] = add_vargs_parse_katcl(px, 0x02, fmt, args);
  return vector_sum(result, 5);
}


x86 assembly (clang, -O0):
<vlog_parse_katcl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
cmpl   $0x6,-0x14(%rbp)
jge    117f <vlog_parse_katcl+0x2f>
cmpl   $0x0,-0x14(%rbp)
jge    118b <vlog_parse_katcl+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1255 <vlog_parse_katcl+0x105>
mov    -0x14(%rbp),%edi
call   1050 <log_to_string_katcl@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    11ae <vlog_parse_katcl+0x5e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1255 <vlog_parse_katcl+0x105>
cmpq   $0x0,-0x20(%rbp)
je     11c6 <vlog_parse_katcl+0x76>
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
jmp    11d6 <vlog_parse_katcl+0x86>
lea    0xe33(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    11d6 <vlog_parse_katcl+0x86>
mov    -0x58(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
lea    0xe1a(%rip),%rdx
call   1030 <add_string_parse_katcl@plt>
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x50(%rbp),%rdx
xor    %esi,%esi
call   1030 <add_string_parse_katcl@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <add_timestamp_parse_katcl@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rdx
xor    %esi,%esi
call   1030 <add_string_parse_katcl@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    $0x2,%esi
call   1040 <add_vargs_parse_katcl@plt>
mov    %eax,-0x30(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x5,%esi
call   1060 <vector_sum@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vlog_parse_katcl>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0xffffffff,%ebp
cmp    $0x5,%esi
ja     120a <vlog_parse_katcl+0xba>
mov    %r8d,%r12d
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rdi,%r14
mov    %esi,%edi
call   1050 <log_to_string_katcl@plt>
test   %rax,%rax
je     120a <vlog_parse_katcl+0xba>
mov    %rax,%r13
test   %rbx,%rbx
mov    %r12d,%ebp
lea    0xe68(%rip),%r12
cmovne %rbx,%r12
lea    0xe65(%rip),%rdx
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <add_string_parse_katcl@plt>
mov    %eax,(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
mov    %r13,%rdx
call   1030 <add_string_parse_katcl@plt>
mov    %eax,0x4(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <add_timestamp_parse_katcl@plt>
mov    %eax,0x8(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1030 <add_string_parse_katcl@plt>
mov    %eax,0xc(%rsp)
mov    %r14,%rdi
mov    $0x2,%esi
mov    %r15,%rdx
mov    %ebp,%ecx
call   1040 <add_vargs_parse_katcl@plt>
mov    %eax,0x10(%rsp)
mov    %rsp,%rdi
mov    $0x5,%esi
call   1060 <vector_sum@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.katcl_parse = type { i32 }
@.str = [8 x i8] c"unknown\00"
@.str.1 = [5 x i8] c"#log\00"
define i32 @vlog_parse_katcl(%struct.katcl_parse* %0, i32 %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca [5 x i32]
%7 = bitcast [5 x i32]* %6 to i8*
%8 = icmp ugt i32 %1, 5
br i1 %8, label %26, label %9
9: ; preds = %5
%10 = tail call i8* @log_to_string_katcl(i32 %1)
%11 = icmp eq i8* %10, null
br i1 %11, label %26, label %12
12: ; preds = %9
%13 = icmp eq i8* %2, null
%14 = select i1 %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %2
%15 = tail call i32 @add_string_parse_katcl(%struct.katcl_parse* %0, i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 0
store i32 %15, i32* %16
%17 = tail call i32 @add_string_parse_katcl(%struct.katcl_parse* %0, i32 0, i8* %10)
%18 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 1
store i32 %17, i32* %18
%19 = tail call i32 @add_timestamp_parse_katcl(%struct.katcl_parse* %0, i32 0, i32* null)
%20 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 2
store i32 %19, i32* %20
%21 = tail call i32 @add_string_parse_katcl(%struct.katcl_parse* %0, i32 0, i8* %14)
%22 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 3
store i32 %21, i32* %22
%23 = tail call i32 @add_vargs_parse_katcl(%struct.katcl_parse* %0, i32 2, i8* %3, i32 %4)
%24 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 4
store i32 %23, i32* %24
%25 = call i32 @vector_sum(i32* %16, i32 5)
br label %26
26: ; preds = %9, %5, %12
%27 = phi i32 [ %25, %12 ], [ -1, %5 ], [ -1, %9 ]
ret i32 %27
}