#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 void *uint32_t;
struct TYPE_2__ {
  int numerator;
  int denominator;
};
struct v4l2_frmivalenum {
  scalar_t__ type;
  scalar_t__ index;
  TYPE_1__ discrete;
  void *height;
  void *width;
  void *pixel_format;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
scalar_t__ EINVAL;
scalar_t__ V4L2_FRMIVAL_TYPE_DISCRETE;
int /*<<< orphan*/ VIDIOC_ENUM_FRAMEINTERVALS;
scalar_t__ errno;
int ioctl(int, int /*<<< orphan*/, struct v4l2_frmivalenum *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
void show_resolution_frame_rates(int fd, uint32_t pixel_format, uint32_t width,
                                 uint32_t height) {
  struct v4l2_frmivalenum frame_interval = {0};
  frame_interval.index = 0;
  frame_interval.pixel_format = pixel_format;
  frame_interval.width = width;
  frame_interval.height = height;
  while (ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frame_interval) != -1) {
    if (frame_interval.type != V4L2_FRMIVAL_TYPE_DISCRETE) {
      printf(" only descrete frame intervals are supported\n");
      return;
    }
    if (frame_interval.discrete.numerator == 1)
      printf(" %u", frame_interval.discrete.denominator);
    else
      printf(" %u/%u", frame_interval.discrete.numerator,
             frame_interval.discrete.denominator);
    frame_interval.index++;
  }
  printf(" fps\n");
  if (errno != EINVAL)
    perror("  ioctl() VIDIOC_ENUM_FRAMEINTERVALS");
}


x86 assembly (clang, -O0):
<show_resolution_frame_rates>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1040 <memset@plt>
movq   $0x0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1211 <show_resolution_frame_rates+0xd1>
mov    -0x58(%rbp),%rax
mov    0x2e10(%rip),%rcx
cmp    (%rcx),%rax
je     11cc <show_resolution_frame_rates+0x8c>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1245 <show_resolution_frame_rates+0x105>
cmpl   $0x1,-0x48(%rbp)
jne    11ec <show_resolution_frame_rates+0xac>
mov    -0x44(%rbp),%esi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1200 <show_resolution_frame_rates+0xc0>
mov    -0x48(%rbp),%esi
mov    -0x44(%rbp),%edx
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    1187 <show_resolution_frame_rates+0x47>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%rax
mov    0x2da0(%rip),%rcx
cmp    (%rcx),%rax
je     1245 <show_resolution_frame_rates+0x105>
lea    0xdff(%rip),%rdi
call   1060 <perror@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_resolution_frame_rates>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edi,%ebx
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movq   $0x0,0x30(%rsp)
mov    %rsi,0x28(%rsp)
mov    %rdx,0x20(%rsp)
mov    %rcx,0x18(%rsp)
mov    0x2e68(%rip),%r13
mov    0x0(%r13),%esi
mov    %rsp,%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     11f8 <show_resolution_frame_rates+0xb8>
mov    0x2e28(%rip),%rbp
lea    0xe61(%rip),%r14
mov    %rsp,%r15
lea    0xe5b(%rip),%r12
jmp    11d3 <show_resolution_frame_rates+0x93>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
addq   $0x1,0x8(%rsp)
mov    0x0(%r13),%esi
mov    %ebx,%edi
mov    %r15,%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     11f8 <show_resolution_frame_rates+0xb8>
mov    (%rsp),%rax
cmp    0x0(%rbp),%rax
jne    1228 <show_resolution_frame_rates+0xe8>
mov    0x10(%rsp),%esi
mov    0x14(%rsp),%edx
cmp    $0x1,%esi
jne    11b0 <show_resolution_frame_rates+0x70>
mov    %r14,%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ba <show_resolution_frame_rates+0x7a>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%rax
mov    0x2dbb(%rip),%rcx
cmp    (%rcx),%rax
je     1234 <show_resolution_frame_rates+0xf4>
lea    0xdea(%rip),%rdi
call   1060 <perror@plt>
jmp    1234 <show_resolution_frame_rates+0xf4>
lea    0xe06(%rip),%rdi
call   1030 <puts@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.v4l2_frmivalenum = type { i64, i64, %struct.TYPE_2__, i8*, i8*, i8*, i32 }
%struct.TYPE_2__ = type { i32, i32 }
@VIDIOC_ENUM_FRAMEINTERVALS = global i32 0
@V4L2_FRMIVAL_TYPE_DISCRETE = global i64 0
@.str = [46 x i8] c" only descrete frame intervals are supported\0A\00"
@.str.1 = [4 x i8] c" %u\00"
@.str.2 = [7 x i8] c" %u/%u\00"
@.str.3 = [6 x i8] c" fps\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.4 = [37 x i8] c" ioctl() VIDIOC_ENUM_FRAMEINTERVALS\00"
define void @show_resolution_frame_rates(i32 %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.v4l2_frmivalenum
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%10 = bitcast %struct.v4l2_frmivalenum* %9 to i8*
%11 = getelementptr inbounds %struct.v4l2_frmivalenum, %struct.v4l2_frmivalenum* %9, i32 0, i32 1
store i64 0, i64* %11
%12 = load i8*, i8** %6
%13 = getelementptr inbounds %struct.v4l2_frmivalenum, %struct.v4l2_frmivalenum* %9, i32 0, i32 5
store i8* %12, i8** %13
%14 = load i8*, i8** %7
%15 = getelementptr inbounds %struct.v4l2_frmivalenum, %struct.v4l2_frmivalenum* %9, i32 0, i32 4
store i8* %14, i8** %15
%16 = load i8*, i8** %8
%17 = getelementptr inbounds %struct.v4l2_frmivalenum, %struct.v4l2_frmivalenum* %9, i32 0, i32 3
store i8* %16, i8** %17
br label %18
18: ; preds = %48, %4
%19 = load i32, i32* %5
%20 = load i32, i32* @VIDIOC_ENUM_FRAMEINTERVALS
%21 = call i32 @ioctl(i32 %19, i32 %20, %struct.v4l2_frmivalenum* %9)
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %52
23: ; preds = %18
%24 = getelementptr inbounds %struct.v4l2_frmivalenum, %struct.v4l2_frmivalenum* %9, i32 0, i32 0
%25 = load i64, i64* %24
%26 = load i64, i64* @V4L2_FRMIVAL_TYPE_DISCRETE
%27 = icmp ne i64 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %59
30: ; preds = %23
%31 = getelementptr inbounds %struct.v4l2_frmivalenum, %struct.v4l2_frmivalenum* %9, i32 0, i32 2
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = getelementptr inbounds %struct.v4l2_frmivalenum, %struct.v4l2_frmivalenum* %9, i32 0, i32 2
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 1
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %38)
br label %48
40: ; preds = %30
%41 = getelementptr inbounds %struct.v4l2_frmivalenum, %struct.v4l2_frmivalenum* %9, i32 0, i32 2
%42 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %41, i32 0, i32 0
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.v4l2_frmivalenum, %struct.v4l2_frmivalenum* %9, i32 0, i32 2
%45 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %44, i32 0, i32 1
%46 = load i32, i32* %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %43, i32 %46)
br label %48
48: ; preds = %40, %35
%49 = getelementptr inbounds %struct.v4l2_frmivalenum, %struct.v4l2_frmivalenum* %9, i32 0, i32 1
%50 = load i64, i64* %49
%51 = add nsw i64 %50, 1
store i64 %51, i64* %49
br label %18
52: ; preds = %18
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%54 = load i64, i64* @errno
%55 = load i64, i64* @EINVAL
%56 = icmp ne i64 %54, %55
br i1 %56, label %57, label %59
57: ; preds = %52
%58 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %59
59: ; preds = %28, %57, %52
ret void
}

