#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 {
  char *description;
  int flags;
  scalar_t__ index;
  int /*<<< orphan*/ pixelformat;
  int /*<<< orphan*/ type;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
scalar_t__ EINVAL;
int /*<<< orphan*/ V4L2_BUF_TYPE_VIDEO_CAPTURE;
int /*<<< orphan*/ VIDIOC_ENUM_FMT;
scalar_t__ errno;
int ioctl(int, int /*<<< orphan*/, struct v4l2_fmtdesc *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ show_resolutions(int, int /*<<< orphan*/);
void show_capture_pixel_formats(int fd) {
  struct v4l2_fmtdesc format = {0};
  format.index = 0;
  format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  printf("Supported V4L2_BUF_TYPE_VIDEO_CAPTURE pixel formats:\n");
  while (ioctl(fd, VIDIOC_ENUM_FMT, &format) != -1) {
    printf("- %.4s: %s, flags: 0x%04x\n", (const char *)&format.pixelformat,
           format.description, format.flags);
    show_resolutions(fd, format.pixelformat);
    format.index++;
  }
  if (errno != EINVAL)
    perror("  ioctl() VIDIOC_ENUM_FMT");
}


x86 assembly (clang, -O0):
<show_capture_pixel_formats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
movq   $0x0,-0x20(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     11e4 <show_capture_pixel_formats+0x94>
lea    -0x30(%rbp),%rsi
add    $0x18,%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%ecx
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1060 <show_resolutions@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    118d <show_capture_pixel_formats+0x3d>
mov    0x2de5(%rip),%rax
mov    (%rax),%rax
mov    0x2dd3(%rip),%rcx
cmp    (%rcx),%rax
je     120a <show_capture_pixel_formats+0xba>
lea    0xe4c(%rip),%rdi
call   1070 <perror@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_capture_pixel_formats>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %edi,%ebx
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movq   $0x0,0x20(%rsp)
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e4c(%rip),%r13
mov    0x0(%r13),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     11f9 <show_capture_pixel_formats+0xa9>
lea    0x18(%rsp),%r14
lea    0xe4d(%rip),%r15
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
mov    (%rsp),%rdx
mov    0x8(%rsp),%ecx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rsp),%esi
mov    %ebx,%edi
call   1060 <show_resolutions@plt>
addq   $0x1,0x10(%rsp)
mov    0x0(%r13),%esi
mov    %ebx,%edi
mov    %r12,%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11c0 <show_capture_pixel_formats+0x70>
mov    0x2dd0(%rip),%rax
mov    (%rax),%rax
mov    0x2dbe(%rip),%rcx
cmp    (%rcx),%rax
jne    121d <show_capture_pixel_formats+0xcd>
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xdf7(%rip),%rdi
call   1070 <perror@plt>
jmp    120f <show_capture_pixel_formats+0xbf>

LLVM IR (-O0):
%struct.v4l2_fmtdesc = type { i8*, i32, i64, i32, i32, i32 }
@V4L2_BUF_TYPE_VIDEO_CAPTURE = global i32 0
@.str = [54 x i8] c"Supported V4L2_BUF_TYPE_VIDEO_CAPTURE pixel formats:\0A\00"
@VIDIOC_ENUM_FMT = global i32 0
@.str.1 = [27 x i8] c"- %.4s: %s, flags: 0x%04x\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.2 = [26 x i8] c" ioctl() VIDIOC_ENUM_FMT\00"
define void @show_capture_pixel_formats(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.v4l2_fmtdesc
store i32 %0, i32* %2
%4 = bitcast %struct.v4l2_fmtdesc* %3 to i8*
%5 = getelementptr inbounds %struct.v4l2_fmtdesc, %struct.v4l2_fmtdesc* %3, i32 0, i32 2
store i64 0, i64* %5
%6 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_CAPTURE
%7 = getelementptr inbounds %struct.v4l2_fmtdesc, %struct.v4l2_fmtdesc* %3, i32 0, i32 4
store i32 %6, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %14, %1
%10 = load i32, i32* %2
%11 = load i32, i32* @VIDIOC_ENUM_FMT
%12 = call i32 @ioctl(i32 %10, i32 %11, %struct.v4l2_fmtdesc* %3)
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %29
14: ; preds = %9
%15 = getelementptr inbounds %struct.v4l2_fmtdesc, %struct.v4l2_fmtdesc* %3, i32 0, i32 3
%16 = bitcast i32* %15 to i8*
%17 = getelementptr inbounds %struct.v4l2_fmtdesc, %struct.v4l2_fmtdesc* %3, i32 0, i32 0
%18 = load i8*, i8** %17
%19 = getelementptr inbounds %struct.v4l2_fmtdesc, %struct.v4l2_fmtdesc* %3, i32 0, i32 1
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %18, i32 %20)
%22 = load i32, i32* %2
%23 = getelementptr inbounds %struct.v4l2_fmtdesc, %struct.v4l2_fmtdesc* %3, i32 0, i32 3
%24 = load i32, i32* %23
%25 = call i32 @show_resolutions(i32 %22, i32 %24)
%26 = getelementptr inbounds %struct.v4l2_fmtdesc, %struct.v4l2_fmtdesc* %3, i32 0, i32 2
%27 = load i64, i64* %26
%28 = add nsw i64 %27, 1
store i64 %28, i64* %26
br label %9
29: ; preds = %9
%30 = load i64, i64* @errno
%31 = load i64, i64* @EINVAL
%32 = icmp ne i64 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %29
ret void
}

