int cmd_test(struct cli_def *cli, char *command, char *argv[], int argc) {
  int i;
  cli_print(cli, "called %s with \"%s\"", __FUNCTION__, command);
  cli_print(cli, "%d arguments:", argc);
  for (i = 0; i < argc; i++)
    cli_print(cli, "        %s", argv[i]);
  return 0;
}


x86 assembly (clang, -O0):
<cmd_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rcx
lea    0xeca(%rip),%rsi
lea    0xed7(%rip),%rdx
mov    $0x0,%al
call   1030 <cli_print@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xecb(%rip),%rsi
mov    $0x0,%al
call   1030 <cli_print@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1198 <cmd_test+0x88>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xea8(%rip),%rsi
mov    $0x0,%al
call   1030 <cli_print@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1160 <cmd_test+0x50>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_test>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%rcx
mov    %rdi,%r12
lea    0xed6(%rip),%rsi
lea    0xee3(%rip),%rdx
xor    %eax,%eax
call   1030 <cli_print@plt>
lea    0xede(%rip),%rsi
mov    %r12,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <cli_print@plt>
test   %ebp,%ebp
jle    117a <cmd_test+0x6a>
mov    %ebp,%ebp
lea    0xed3(%rip),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <cli_print@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <cmd_test+0x50>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.cli_def = type opaque
@.str = [20 x i8] c"called %s with \22%s\22\00"
@__FUNCTION__.cmd_test = [9 x i8] c"cmd_test\00"
@.str.1 = [14 x i8] c"%d arguments:\00"
@.str.2 = [11 x i8] c" %s\00"
define i32 @cmd_test(%struct.cli_def* %0, i8* %1, i8** %2, i32 %3) {
%5 = alloca %struct.cli_def*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
store %struct.cli_def* %0, %struct.cli_def** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
store i32 %3, i32* %8
%10 = load %struct.cli_def*, %struct.cli_def** %5
%11 = load i8*, i8** %6
%12 = call i32 (%struct.cli_def*, i8*, i8*, i8*, ...) bitcast (i32 (...)* @cli_print to i32 (%struct.cli_def*, i8*, i8*, i8*, ...)*)(%struct.cli_def* %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__FUNCTION__.cmd_test, i64 0, i64 0), i8* %11)
%13 = load %struct.cli_def*, %struct.cli_def** %5
%14 = load i32, i32* %8
%15 = call i32 (%struct.cli_def*, i8*, i32, ...) bitcast (i32 (...)* @cli_print to i32 (%struct.cli_def*, i8*, i32, ...)*)(%struct.cli_def* %13, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %14)
store i32 0, i32* %9
br label %16
16: ; preds = %28, %4
%17 = load i32, i32* %9
%18 = load i32, i32* %8
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %31
20: ; preds = %16
%21 = load %struct.cli_def*, %struct.cli_def** %5
%22 = load i8**, i8*** %7
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 (%struct.cli_def*, i8*, i8*, ...) bitcast (i32 (...)* @cli_print to i32 (%struct.cli_def*, i8*, i8*, ...)*)(%struct.cli_def* %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %20
%29 = load i32, i32* %9
%30 = add nsw i32 %29, 1
store i32 %30, i32* %9
br label %16
31: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
%struct.cli_def = type opaque
@.str = [20 x i8] c"called %s with \22%s\22\00"
@__FUNCTION__.cmd_test = [9 x i8] c"cmd_test\00"
@.str.1 = [14 x i8] c"%d arguments:\00"
@.str.2 = [11 x i8] c" %s\00"
define i32 @cmd_test(%struct.cli_def* %0, i8* %1, i8** nocapture %2, i32 %3) {
%5 = tail call i32 (%struct.cli_def*, i8*, i8*, i8*, ...) bitcast (i32 (...)* @cli_print to i32 (%struct.cli_def*, i8*, i8*, i8*, ...)*)(%struct.cli_def* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__FUNCTION__.cmd_test, i64 0, i64 0), i8* %1)
%6 = tail call i32 (%struct.cli_def*, i8*, i32, ...) bitcast (i32 (...)* @cli_print to i32 (%struct.cli_def*, i8*, i32, ...)*)(%struct.cli_def* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %17
8: ; preds = %4
%9 = zext i32 %3 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %15, %10 ]
%12 = getelementptr inbounds i8*, i8** %2, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i32 (%struct.cli_def*, i8*, i8*, ...) bitcast (i32 (...)* @cli_print to i32 (%struct.cli_def*, i8*, i8*, ...)*)(%struct.cli_def* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, %9
br i1 %16, label %17, label %10
17: ; preds = %10, %4
ret i32 0
}