#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 const *tvtime_get_command(int);
int tvtime_get_command_id(int);
int tvtime_num_commands();
const char *tvtime_command_to_string(int command) {
  int i;
  for (i = 0; i < tvtime_num_commands(); i++) {
    if (tvtime_get_command_id(i) == command) {
      return tvtime_get_command(i);
    }
  }
  return "ERROR";
}


x86 assembly (clang, -O0):
<tvtime_command_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1040 <tvtime_num_commands@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    1191 <tvtime_command_to_string+0x61>
mov    -0x10(%rbp),%edi
call   1050 <tvtime_get_command_id@plt>
cmp    -0xc(%rbp),%eax
jne    117e <tvtime_command_to_string+0x4e>
mov    -0x10(%rbp),%edi
call   1030 <tvtime_get_command@plt>
mov    %rax,-0x8(%rbp)
jmp    119c <tvtime_command_to_string+0x6c>
jmp    1183 <tvtime_command_to_string+0x53>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1142 <tvtime_command_to_string+0x12>
lea    0xe68(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tvtime_command_to_string>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1040 <tvtime_num_commands@plt>
test   %eax,%eax
jle    1169 <tvtime_command_to_string+0x39>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
call   1050 <tvtime_get_command_id@plt>
cmp    %ebx,%eax
je     1177 <tvtime_command_to_string+0x47>
add    $0x1,%ebp
xor    %eax,%eax
call   1040 <tvtime_num_commands@plt>
cmp    %eax,%ebp
jl     1150 <tvtime_command_to_string+0x20>
lea    0xe90(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <tvtime_get_command@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"ERROR\00"
define i8* @tvtime_command_to_string(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %18, %1
%6 = load i32, i32* %4
%7 = call i32 (...) @tvtime_num_commands()
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %21
9: ; preds = %5
%10 = load i32, i32* %4
%11 = call i32 @tvtime_get_command_id(i32 %10)
%12 = load i32, i32* %3
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* %4
%16 = call i8* @tvtime_get_command(i32 %15)
store i8* %16, i8** %2
br label %22
17: ; preds = %9
br label %18
18: ; preds = %17
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %5
21: ; preds = %5
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %2
br label %22
22: ; preds = %21, %14
%23 = load i8*, i8** %2
ret i8* %23
}

LLVM IR (-O2):
@.str = [6 x i8] c"ERROR\00"
define i8* @tvtime_command_to_string(i32 %0) {
%2 = tail call i32 (...) @tvtime_num_commands()
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %14
4: ; preds = %1, %10
%5 = phi i32 [ %11, %10 ], [ 0, %1 ]
%6 = tail call i32 @tvtime_get_command_id(i32 %5)
%7 = icmp eq i32 %6, %0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i8* @tvtime_get_command(i32 %5)
br label %14
10: ; preds = %4
%11 = add nuw nsw i32 %5, 1
%12 = tail call i32 (...) @tvtime_num_commands()
%13 = icmp slt i32 %11, %12
br i1 %13, label %4, label %14
14: ; preds = %10, %1, %8
%15 = phi i8* [ %9, %8 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %10 ]
ret i8* %15
}