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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int get_cea861_modes(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
bool show_cea861_modes(void) {
  int modes[64];
  int res = get_cea861_modes(modes, (sizeof(modes) / sizeof((modes)[0])));
  if (res < 0) {
    fprintf(stderr,
            "ERROR: Cannot determine available CEA-861 display modes\n");
    return false;
  }
  printf("Available CEA-861 display modes: ");
  for (int i = 0; i < res; i++)
    printf("%d%s", modes[i], i < (res - 1) ? ", " : "\n");
  return true;
}


x86 assembly (clang, -O0):
<show_cea861_modes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    -0x110(%rbp),%rdi
mov    $0x40,%esi
call   1040 <get_cea861_modes@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jge    1180 <show_cea861_modes+0x50>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1204 <show_cea861_modes+0xd4>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x118(%rbp)
mov    -0x118(%rbp),%eax
cmp    -0x114(%rbp),%eax
jge    11fd <show_cea861_modes+0xcd>
movslq -0x118(%rbp),%rax
mov    -0x110(%rbp,%rax,4),%esi
mov    -0x118(%rbp),%ecx
mov    -0x114(%rbp),%edi
sub    $0x1,%edi
lea    0xe69(%rip),%rdx
lea    0xe8b(%rip),%rax
cmp    %edi,%ecx
cmovl  %rax,%rdx
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
jmp    1198 <show_cea861_modes+0x68>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_cea861_modes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsp,%rdi
mov    $0x40,%esi
call   1040 <get_cea861_modes@plt>
test   %eax,%eax
js     11b8 <show_cea861_modes+0x88>
mov    %eax,%ebx
lea    0xede(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%eax
test   %ebx,%ebx
je     11cf <show_cea861_modes+0x9f>
lea    -0x1(%rbx),%ebp
mov    %ebx,%ebx
lea    0xee9(%rip),%r12
lea    0xeb9(%rip),%r13
lea    0xed6(%rip),%r15
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
mov    (%rsp,%r14,4),%esi
cmp    %rbp,%r14
mov    %r13,%rdx
cmovb  %r12,%rdx
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%r14
cmp    %r14,%rbx
jne    1190 <show_cea861_modes+0x60>
mov    $0x1,%eax
jmp    11cf <show_cea861_modes+0x9f>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [57 x i8] c"ERROR: Cannot determine available CEA-861 display modes\0A\00"
@.str.1 = [34 x i8] c"Available CEA-861 display modes: \00"
@.str.2 = [5 x i8] c"%d%s\00"
@.str.3 = [3 x i8] c", \00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @show_cea861_modes() {
%1 = alloca i32
%2 = alloca [64 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [64 x i32], [64 x i32]* %2, i64 0, i64 0
%6 = call i32 @get_cea861_modes(i32* %5, i32 64)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %34
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %14
14: ; preds = %30, %12
%15 = load i32, i32* %4
%16 = load i32, i32* %3
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %33
18: ; preds = %14
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [64 x i32], [64 x i32]* %2, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = load i32, i32* %4
%24 = load i32, i32* %3
%25 = sub nsw i32 %24, 1
%26 = icmp slt i32 %23, %25
%27 = zext i1 %26 to i64
%28 = select i1 %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %22, i8* %28)
br label %30
30: ; preds = %18
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %14
33: ; preds = %14
store i32 1, i32* %1
br label %34
34: ; preds = %33, %9
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [57 x i8] c"ERROR: Cannot determine available CEA-861 display modes\0A\00"
@.str.1 = [34 x i8] c"Available CEA-861 display modes: \00"
@.str.2 = [5 x i8] c"%d%s\00"
@.str.3 = [3 x i8] c", \00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @show_cea861_modes() {
%1 = alloca [64 x i32]
%2 = bitcast [64 x i32]* %1 to i8*
%3 = getelementptr inbounds [64 x i32], [64 x i32]* %1, i64 0, i64 0
%4 = call i32 @get_cea861_modes(i32* %3, i32 64)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
br label %25
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32 %4, 0
br i1 %11, label %25, label %12
12: ; preds = %9
%13 = add nsw i32 %4, -1
%14 = zext i32 %13 to i64
%15 = zext i32 %4 to i64
br label %16
16: ; preds = %12, %16
%17 = phi i64 [ 0, %12 ], [ %23, %16 ]
%18 = getelementptr inbounds [64 x i32], [64 x i32]* %1, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = icmp ult i64 %17, %14
%21 = select i1 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %19, i8* %21)
%23 = add nuw nsw i64 %17, 1
%24 = icmp eq i64 %23, %15
br i1 %24, label %25, label %16
25: ; preds = %16, %9, %6
%26 = phi i32 [ 0, %6 ], [ 1, %9 ], [ 1, %16 ]
ret i32 %26
}