#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 */

/* Variables and functions */
char *pios_fbconsole_getCommand(int);
int pios_fbconsole_getCommandCount();
int /*<<< orphan*/ pios_fbconsole_write(char *);
int listCommands(int argc, char **argv) {
  pios_fbconsole_write("Available commands: \n");
  for (int i = 0; i < pios_fbconsole_getCommandCount(); i += 2) {
    pios_fbconsole_write(" -- ");
    pios_fbconsole_write(pios_fbconsole_getCommand(i));
    if (i + 1 < pios_fbconsole_getCommandCount()) {
      pios_fbconsole_write("    -- ");
      pios_fbconsole_write(pios_fbconsole_getCommand(i + 1));
    }
    pios_fbconsole_write("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<listCommands>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <pios_fbconsole_write@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <pios_fbconsole_getCommandCount@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    11de <listCommands+0xae>
lea    0xea6(%rip),%rdi
call   1030 <pios_fbconsole_write@plt>
mov    -0x14(%rbp),%edi
call   1040 <pios_fbconsole_getCommand@plt>
mov    %rax,%rdi
call   1030 <pios_fbconsole_write@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1050 <pios_fbconsole_getCommandCount@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11c4 <listCommands+0x94>
lea    0xe6a(%rip),%rdi
call   1030 <pios_fbconsole_write@plt>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1040 <pios_fbconsole_getCommand@plt>
mov    %rax,%rdi
call   1030 <pios_fbconsole_write@plt>
lea    0xe49(%rip),%rdi
call   1030 <pios_fbconsole_write@plt>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    1152 <listCommands+0x22>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listCommands>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xec1(%rip),%rdi
call   1030 <pios_fbconsole_write@plt>
xor    %eax,%eax
call   1050 <pios_fbconsole_getCommandCount@plt>
test   %eax,%eax
jle    11c4 <listCommands+0x94>
lea    0xec3(%rip),%r15
lea    0xeb9(%rip),%r14
lea    0xeb0(%rip),%r12
xor    %ebx,%ebx
jmp    1186 <listCommands+0x56>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <pios_fbconsole_write@plt>
add    $0x2,%ebx
xor    %eax,%eax
call   1050 <pios_fbconsole_getCommandCount@plt>
cmp    %eax,%ebx
jge    11c4 <listCommands+0x94>
mov    %r15,%rdi
call   1030 <pios_fbconsole_write@plt>
mov    %ebx,%edi
call   1040 <pios_fbconsole_getCommand@plt>
mov    %rax,%rdi
call   1030 <pios_fbconsole_write@plt>
lea    0x1(%rbx),%ebp
xor    %eax,%eax
call   1050 <pios_fbconsole_getCommandCount@plt>
cmp    %eax,%ebp
jge    1170 <listCommands+0x40>
mov    %r14,%rdi
call   1030 <pios_fbconsole_write@plt>
mov    %ebp,%edi
call   1040 <pios_fbconsole_getCommand@plt>
mov    %rax,%rdi
call   1030 <pios_fbconsole_write@plt>
jmp    1170 <listCommands+0x40>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Available commands: \0A\00"
@.str.1 = [5 x i8] c" -- \00"
@.str.2 = [8 x i8] c" -- \00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @listCommands(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%6 = call i32 @pios_fbconsole_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %7
7: ; preds = %28, %2
%8 = load i32, i32* %5
%9 = call i32 (...) @pios_fbconsole_getCommandCount()
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %31
11: ; preds = %7
%12 = call i32 @pios_fbconsole_write(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* %5
%14 = call i8* @pios_fbconsole_getCommand(i32 %13)
%15 = call i32 @pios_fbconsole_write(i8* %14)
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
%18 = call i32 (...) @pios_fbconsole_getCommandCount()
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %26
20: ; preds = %11
%21 = call i32 @pios_fbconsole_write(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
%24 = call i8* @pios_fbconsole_getCommand(i32 %23)
%25 = call i32 @pios_fbconsole_write(i8* %24)
br label %26
26: ; preds = %20, %11
%27 = call i32 @pios_fbconsole_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 2
store i32 %30, i32* %5
br label %7
31: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Available commands: \0A\00"
@.str.1 = [5 x i8] c" -- \00"
@.str.2 = [8 x i8] c" -- \00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @listCommands(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @pios_fbconsole_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (...) @pios_fbconsole_getCommandCount()
%5 = icmp sgt i32 %4, 0
br i1 %5, label %7, label %6
6: ; preds = %19, %2
ret i32 0
7: ; preds = %2, %19
%8 = phi i32 [ %21, %19 ], [ 0, %2 ]
%9 = tail call i32 @pios_fbconsole_write(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i8* @pios_fbconsole_getCommand(i32 %8)
%11 = tail call i32 @pios_fbconsole_write(i8* %10)
%12 = or i32 %8, 1
%13 = tail call i32 (...) @pios_fbconsole_getCommandCount()
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %7
%16 = tail call i32 @pios_fbconsole_write(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i8* @pios_fbconsole_getCommand(i32 %12)
%18 = tail call i32 @pios_fbconsole_write(i8* %17)
br label %19
19: ; preds = %15, %7
%20 = tail call i32 @pios_fbconsole_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = add nuw nsw i32 %8, 2
%22 = tail call i32 (...) @pios_fbconsole_getCommandCount()
%23 = icmp slt i32 %21, %22
br i1 %23, label %7, label %6
}