#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_querymenu {
  int flags;
  size_t type;
  char *name;
  int value;
  int minimum;
  int maximum;
  int index;
  int step;
  int /*<<< orphan*/ id;
  int /*<<< orphan*/ member_0;
  int /*<<< orphan*/ member_1;
};
struct v4l2_queryctrl {
  int flags;
  size_t type;
  char *name;
  int value;
  int minimum;
  int maximum;
  int index;
  int step;
  int /*<<< orphan*/ id;
  int /*<<< orphan*/ member_0;
  int /*<<< orphan*/ member_1;
};
struct v4l2_control {
  int flags;
  size_t type;
  char *name;
  int value;
  int minimum;
  int maximum;
  int index;
  int step;
  int /*<<< orphan*/ id;
  int /*<<< orphan*/ member_0;
  int /*<<< orphan*/ member_1;
};
typedef int ssize_t;

/* Variables and functions */
int V4L2_CTRL_FLAG_DISABLED;
int /*<<< orphan*/ V4L2_CTRL_FLAG_NEXT_CTRL;
size_t V4L2_CTRL_TYPE_INTEGER_MENU;
size_t V4L2_CTRL_TYPE_MENU;
int /*<<< orphan*/ VIDIOC_G_CTRL;
int /*<<< orphan*/ VIDIOC_QUERYCTRL;
int /*<<< orphan*/ VIDIOC_QUERYMENU;
int ioctl(int, int /*<<< orphan*/, struct v4l2_querymenu *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
void show_controls(int fd) {
  const char *type_names[] = {NULL,      "integer",     "boolean",    "menu",
                              "button",  "integer64",   "ctrl_class", "string",
                              "bitmask", "integer_menu"};
  printf("Extended controls:\n");
  struct v4l2_queryctrl control = {0};
  for (control.id = V4L2_CTRL_FLAG_NEXT_CTRL;
       ioctl(fd, VIDIOC_QUERYCTRL, &control) == 0;
       control.id |= V4L2_CTRL_FLAG_NEXT_CTRL) {
    if (control.flags & V4L2_CTRL_FLAG_DISABLED) {
      printf("- DISABLED: ");
    } else {
      printf("- ");
    }
    struct v4l2_control control_value = {control.id, 0};
    if (ioctl(fd, VIDIOC_G_CTRL, &control_value) == -1)
      perror("VIDIOC_G_CTRL ioctl() failed");
    if (control.type == V4L2_CTRL_TYPE_MENU ||
        control.type == V4L2_CTRL_TYPE_INTEGER_MENU) {
      printf("%s: %d (%s)\n", control.name, control_value.value,
             type_names[control.type]);
      struct v4l2_querymenu menu_entry = {0};
      for (ssize_t i = control.minimum; i <= control.maximum; i++) {
        menu_entry.id = control.id;
        menu_entry.index = i;
        if (ioctl(fd, VIDIOC_QUERYMENU, &menu_entry) == -1) {
          perror("VIDIOC_QUERYMENU ioctl() failed");
          continue;
        }
        if (control.type == V4L2_CTRL_TYPE_MENU)
          printf("  %d: %s\n", menu_entry.index, menu_entry.name);
        else
          printf("  %d: %lld\n", menu_entry.index, menu_entry.value);
      }
    } else {
      printf("%s: %d (%s, values in [%d, %d] step %d)\n", control.name,
             control_value.value, type_names[control.type], control.minimum,
             control.maximum, control.step);
    }
  }
}


x86 assembly (clang, -O0):
<show_controls>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x60(%rbp),%rdi
lea    0x2c27(%rip),%rsi
mov    $0x50,%edx
call   1060 <memcpy@plt>
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x98(%rbp),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1040 <memset@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
lea    -0x98(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%eax
jne    13c7 <show_controls+0x277>
mov    -0x98(%rbp),%eax
mov    0x2e22(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11ec <show_controls+0x9c>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fa <show_controls+0xaa>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xd0(%rbp),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1040 <memset@plt>
mov    -0x6c(%rbp),%eax
mov    %eax,-0xd0(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
lea    -0xd0(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1243 <show_controls+0xf3>
lea    0xe2e(%rip),%rdi
call   1070 <perror@plt>
mov    -0x90(%rbp),%rax
mov    0x2d87(%rip),%rcx
cmp    (%rcx),%rax
je     1271 <show_controls+0x121>
mov    -0x90(%rbp),%rax
mov    0x2d48(%rip),%rcx
cmp    (%rcx),%rax
jne    1379 <show_controls+0x229>
mov    -0x88(%rbp),%rsi
mov    -0xb8(%rbp),%edx
mov    -0x90(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rcx
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x108(%rbp),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1040 <memset@plt>
mov    -0x7c(%rbp),%eax
mov    %eax,-0x10c(%rbp)
mov    -0x10c(%rbp),%eax
cmp    -0x78(%rbp),%eax
jg     1374 <show_controls+0x224>
mov    -0x6c(%rbp),%eax
mov    %eax,-0xdc(%rbp)
mov    -0x10c(%rbp),%eax
mov    %eax,-0xe4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2cbe(%rip),%rax
mov    (%rax),%esi
lea    -0x108(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    130a <show_controls+0x1ba>
lea    0xd96(%rip),%rdi
call   1070 <perror@plt>
jmp    1360 <show_controls+0x210>
mov    -0x90(%rbp),%rax
mov    0x2cc0(%rip),%rcx
cmp    (%rcx),%rax
jne    1341 <show_controls+0x1f1>
mov    -0xe4(%rbp),%esi
mov    -0xf8(%rbp),%rdx
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    135b <show_controls+0x20b>
mov    -0xe4(%rbp),%esi
mov    -0xf0(%rbp),%edx
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1360 <show_controls+0x210>
mov    -0x10c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10c(%rbp)
jmp    12b4 <show_controls+0x164>
jmp    13ae <show_controls+0x25e>
mov    -0x88(%rbp),%rsi
mov    -0xb8(%rbp),%edx
mov    -0x90(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rcx
mov    -0x7c(%rbp),%r8d
mov    -0x78(%rbp),%r9d
mov    -0x70(%rbp),%eax
lea    0xd28(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
jmp    13b3 <show_controls+0x263>
mov    0x2bfe(%rip),%rax
mov    (%rax),%eax
or     -0x6c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
jmp    11a0 <show_controls+0x50>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_controls>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    %edi,%ebx
lea    0xf87(%rip),%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x40(%rsp)
mov    0x2e37(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x3c(%rsp)
mov    0x2e41(%rip),%r15
mov    (%r15),%esi
lea    0x10(%rsp),%rdx
mov    %ebx,%edi
call   1050 <ioctl@plt>
test   %eax,%eax
je     11b4 <show_controls+0x74>
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e1d(%rip),%r14
mov    0x2dde(%rip),%r12
lea    0x50(%rsp),%r13
jmp    11f1 <show_controls+0xb1>
nopl   0x0(%rax)
mov    0x2df9(%rip),%r15
mov    0x0(%rbp),%eax
or     %eax,0x3c(%rsp)
mov    (%r15),%esi
mov    %ebx,%edi
lea    0x10(%rsp),%rdx
call   1050 <ioctl@plt>
test   %eax,%eax
jne    11a2 <show_controls+0x62>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
and    0x10(%rsp),%eax
lea    0xe43(%rip),%rdi
lea    0xe49(%rip),%rax
cmove  %rax,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movq   $0x0,0xc0(%rsp)
mov    0x3c(%rsp),%eax
mov    %eax,0x90(%rsp)
mov    0x2d78(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
lea    0x90(%rsp),%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1375 <show_controls+0x235>
mov    0x18(%rsp),%rax
mov    0x20(%rsp),%rsi
mov    0xa8(%rsp),%edx
lea    0x2b0e(%rip),%rcx
mov    (%rcx,%rax,8),%rcx
cmp    (%r14),%rax
je     12c0 <show_controls+0x180>
mov    0x2d1e(%rip),%rdi
cmp    (%rdi),%rax
je     12c0 <show_controls+0x180>
mov    0x2c(%rsp),%r8d
mov    0x30(%rsp),%r9d
mov    0x38(%rsp),%eax
mov    %eax,(%rsp)
lea    0xe09(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d7 <show_controls+0x97>
nopl   0x0(%rax,%rax,1)
lea    0xdae(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movq   $0x0,0x80(%rsp)
mov    0x2c(%rsp),%r15d
cmp    0x30(%rsp),%r15d
jle    1324 <show_controls+0x1e4>
jmp    11d0 <show_controls+0x90>
nopl   (%rax)
mov    0x68(%rsp),%edx
lea    0xda1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1(%r15),%eax
cmp    0x30(%rsp),%r15d
mov    %eax,%r15d
jge    11d0 <show_controls+0x90>
mov    0x3c(%rsp),%eax
mov    %eax,0x7c(%rsp)
mov    %r15d,0x74(%rsp)
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r13,%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1367 <show_controls+0x227>
mov    0x18(%rsp),%rax
mov    0x74(%rsp),%esi
cmp    (%r14),%rax
jne    1300 <show_controls+0x1c0>
mov    0x60(%rsp),%rdx
lea    0xd44(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1312 <show_controls+0x1d2>
lea    0xd14(%rip),%rdi
call   1060 <perror@plt>
jmp    1312 <show_controls+0x1d2>
lea    0xcdc(%rip),%rdi
call   1060 <perror@plt>
jmp    126a <show_controls+0x12a>

LLVM IR (-O0):
%struct.v4l2_queryctrl = type { i32, i64, i8*, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.v4l2_control = type { i32, i64, i8*, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.v4l2_querymenu = type { i32, i64, i8*, i32, i32, i32, i32, i32, i32, i32, i32 }
@.str = [8 x i8] c"integer\00"
@.str.1 = [8 x i8] c"boolean\00"
@.str.2 = [5 x i8] c"menu\00"
@.str.3 = [7 x i8] c"button\00"
@.str.4 = [10 x i8] c"integer64\00"
@.str.5 = [11 x i8] c"ctrl_class\00"
@.str.6 = [7 x i8] c"string\00"
@.str.7 = [8 x i8] c"bitmask\00"
@.str.8 = [13 x i8] c"integer_menu\00"
@__const.show_controls.type_names = [10 x i8*] [i8* null, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i32 0, i32 0)]
@.str.9 = [20 x i8] c"Extended controls:\0A\00"
@V4L2_CTRL_FLAG_NEXT_CTRL = global i32 0
@VIDIOC_QUERYCTRL = global i32 0
@V4L2_CTRL_FLAG_DISABLED = global i32 0
@.str.10 = [13 x i8] c"- DISABLED: \00"
@.str.11 = [3 x i8] c"- \00"
@VIDIOC_G_CTRL = global i32 0
@.str.12 = [29 x i8] c"VIDIOC_G_CTRL ioctl() failed\00"
@V4L2_CTRL_TYPE_MENU = global i64 0
@V4L2_CTRL_TYPE_INTEGER_MENU = global i64 0
@.str.13 = [13 x i8] c"%s: %d (%s)\0A\00"
@VIDIOC_QUERYMENU = global i32 0
@.str.14 = [32 x i8] c"VIDIOC_QUERYMENU ioctl() failed\00"
@.str.15 = [10 x i8] c" %d: %s\0A\00"
@.str.16 = [12 x i8] c" %d: %lld\0A\00"
@.str.17 = [41 x i8] c"%s: %d (%s, values in [%d, %d] step %d)\0A\00"
define void @show_controls(i32 %0) {
%2 = alloca i32
%3 = alloca [10 x i8*]
%4 = alloca %struct.v4l2_queryctrl
%5 = alloca %struct.v4l2_control
%6 = alloca %struct.v4l2_querymenu
%7 = alloca i32
store i32 %0, i32* %2
%8 = bitcast [10 x i8*]* %3 to i8*
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
%10 = bitcast %struct.v4l2_queryctrl* %4 to i8*
%11 = load i32, i32* @V4L2_CTRL_FLAG_NEXT_CTRL
%12 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %4, i32 0, i32 8
store i32 %11, i32* %12
br label %13
13: ; preds = %120, %1
%14 = load i32, i32* %2
%15 = load i32, i32* @VIDIOC_QUERYCTRL
%16 = bitcast %struct.v4l2_queryctrl* %4 to %struct.v4l2_querymenu*
%17 = call i32 @ioctl(i32 %14, i32 %15, %struct.v4l2_querymenu* %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %125
19: ; preds = %13
%20 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %4, i32 0, i32 0
%21 = load i32, i32* %20
%22 = load i32, i32* @V4L2_CTRL_FLAG_DISABLED
%23 = and i32 %21, %22
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
br label %29
27: ; preds = %19
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
br label %29
29: ; preds = %27, %25
%30 = bitcast %struct.v4l2_control* %5 to i8*
%31 = getelementptr inbounds %struct.v4l2_control, %struct.v4l2_control* %5, i32 0, i32 0
%32 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %4, i32 0, i32 8
%33 = load i32, i32* %32
store i32 %33, i32* %31
%34 = load i32, i32* %2
%35 = load i32, i32* @VIDIOC_G_CTRL
%36 = bitcast %struct.v4l2_control* %5 to %struct.v4l2_querymenu*
%37 = call i32 @ioctl(i32 %34, i32 %35, %struct.v4l2_querymenu* %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %29
%40 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.12, i64 0, i64 0))
br label %41
41: ; preds = %39, %29
%42 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %4, i32 0, i32 1
%43 = load i64, i64* %42
%44 = load i64, i64* @V4L2_CTRL_TYPE_MENU
%45 = icmp eq i64 %43, %44
br i1 %45, label %51, label %46
46: ; preds = %41
%47 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %4, i32 0, i32 1
%48 = load i64, i64* %47
%49 = load i64, i64* @V4L2_CTRL_TYPE_INTEGER_MENU
%50 = icmp eq i64 %48, %49
br i1 %50, label %51, label %103
51: ; preds = %46, %41
%52 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %4, i32 0, i32 2
%53 = load i8*, i8** %52
%54 = getelementptr inbounds %struct.v4l2_control, %struct.v4l2_control* %5, i32 0, i32 3
%55 = load i32, i32* %54
%56 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %4, i32 0, i32 1
%57 = load i64, i64* %56
%58 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 %57
%59 = load i8*, i8** %58
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i64 0, i64 0), i8* %53, i32 %55, i8* %59)
%61 = bitcast %struct.v4l2_querymenu* %6 to i8*
%62 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %4, i32 0, i32 4
%63 = load i32, i32* %62
store i32 %63, i32* %7
br label %64
64: ; preds = %99, %51
%65 = load i32, i32* %7
%66 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %4, i32 0, i32 5
%67 = load i32, i32* %66
%68 = icmp sle i32 %65, %67
br i1 %68, label %69, label %102
69: ; preds = %64
%70 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %4, i32 0, i32 8
%71 = load i32, i32* %70
%72 = getelementptr inbounds %struct.v4l2_querymenu, %struct.v4l2_querymenu* %6, i32 0, i32 8
store i32 %71, i32* %72
%73 = load i32, i32* %7
%74 = getelementptr inbounds %struct.v4l2_querymenu, %struct.v4l2_querymenu* %6, i32 0, i32 6
store i32 %73, i32* %74
%75 = load i32, i32* %2
%76 = load i32, i32* @VIDIOC_QUERYMENU
%77 = call i32 @ioctl(i32 %75, i32 %76, %struct.v4l2_querymenu* %6)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %81
79: ; preds = %69
%80 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.14, i64 0, i64 0))
br label %99
81: ; preds = %69
%82 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %4, i32 0, i32 1
%83 = load i64, i64* %82
%84 = load i64, i64* @V4L2_CTRL_TYPE_MENU
%85 = icmp eq i64 %83, %84
br i1 %85, label %86, label %92
86: ; preds = %81
%87 = getelementptr inbounds %struct.v4l2_querymenu, %struct.v4l2_querymenu* %6, i32 0, i32 6
%88 = load i32, i32* %87
%89 = getelementptr inbounds %struct.v4l2_querymenu, %struct.v4l2_querymenu* %6, i32 0, i32 2
%90 = load i8*, i8** %89
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.15, i64 0, i64 0), i32 %88, i8* %90)
br label %98
92: ; preds = %81
%93 = getelementptr inbounds %struct.v4l2_querymenu, %struct.v4l2_querymenu* %6, i32 0, i32 6
%94 = load i32, i32* %93
%95 = getelementptr inbounds %struct.v4l2_querymenu, %struct.v4l2_querymenu* %6, i32 0, i32 3
%96 = load i32, i32* %95
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.16, i64 0, i64 0), i32 %94, i32 %96)
br label %98
98: ; preds = %92, %86
br label %99
99: ; preds = %98, %79
%100 = load i32, i32* %7
%101 = add nsw i32 %100, 1
store i32 %101, i32* %7
br label %64
102: ; preds = %64
br label %119
103: ; preds = %46
%104 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %4, i32 0, i32 2
%105 = load i8*, i8** %104
%106 = getelementptr inbounds %struct.v4l2_control, %struct.v4l2_control* %5, i32 0, i32 3
%107 = load i32, i32* %106
%108 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %4, i32 0, i32 1
%109 = load i64, i64* %108
%110 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 %109
%111 = load i8*, i8** %110
%112 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %4, i32 0, i32 4
%113 = load i32, i32* %112
%114 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %4, i32 0, i32 5
%115 = load i32, i32* %114
%116 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %4, i32 0, i32 7
%117 = load i32, i32* %116
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.17, i64 0, i64 0), i8* %105, i32 %107, i8* %111, i32 %113, i32 %115, i32 %117)
br label %119
119: ; preds = %103, %102
br label %120
120: ; preds = %119
%121 = load i32, i32* @V4L2_CTRL_FLAG_NEXT_CTRL
%122 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %4, i32 0, i32 8
%123 = load i32, i32* %122
%124 = or i32 %123, %121
store i32 %124, i32* %122
br label %13
125: ; preds = %13
ret void
}

LLVM IR (-O2):
%struct.v4l2_queryctrl = type { i32, i64, i8*, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.v4l2_control = type { i32, i64, i8*, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.v4l2_querymenu = type { i32, i64, i8*, i32, i32, i32, i32, i32, i32, i32, i32 }
@.str = [8 x i8] c"integer\00"
@.str.1 = [8 x i8] c"boolean\00"
@.str.2 = [5 x i8] c"menu\00"
@.str.3 = [7 x i8] c"button\00"
@.str.4 = [10 x i8] c"integer64\00"
@.str.5 = [11 x i8] c"ctrl_class\00"
@.str.6 = [7 x i8] c"string\00"
@.str.7 = [8 x i8] c"bitmask\00"
@.str.8 = [13 x i8] c"integer_menu\00"
@__const.show_controls.type_names = [10 x i8*] [i8* null, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i32 0, i32 0)]
@V4L2_CTRL_FLAG_NEXT_CTRL = global i32 0
@VIDIOC_QUERYCTRL = global i32 0
@V4L2_CTRL_FLAG_DISABLED = global i32 0
@.str.10 = [13 x i8] c"- DISABLED: \00"
@.str.11 = [3 x i8] c"- \00"
@VIDIOC_G_CTRL = global i32 0
@.str.12 = [29 x i8] c"VIDIOC_G_CTRL ioctl() failed\00"
@V4L2_CTRL_TYPE_MENU = global i64 0
@V4L2_CTRL_TYPE_INTEGER_MENU = global i64 0
@.str.13 = [13 x i8] c"%s: %d (%s)\0A\00"
@VIDIOC_QUERYMENU = global i32 0
@.str.14 = [32 x i8] c"VIDIOC_QUERYMENU ioctl() failed\00"
@.str.15 = [10 x i8] c" %d: %s\0A\00"
@.str.16 = [12 x i8] c" %d: %lld\0A\00"
@.str.17 = [41 x i8] c"%s: %d (%s, values in [%d, %d] step %d)\0A\00"
@str = [19 x i8] c"Extended controls:\00"
define void @show_controls(i32 %0) {
%2 = alloca %struct.v4l2_queryctrl
%3 = alloca %struct.v4l2_control
%4 = alloca %struct.v4l2_querymenu
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%6 = bitcast %struct.v4l2_queryctrl* %2 to i8*
%7 = load i32, i32* @V4L2_CTRL_FLAG_NEXT_CTRL
%8 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %2, i64 0, i32 8
%9 = bitcast %struct.v4l2_queryctrl* %2 to %struct.v4l2_querymenu*
store i32 %7, i32* %8
%10 = load i32, i32* @VIDIOC_QUERYCTRL
%11 = call i32 @ioctl(i32 %0, i32 %10, %struct.v4l2_querymenu* %9)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %94
13: ; preds = %1
%14 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %2, i64 0, i32 0
%15 = bitcast %struct.v4l2_control* %3 to i8*
%16 = getelementptr inbounds %struct.v4l2_control, %struct.v4l2_control* %3, i64 0, i32 0
%17 = bitcast %struct.v4l2_control* %3 to %struct.v4l2_querymenu*
%18 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %2, i64 0, i32 1
%19 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %2, i64 0, i32 2
%20 = getelementptr inbounds %struct.v4l2_control, %struct.v4l2_control* %3, i64 0, i32 3
%21 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %2, i64 0, i32 4
%22 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %2, i64 0, i32 5
%23 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %2, i64 0, i32 7
%24 = bitcast %struct.v4l2_querymenu* %4 to i8*
%25 = getelementptr inbounds %struct.v4l2_querymenu, %struct.v4l2_querymenu* %4, i64 0, i32 8
%26 = getelementptr inbounds %struct.v4l2_querymenu, %struct.v4l2_querymenu* %4, i64 0, i32 6
%27 = getelementptr inbounds %struct.v4l2_querymenu, %struct.v4l2_querymenu* %4, i64 0, i32 3
%28 = getelementptr inbounds %struct.v4l2_querymenu, %struct.v4l2_querymenu* %4, i64 0, i32 2
br label %29
29: ; preds = %13, %87
%30 = load i32, i32* %14
%31 = load i32, i32* @V4L2_CTRL_FLAG_DISABLED
%32 = and i32 %31, %30
%33 = icmp eq i32 %32, 0
%34 = select i1 %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %34)
%36 = load i32, i32* %8
store i32 %36, i32* %16
%37 = load i32, i32* @VIDIOC_G_CTRL
%38 = call i32 @ioctl(i32 %0, i32 %37, %struct.v4l2_querymenu* %17)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %29
%41 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.12, i64 0, i64 0))
br label %42
42: ; preds = %40, %29
%43 = load i64, i64* %18
%44 = load i64, i64* @V4L2_CTRL_TYPE_MENU
%45 = icmp eq i64 %43, %44
%46 = load i64, i64* @V4L2_CTRL_TYPE_INTEGER_MENU
%47 = icmp eq i64 %43, %46
%48 = select i1 %45, i1 true, i1 %47
%49 = load i8*, i8** %19
%50 = load i32, i32* %20
%51 = getelementptr inbounds [10 x i8*], [10 x i8*]* @__const.show_controls.type_names, i64 0, i64 %43
%52 = load i8*, i8** %51
br i1 %48, label %53, label %82
53: ; preds = %42
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i64 0, i64 0), i8* %49, i32 %50, i8* %52)
%55 = load i32, i32* %21
%56 = load i32, i32* %22
%57 = icmp sgt i32 %55, %56
br i1 %57, label %58, label %59
58: ; preds = %78, %53
br label %87
59: ; preds = %53, %78
%60 = phi i32 [ %79, %78 ], [ %55, %53 ]
%61 = load i32, i32* %8
store i32 %61, i32* %25
store i32 %60, i32* %26
%62 = load i32, i32* @VIDIOC_QUERYMENU
%63 = call i32 @ioctl(i32 %0, i32 %62, %struct.v4l2_querymenu* %4)
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %67
65: ; preds = %59
%66 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.14, i64 0, i64 0))
br label %78
67: ; preds = %59
%68 = load i64, i64* %18
%69 = load i64, i64* @V4L2_CTRL_TYPE_MENU
%70 = icmp eq i64 %68, %69
%71 = load i32, i32* %26
br i1 %70, label %72, label %75
72: ; preds = %67
%73 = load i8*, i8** %28
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.15, i64 0, i64 0), i32 %71, i8* %73)
br label %78
75: ; preds = %67
%76 = load i32, i32* %27
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.16, i64 0, i64 0), i32 %71, i32 %76)
br label %78
78: ; preds = %72, %75, %65
%79 = add nsw i32 %60, 1
%80 = load i32, i32* %22
%81 = icmp slt i32 %60, %80
br i1 %81, label %59, label %58
82: ; preds = %42
%83 = load i32, i32* %21
%84 = load i32, i32* %22
%85 = load i32, i32* %23
%86 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.17, i64 0, i64 0), i8* %49, i32 %50, i8* %52, i32 %83, i32 %84, i32 %85)
br label %87
87: ; preds = %82, %58
%88 = load i32, i32* @V4L2_CTRL_FLAG_NEXT_CTRL
%89 = load i32, i32* %8
%90 = or i32 %89, %88
store i32 %90, i32* %8
%91 = load i32, i32* @VIDIOC_QUERYCTRL
%92 = call i32 @ioctl(i32 %0, i32 %91, %struct.v4l2_querymenu* %9)
%93 = icmp eq i32 %92, 0
br i1 %93, label %29, label %94
94: ; preds = %87, %1
ret void
}