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

/* Variables and functions */
char *arg_string_katcp(struct katcp_dispatch *, int);
int /*<<< orphan*/ log_message_katcp(struct katcp_dispatch *, int,
                                     int /*<<< orphan*/ *, char *, ...);
int log_to_code_katcl(char *);
int log_record_cmd_katcp(struct katcp_dispatch *d, int argc) {
  int code;
  char *message, *level;
  code = 2;
  if (argc > 2) {
    message = arg_string_katcp(d, 2);
    level = arg_string_katcp(d, 1);
    if (level) {
      code = log_to_code_katcl(level);
      if (code < 0) {
        code = 2;
      }
    }
  } else if (argc > 1) {
    message = arg_string_katcp(d, 1);
  } else {
    log_message_katcp(d, 4, NULL, "require a message to log");
    return (-1);
  }
  if (message == NULL) {
    log_message_katcp(d, 5, NULL, "unable to acquire message");
    return (-1);
  }
  log_message_katcp(d, code, NULL, "%s", message);
  return 0;
}


x86 assembly (clang, -O0):
<log_record_cmd_katcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x2,-0x18(%rbp)
cmpl   $0x2,-0x14(%rbp)
jle    11a6 <log_record_cmd_katcp+0x76>
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
call   1040 <arg_string_katcp@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1040 <arg_string_katcp@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11a1 <log_record_cmd_katcp+0x71>
mov    -0x28(%rbp),%rdi
call   1030 <log_to_code_katcl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    119c <log_record_cmd_katcp+0x6c>
movl   $0x2,-0x18(%rbp)
jmp    11a1 <log_record_cmd_katcp+0x71>
jmp    11f3 <log_record_cmd_katcp+0xc3>
cmpl   $0x1,-0x14(%rbp)
jle    11c7 <log_record_cmd_katcp+0x97>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1040 <arg_string_katcp@plt>
mov    %rax,-0x20(%rbp)
jmp    11ee <log_record_cmd_katcp+0xbe>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    0xe25(%rip),%rcx
mov    $0x0,%al
call   1050 <log_message_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1249 <log_record_cmd_katcp+0x119>
jmp    11f3 <log_record_cmd_katcp+0xc3>
cmpq   $0x0,-0x20(%rbp)
jne    1225 <log_record_cmd_katcp+0xf5>
mov    -0x10(%rbp),%rdi
mov    $0x5,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    0xe07(%rip),%rcx
mov    $0x0,%al
call   1050 <log_message_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1249 <log_record_cmd_katcp+0x119>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%r8
xor    %eax,%eax
mov    %eax,%edx
lea    0xdf8(%rip),%rcx
mov    $0x0,%al
call   1050 <log_message_katcp@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_record_cmd_katcp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
cmp    $0x3,%esi
jl     1199 <log_record_cmd_katcp+0x69>
mov    $0x2,%ebp
mov    %r15,%rdi
mov    $0x2,%esi
call   1040 <arg_string_katcp@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    $0x1,%esi
call   1040 <arg_string_katcp@plt>
test   %rax,%rax
je     1178 <log_record_cmd_katcp+0x48>
mov    %rax,%rdi
call   1030 <log_to_code_katcl@plt>
test   %eax,%eax
mov    $0x2,%ebp
cmovns %eax,%ebp
test   %r14,%r14
je     11b8 <log_record_cmd_katcp+0x88>
lea    0xeaf(%rip),%rcx
xor    %ebx,%ebx
mov    %r15,%rdi
mov    %ebp,%esi
xor    %edx,%edx
mov    %r14,%r8
xor    %eax,%eax
call   1050 <log_message_katcp@plt>
jmp    11e6 <log_record_cmd_katcp+0xb6>
cmp    $0x2,%esi
jne    11c9 <log_record_cmd_katcp+0x99>
mov    %r15,%rdi
mov    $0x1,%esi
call   1040 <arg_string_katcp@plt>
mov    %rax,%r14
mov    $0x2,%ebp
test   %r14,%r14
jne    117d <log_record_cmd_katcp+0x4d>
lea    0xe5a(%rip),%rcx
mov    %r15,%rdi
mov    $0x5,%esi
jmp    11d8 <log_record_cmd_katcp+0xa8>
lea    0xe30(%rip),%rcx
mov    %r15,%rdi
mov    $0x4,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <log_message_katcp@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.katcp_dispatch = type { i32 }
@.str = [25 x i8] c"require a message to log\00"
@.str.1 = [26 x i8] c"unable to acquire message\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @log_record_cmd_katcp(%struct.katcp_dispatch* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.katcp_dispatch*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store %struct.katcp_dispatch* %0, %struct.katcp_dispatch** %4
store i32 %1, i32* %5
store i32 2, i32* %6
%9 = load i32, i32* %5
%10 = icmp sgt i32 %9, 2
br i1 %10, label %11, label %26
11: ; preds = %2
%12 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%13 = call i8* @arg_string_katcp(%struct.katcp_dispatch* %12, i32 2)
store i8* %13, i8** %7
%14 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%15 = call i8* @arg_string_katcp(%struct.katcp_dispatch* %14, i32 1)
store i8* %15, i8** %8
%16 = load i8*, i8** %8
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %25
18: ; preds = %11
%19 = load i8*, i8** %8
%20 = call i32 @log_to_code_katcl(i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 2, i32* %6
br label %24
24: ; preds = %23, %18
br label %25
25: ; preds = %24, %11
br label %36
26: ; preds = %2
%27 = load i32, i32* %5
%28 = icmp sgt i32 %27, 1
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%31 = call i8* @arg_string_katcp(%struct.katcp_dispatch* %30, i32 1)
store i8* %31, i8** %7
br label %35
32: ; preds = %26
%33 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%34 = call i32 (%struct.katcp_dispatch*, i32, i32*, i8*, ...) @log_message_katcp(%struct.katcp_dispatch* %33, i32 4, i32* null, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %47
35: ; preds = %29
br label %36
36: ; preds = %35, %25
%37 = load i8*, i8** %7
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%41 = call i32 (%struct.katcp_dispatch*, i32, i32*, i8*, ...) @log_message_katcp(%struct.katcp_dispatch* %40, i32 5, i32* null, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %47
42: ; preds = %36
%43 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%44 = load i32, i32* %6
%45 = load i8*, i8** %7
%46 = call i32 (%struct.katcp_dispatch*, i32, i32*, i8*, ...) @log_message_katcp(%struct.katcp_dispatch* %43, i32 %44, i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %45)
store i32 0, i32* %3
br label %47
47: ; preds = %42, %39, %32
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
%struct.katcp_dispatch = type { i32 }
@.str = [25 x i8] c"require a message to log\00"
@.str.1 = [26 x i8] c"unable to acquire message\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @log_record_cmd_katcp(%struct.katcp_dispatch* %0, i32 %1) {
%3 = icmp sgt i32 %1, 2
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = tail call i8* @arg_string_katcp(%struct.katcp_dispatch* %0, i32 2)
%6 = tail call i8* @arg_string_katcp(%struct.katcp_dispatch* %0, i32 1)
%7 = icmp eq i8* %6, null
br i1 %7, label %18, label %8
8: ; preds = %4
%9 = tail call i32 @log_to_code_katcl(i8* %6)
%10 = icmp slt i32 %9, 0
%11 = select i1 %10, i32 2, i32 %9
br label %18
12: ; preds = %2
%13 = icmp eq i32 %1, 2
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = tail call i8* @arg_string_katcp(%struct.katcp_dispatch* %0, i32 1)
br label %18
16: ; preds = %12
%17 = tail call i32 (%struct.katcp_dispatch*, i32, i32*, i8*, ...) @log_message_katcp(%struct.katcp_dispatch* %0, i32 4, i32* null, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %26
18: ; preds = %4, %8, %14
%19 = phi i32 [ %11, %8 ], [ 2, %4 ], [ 2, %14 ]
%20 = phi i8* [ %5, %8 ], [ %5, %4 ], [ %15, %14 ]
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 (%struct.katcp_dispatch*, i32, i32*, i8*, ...) @log_message_katcp(%struct.katcp_dispatch* %0, i32 5, i32* null, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %26
24: ; preds = %18
%25 = tail call i32 (%struct.katcp_dispatch*, i32, i32*, i8*, ...) @log_message_katcp(%struct.katcp_dispatch* %0, i32 %19, i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %26
26: ; preds = %24, %22, %16
%27 = phi i32 [ -1, %22 ], [ 0, %24 ], [ -1, %16 ]
ret i32 %27
}