#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 device {
  int dummy;
};

/* Variables and functions */
unsigned int V4L2_CID_BASE;
unsigned int V4L2_CID_LASTP1;
int /*<<< orphan*/ printf(char *, ...);
int video_print_control(struct device *, unsigned int, int);
void video_list_controls(struct device *dev) {
  unsigned int nctrls = 0;
  unsigned int id;
  int ret;
  unsigned int i;
  for (i = V4L2_CID_BASE; i <= V4L2_CID_LASTP1; ++i) {
    id = i;
    ret = video_print_control(dev, id, true);
    if (ret < 0)
      break;
    id = ret;
    nctrls++;
  }
  if (nctrls)
    printf("%u control%s found.\n", nctrls, nctrls > 1 ? "s" : "");
  else
    printf("No control found.\n");
}


x86 assembly (clang, -O0):
<video_list_controls>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e9f(%rip),%rcx
cmp    (%rcx),%eax
ja     1197 <video_list_controls+0x77>
mov    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    $0x1,%edx
call   1040 <video_print_control@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    117a <video_list_controls+0x5a>
jmp    1197 <video_list_controls+0x77>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113f <video_list_controls+0x1f>
cmpl   $0x0,-0xc(%rbp)
je     11cf <video_list_controls+0xaf>
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%ecx
lea    0xe7b(%rip),%rdx
lea    0xe60(%rip),%rax
cmp    $0x1,%ecx
cmova  %rax,%rdx
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11dd <video_list_controls+0xbd>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<video_list_controls>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2e99(%rip),%rax
mov    (%rax),%r12d
mov    0x2e9f(%rip),%r15
cmp    (%r15),%r12d
ja     11c0 <video_list_controls+0x90>
mov    %rdi,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%r12,%rbx,1),%esi
mov    %r14,%rdi
mov    $0x1,%edx
call   1050 <video_print_control@plt>
test   %eax,%eax
js     11ba <video_list_controls+0x8a>
mov    %ebx,%esi
add    $0x1,%esi
lea    (%r12,%rbx,1),%eax
add    $0x1,%eax
mov    %esi,%ebx
cmp    (%r15),%eax
jbe    1160 <video_list_controls+0x30>
test   %esi,%esi
je     11c0 <video_list_controls+0x90>
cmp    $0x1,%esi
lea    0xe7e(%rip),%rax
lea    0xe78(%rip),%rdx
cmove  %rax,%rdx
lea    0xe58(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <printf@plt>
mov    %ebx,%esi
test   %esi,%esi
jne    118c <video_list_controls+0x5c>
lea    0xe50(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

LLVM IR (-O0):
%struct.device = type { i32 }
@V4L2_CID_BASE = global i32 0
@V4L2_CID_LASTP1 = global i32 0
@.str = [21 x i8] c"%u control%s found.\0A\00"
@.str.1 = [2 x i8] c"s\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [19 x i8] c"No control found.\0A\00"
define void @video_list_controls(%struct.device* %0) {
%2 = alloca %struct.device*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store %struct.device* %0, %struct.device** %2
store i32 0, i32* %3
%7 = load i32, i32* @V4L2_CID_BASE
store i32 %7, i32* %6
br label %8
8: ; preds = %24, %1
%9 = load i32, i32* %6
%10 = load i32, i32* @V4L2_CID_LASTP1
%11 = icmp ule i32 %9, %10
br i1 %11, label %12, label %27
12: ; preds = %8
%13 = load i32, i32* %6
store i32 %13, i32* %4
%14 = load %struct.device*, %struct.device** %2
%15 = load i32, i32* %4
%16 = call i32 @video_print_control(%struct.device* %14, i32 %15, i32 1)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %12
br label %27
20: ; preds = %12
%21 = load i32, i32* %5
store i32 %21, i32* %4
%22 = load i32, i32* %3
%23 = add i32 %22, 1
store i32 %23, i32* %3
br label %24
24: ; preds = %20
%25 = load i32, i32* %6
%26 = add i32 %25, 1
store i32 %26, i32* %6
br label %8
27: ; preds = %19, %8
%28 = load i32, i32* %3
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = load i32, i32* %3
%32 = load i32, i32* %3
%33 = icmp ugt i32 %32, 1
%34 = zext i1 %33 to i64
%35 = select i1 %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %31, i8* %35)
br label %39
37: ; preds = %27
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %30
ret void
}

LLVM IR (-O2):
%struct.device = type { i32 }
@V4L2_CID_BASE = global i32 0
@V4L2_CID_LASTP1 = global i32 0
@.str = [21 x i8] c"%u control%s found.\0A\00"
@.str.1 = [2 x i8] c"s\00"
@.str.2 = [1 x i8] zeroinitializer
@str = [18 x i8] c"No control found.\00"
define void @video_list_controls(%struct.device* %0) {
%2 = load i32, i32* @V4L2_CID_BASE
%3 = load i32, i32* @V4L2_CID_LASTP1
%4 = icmp ugt i32 %2, %3
br i1 %4, label %22, label %5
5: ; preds = %1, %10
%6 = phi i32 [ %12, %10 ], [ %2, %1 ]
%7 = phi i32 [ %11, %10 ], [ 0, %1 ]
%8 = tail call i32 @video_print_control(%struct.device* %0, i32 %6, i32 1)
%9 = icmp slt i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = add i32 %7, 1
%12 = add i32 %6, 1
%13 = load i32, i32* @V4L2_CID_LASTP1
%14 = icmp ugt i32 %12, %13
br i1 %14, label %15, label %5
15: ; preds = %10, %5
%16 = phi i32 [ %11, %10 ], [ %7, %5 ]
%17 = icmp eq i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = icmp eq i32 %16, 1
%20 = select i1 %19, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %16, i8* %20)
br label %24
22: ; preds = %1, %15
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
ret void
}