#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 v4l2_fmtdesc {
  int /*<<< orphan*/ pixelformat;
};

/* Variables and functions */
int /*<<< orphan*/ V4L2_BUF_TYPE_VIDEO_CAPTURE;
int enum_pixel_formats(int, int /*<<< orphan*/, struct v4l2_fmtdesc **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(struct v4l2_fmtdesc *);
char *pix_fmt_to_str(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
void print_pixel_formats(int fd) {
  struct v4l2_fmtdesc *format = NULL;
  int fmt_cnt = enum_pixel_formats(fd, V4L2_BUF_TYPE_VIDEO_CAPTURE, &format);
  if (fmt_cnt < -1) {
    fprintf(stderr, "Unable to enumerate video capture formats\n");
    return;
  }
  fprintf(
      stdout,
      "No/invalid pixel format specified! Please select from the following:\n");
  for (int i = 0; i < fmt_cnt; i++) {
    fprintf(stdout, "%s\n", pix_fmt_to_str(format[i].pixelformat));
  }
  free(format);
  format = NULL;
}


x86 assembly (clang, -O0):
<print_pixel_formats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <enum_pixel_formats@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jge    1191 <print_pixel_formats+0x51>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    120a <print_pixel_formats+0xca>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f9 <print_pixel_formats+0xb9>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1050 <pix_fmt_to_str@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe8d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11af <print_pixel_formats+0x6f>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_pixel_formats>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1040 <enum_pixel_formats@plt>
cmp    $0xfffffffe,%eax
jg     1186 <print_pixel_formats+0x46>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11e2 <print_pixel_formats+0xa2>
mov    %eax,%ebx
mov    0x2e41(%rip),%r14
mov    (%r14),%edi
lea    0xe92(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %ebx,%ebx
jle    11d8 <print_pixel_formats+0x98>
mov    %ebx,%r12d
lea    0xec3(%rip),%r15
xor    %ebx,%ebx
mov    (%r14),%ebp
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,4),%edi
call   1050 <pix_fmt_to_str@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11b0 <print_pixel_formats+0x70>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.v4l2_fmtdesc = type { i32 }
@V4L2_BUF_TYPE_VIDEO_CAPTURE = global i32 0
@stderr = global i32 0
@.str = [43 x i8] c"Unable to enumerate video capture formats\0A\00"
@stdout = global i32 0
@.str.1 = [70 x i8] c"No/invalid pixel format specified! Please select from the following:\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @print_pixel_formats(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.v4l2_fmtdesc*
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store %struct.v4l2_fmtdesc* null, %struct.v4l2_fmtdesc** %3
%6 = load i32, i32* %2
%7 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_CAPTURE
%8 = call i32 @enum_pixel_formats(i32 %6, i32 %7, %struct.v4l2_fmtdesc** %3)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
br label %37
14: ; preds = %1
%15 = load i32, i32* @stdout
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
br label %17
17: ; preds = %31, %14
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %34
21: ; preds = %17
%22 = load i32, i32* @stdout
%23 = load %struct.v4l2_fmtdesc*, %struct.v4l2_fmtdesc** %3
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds %struct.v4l2_fmtdesc, %struct.v4l2_fmtdesc* %23, i64 %25
%27 = getelementptr inbounds %struct.v4l2_fmtdesc, %struct.v4l2_fmtdesc* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i8* @pix_fmt_to_str(i32 %28)
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %21
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %17
34: ; preds = %17
%35 = load %struct.v4l2_fmtdesc*, %struct.v4l2_fmtdesc** %3
%36 = call i32 @free(%struct.v4l2_fmtdesc* %35)
store %struct.v4l2_fmtdesc* null, %struct.v4l2_fmtdesc** %3
br label %37
37: ; preds = %34, %11
ret void
}

LLVM IR (-O2):
%struct.v4l2_fmtdesc = type { i32 }
@V4L2_BUF_TYPE_VIDEO_CAPTURE = global i32 0
@stderr = global i32 0
@.str = [43 x i8] c"Unable to enumerate video capture formats\0A\00"
@stdout = global i32 0
@.str.1 = [70 x i8] c"No/invalid pixel format specified! Please select from the following:\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @print_pixel_formats(i32 %0) {
%2 = alloca %struct.v4l2_fmtdesc*
%3 = bitcast %struct.v4l2_fmtdesc** %2 to i8*
store %struct.v4l2_fmtdesc* null, %struct.v4l2_fmtdesc** %2
%4 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_CAPTURE
%5 = call i32 @enum_pixel_formats(i32 %0, i32 %4, %struct.v4l2_fmtdesc** %2)
%6 = icmp slt i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
br label %29
10: ; preds = %1
%11 = load i32, i32* @stdout
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp sgt i32 %5, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = zext i32 %5 to i64
br label %19
16: ; preds = %19, %10
%17 = load %struct.v4l2_fmtdesc*, %struct.v4l2_fmtdesc** %2
%18 = call i32 @free(%struct.v4l2_fmtdesc* %17)
br label %29
19: ; preds = %14, %19
%20 = phi i64 [ 0, %14 ], [ %27, %19 ]
%21 = load i32, i32* @stdout
%22 = load %struct.v4l2_fmtdesc*, %struct.v4l2_fmtdesc** %2
%23 = getelementptr inbounds %struct.v4l2_fmtdesc, %struct.v4l2_fmtdesc* %22, i64 %20, i32 0
%24 = load i32, i32* %23
%25 = call i8* @pix_fmt_to_str(i32 %24)
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = add nuw nsw i64 %20, 1
%28 = icmp eq i64 %27, %15
br i1 %28, label %16, label %19
29: ; preds = %16, %7
ret void
}