#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ uint32_t;
struct TYPE_2__ {
  int width;
  int height;
};
struct v4l2_frmsizeenum {
  scalar_t__ type;
  scalar_t__ index;
  TYPE_1__ discrete;
  int /*<<< orphan*/ pixel_format;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
scalar_t__ EINVAL;
scalar_t__ V4L2_FRMSIZE_TYPE_DISCRETE;
int /*<<< orphan*/ VIDIOC_ENUM_FRAMESIZES;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int ioctl(int, int /*<<< orphan*/, struct v4l2_frmsizeenum *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ show_resolution_frame_rates(int, int /*<<< orphan*/, int,
                                               int);
int /*<<< orphan*/ stderr;
void show_resolutions(int fd, uint32_t pixel_format) {
  struct v4l2_frmsizeenum framesize = {0};
  framesize.index = 0;
  framesize.pixel_format = pixel_format;
  while (ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &framesize) != -1) {
    if (framesize.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
      printf("  %ux%u:", framesize.discrete.width, framesize.discrete.height);
      show_resolution_frame_rates(fd, pixel_format, framesize.discrete.width,
                                  framesize.discrete.height);
    } else {
      fprintf(stderr, "stepwise or continuous resolutions not supported\n");
      break;
    }
    framesize.index++;
  }
  if (errno != EINVAL)
    perror("  ioctl() VIDIOC_ENUM_FRAMESIZES");
}


x86 assembly (clang, -O0):
<show_resolutions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1211 <show_resolutions+0xb1>
mov    -0x28(%rbp),%rax
mov    0x2e2b(%rip),%rcx
cmp    (%rcx),%rax
jne    11e6 <show_resolutions+0x86>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe35(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1070 <show_resolution_frame_rates@plt>
jmp    1200 <show_resolutions+0xa0>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1211 <show_resolutions+0xb1>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    118c <show_resolutions+0x2c>
mov    0x2db0(%rip),%rax
mov    (%rax),%rax
mov    0x2d9e(%rip),%rcx
cmp    (%rcx),%rax
je     1237 <show_resolutions+0xd7>
lea    0xe09(%rip),%rdi
call   1080 <perror@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_resolutions>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %esi,0x18(%rsp)
mov    0x2e6f(%rip),%r12
mov    (%r12),%esi
mov    %rsp,%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     11fb <show_resolutions+0xab>
mov    0x2e4f(%rip),%r13
lea    0xe68(%rip),%r14
mov    %rsp,%r15
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%rax
cmp    0x0(%r13),%rax
jne    11e6 <show_resolutions+0x96>
mov    0x10(%rsp),%esi
mov    0x14(%rsp),%edx
mov    %r14,%rdi
call   1030 <printf@plt>
mov    0x10(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    %ebp,%edi
mov    %ebx,%esi
call   1060 <show_resolution_frame_rates@plt>
addq   $0x1,0x8(%rsp)
mov    (%r12),%esi
mov    %ebp,%edi
mov    %r15,%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11a0 <show_resolutions+0x50>
jmp    11fb <show_resolutions+0xab>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%rax
mov    0x2db4(%rip),%rcx
cmp    (%rcx),%rax
jne    1220 <show_resolutions+0xd0>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe14(%rip),%rdi
call   1070 <perror@plt>
jmp    1211 <show_resolutions+0xc1>

LLVM IR (-O0):
%struct.v4l2_frmsizeenum = type { i64, i64, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32, i32 }
@VIDIOC_ENUM_FRAMESIZES = global i32 0
@V4L2_FRMSIZE_TYPE_DISCRETE = global i64 0
@.str = [9 x i8] c" %ux%u:\00"
@stderr = global i32 0
@.str.1 = [50 x i8] c"stepwise or continuous resolutions not supported\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.2 = [33 x i8] c" ioctl() VIDIOC_ENUM_FRAMESIZES\00"
define void @show_resolutions(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.v4l2_frmsizeenum
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = bitcast %struct.v4l2_frmsizeenum* %5 to i8*
%7 = getelementptr inbounds %struct.v4l2_frmsizeenum, %struct.v4l2_frmsizeenum* %5, i32 0, i32 1
store i64 0, i64* %7
%8 = load i32, i32* %4
%9 = getelementptr inbounds %struct.v4l2_frmsizeenum, %struct.v4l2_frmsizeenum* %5, i32 0, i32 3
store i32 %8, i32* %9
br label %10
10: ; preds = %40, %2
%11 = load i32, i32* %3
%12 = load i32, i32* @VIDIOC_ENUM_FRAMESIZES
%13 = call i32 @ioctl(i32 %11, i32 %12, %struct.v4l2_frmsizeenum* %5)
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %44
15: ; preds = %10
%16 = getelementptr inbounds %struct.v4l2_frmsizeenum, %struct.v4l2_frmsizeenum* %5, i32 0, i32 0
%17 = load i64, i64* %16
%18 = load i64, i64* @V4L2_FRMSIZE_TYPE_DISCRETE
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %37
20: ; preds = %15
%21 = getelementptr inbounds %struct.v4l2_frmsizeenum, %struct.v4l2_frmsizeenum* %5, i32 0, i32 2
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.v4l2_frmsizeenum, %struct.v4l2_frmsizeenum* %5, i32 0, i32 2
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 1
%26 = load i32, i32* %25
%27 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %26)
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = getelementptr inbounds %struct.v4l2_frmsizeenum, %struct.v4l2_frmsizeenum* %5, i32 0, i32 2
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.v4l2_frmsizeenum, %struct.v4l2_frmsizeenum* %5, i32 0, i32 2
%34 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %33, i32 0, i32 1
%35 = load i32, i32* %34
%36 = call i32 @show_resolution_frame_rates(i32 %28, i32 %29, i32 %32, i32 %35)
br label %40
37: ; preds = %15
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
br label %44
40: ; preds = %20
%41 = getelementptr inbounds %struct.v4l2_frmsizeenum, %struct.v4l2_frmsizeenum* %5, i32 0, i32 1
%42 = load i64, i64* %41
%43 = add nsw i64 %42, 1
store i64 %43, i64* %41
br label %10
44: ; preds = %37, %10
%45 = load i64, i64* @errno
%46 = load i64, i64* @EINVAL
%47 = icmp ne i64 %45, %46
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %48, %44
ret void
}

LLVM IR (-O2):
%struct.v4l2_frmsizeenum = type { i64, i64, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32, i32 }
@VIDIOC_ENUM_FRAMESIZES = global i32 0
@V4L2_FRMSIZE_TYPE_DISCRETE = global i64 0
@.str = [9 x i8] c" %ux%u:\00"
@stderr = global i32 0
@.str.1 = [50 x i8] c"stepwise or continuous resolutions not supported\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.2 = [33 x i8] c" ioctl() VIDIOC_ENUM_FRAMESIZES\00"
define void @show_resolutions(i32 %0, i32 %1) {
%3 = alloca %struct.v4l2_frmsizeenum
%4 = bitcast %struct.v4l2_frmsizeenum* %3 to i8*
%5 = getelementptr inbounds %struct.v4l2_frmsizeenum, %struct.v4l2_frmsizeenum* %3, i64 0, i32 1
%6 = getelementptr inbounds %struct.v4l2_frmsizeenum, %struct.v4l2_frmsizeenum* %3, i64 0, i32 3
%7 = bitcast %struct.v4l2_frmsizeenum* %3 to i8*
store i32 %1, i32* %6
%8 = load i32, i32* @VIDIOC_ENUM_FRAMESIZES
%9 = call i32 @ioctl(i32 %0, i32 %8, %struct.v4l2_frmsizeenum* %3)
%10 = icmp eq i32 %9, -1
br i1 %10, label %34, label %11
11: ; preds = %2
%12 = getelementptr inbounds %struct.v4l2_frmsizeenum, %struct.v4l2_frmsizeenum* %3, i64 0, i32 0
%13 = getelementptr inbounds %struct.v4l2_frmsizeenum, %struct.v4l2_frmsizeenum* %3, i64 0, i32 2, i32 0
%14 = getelementptr inbounds %struct.v4l2_frmsizeenum, %struct.v4l2_frmsizeenum* %3, i64 0, i32 2, i32 1
br label %15
15: ; preds = %11, %19
%16 = load i64, i64* %12
%17 = load i64, i64* @V4L2_FRMSIZE_TYPE_DISCRETE
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %31
19: ; preds = %15
%20 = load i32, i32* %13
%21 = load i32, i32* %14
%22 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %21)
%23 = load i32, i32* %13
%24 = load i32, i32* %14
%25 = call i32 @show_resolution_frame_rates(i32 %0, i32 %1, i32 %23, i32 %24)
%26 = load i64, i64* %5
%27 = add nsw i64 %26, 1
store i64 %27, i64* %5
%28 = load i32, i32* @VIDIOC_ENUM_FRAMESIZES
%29 = call i32 @ioctl(i32 %0, i32 %28, %struct.v4l2_frmsizeenum* %3)
%30 = icmp eq i32 %29, -1
br i1 %30, label %34, label %15
31: ; preds = %15
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %19, %2, %31
%35 = load i64, i64* @errno
%36 = load i64, i64* @EINVAL
%37 = icmp eq i64 %35, %36
br i1 %37, label %40, label %38
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %34
ret void
}