LLVM IR (-O2):
%struct.v4l2_frmivalenum = type { i64, i64, %struct.TYPE_2__, i8*, i8*, i8*, i32 }
%struct.TYPE_2__ = type { i32, i32 }
@VIDIOC_ENUM_FRAMEINTERVALS = global i32 0
@V4L2_FRMIVAL_TYPE_DISCRETE = global i64 0
@.str.1 = [4 x i8] c" %u\00"
@.str.2 = [7 x i8] c" %u/%u\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.4 = [37 x i8] c" ioctl() VIDIOC_ENUM_FRAMEINTERVALS\00"
@str = [5 x i8] c" fps\00"
@str.5 = [45 x i8] c" only descrete frame intervals are supported\00"
define void @show_resolution_frame_rates(i32 %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca %struct.v4l2_frmivalenum
%6 = bitcast %struct.v4l2_frmivalenum* %5 to i8*
%7 = getelementptr inbounds %struct.v4l2_frmivalenum, %struct.v4l2_frmivalenum* %5, i64 0, i32 1
%8 = getelementptr inbounds %struct.v4l2_frmivalenum, %struct.v4l2_frmivalenum* %5, i64 0, i32 5
%9 = bitcast %struct.v4l2_frmivalenum* %5 to i8*
store i8* %1, i8** %8
%10 = getelementptr inbounds %struct.v4l2_frmivalenum, %struct.v4l2_frmivalenum* %5, i64 0, i32 4
store i8* %2, i8** %10
%11 = getelementptr inbounds %struct.v4l2_frmivalenum, %struct.v4l2_frmivalenum* %5, i64 0, i32 3
store i8* %3, i8** %11
%12 = load i32, i32* @VIDIOC_ENUM_FRAMEINTERVALS
%13 = call i32 @ioctl(i32 %0, i32 %12, %struct.v4l2_frmivalenum* %5)
%14 = icmp eq i32 %13, -1
br i1 %14, label %39, label %15
15: ; preds = %4
%16 = getelementptr inbounds %struct.v4l2_frmivalenum, %struct.v4l2_frmivalenum* %5, i64 0, i32 0
%17 = getelementptr inbounds %struct.v4l2_frmivalenum, %struct.v4l2_frmivalenum* %5, i64 0, i32 2, i32 0
%18 = getelementptr inbounds %struct.v4l2_frmivalenum, %struct.v4l2_frmivalenum* %5, i64 0, i32 2, i32 1
br label %19
19: ; preds = %15, %33
%20 = load i64, i64* %16
%21 = load i64, i64* @V4L2_FRMIVAL_TYPE_DISCRETE
%22 = icmp eq i64 %20, %21
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.5, i64 0, i64 0))
br label %46
25: ; preds = %19
%26 = load i32, i32* %17
%27 = icmp eq i32 %26, 1
%28 = load i32, i32* %18
br i1 %27, label %29, label %31
29: ; preds = %25
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %33
31: ; preds = %25
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %26, i32 %28)
br label %33
33: ; preds = %31, %29
%34 = load i64, i64* %7
%35 = add nsw i64 %34, 1
store i64 %35, i64* %7
%36 = load i32, i32* @VIDIOC_ENUM_FRAMEINTERVALS
%37 = call i32 @ioctl(i32 %0, i32 %36, %struct.v4l2_frmivalenum* %5)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %19
39: ; preds = %33, %4
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%41 = load i64, i64* @errno
%42 = load i64, i64* @EINVAL
%43 = icmp eq i64 %41, %42
br i1 %43, label %46, label %44
44: ; preds = %39
%45 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %39, %44, %23
ret void
}