LLVM IR (-O2):
%struct.v4l2_fmtdesc = type { i8*, i32, i64, i32, i32, i32 }
@V4L2_BUF_TYPE_VIDEO_CAPTURE = global i32 0
@VIDIOC_ENUM_FMT = global i32 0
@.str.1 = [27 x i8] c"- %.4s: %s, flags: 0x%04x\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.2 = [26 x i8] c" ioctl() VIDIOC_ENUM_FMT\00"
@str = [53 x i8] c"Supported V4L2_BUF_TYPE_VIDEO_CAPTURE pixel formats:\00"
define void @show_capture_pixel_formats(i32 %0) {
%2 = alloca %struct.v4l2_fmtdesc
%3 = bitcast %struct.v4l2_fmtdesc* %2 to i8*
%4 = getelementptr inbounds %struct.v4l2_fmtdesc, %struct.v4l2_fmtdesc* %2, i64 0, i32 2
%5 = bitcast %struct.v4l2_fmtdesc* %2 to i8*
%6 = load i32, i32* @V4L2_BUF_TYPE_VIDEO_CAPTURE
%7 = getelementptr inbounds %struct.v4l2_fmtdesc, %struct.v4l2_fmtdesc* %2, i64 0, i32 4
store i32 %6, i32* %7
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str, i64 0, i64 0))
%9 = load i32, i32* @VIDIOC_ENUM_FMT
%10 = call i32 @ioctl(i32 %0, i32 %9, %struct.v4l2_fmtdesc* %2)
%11 = icmp eq i32 %10, -1
br i1 %11, label %27, label %12
12: ; preds = %1
%13 = getelementptr inbounds %struct.v4l2_fmtdesc, %struct.v4l2_fmtdesc* %2, i64 0, i32 3
%14 = getelementptr inbounds %struct.v4l2_fmtdesc, %struct.v4l2_fmtdesc* %2, i64 0, i32 0
%15 = getelementptr inbounds %struct.v4l2_fmtdesc, %struct.v4l2_fmtdesc* %2, i64 0, i32 1
br label %16
16: ; preds = %12, %16
%17 = load i8*, i8** %14
%18 = load i32, i32* %15
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32* %13, i8* %17, i32 %18)
%20 = load i32, i32* %13
%21 = call i32 @show_resolutions(i32 %0, i32 %20)
%22 = load i64, i64* %4
%23 = add nsw i64 %22, 1
store i64 %23, i64* %4
%24 = load i32, i32* @VIDIOC_ENUM_FMT
%25 = call i32 @ioctl(i32 %0, i32 %24, %struct.v4l2_fmtdesc* %2)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %16
27: ; preds = %16, %1
%28 = load i64, i64* @errno
%29 = load i64, i64* @EINVAL
%30 = icmp eq i64 %28, %29
br i1 %30, label %33, label %31
31: ; preds = %27
%32 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
ret void
}