#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_queryctrl {
  unsigned int id;
  int /*<<< orphan*/ name;
};
typedef int /*<<< orphan*/ qctrl;

/* Variables and functions */
int V4L2_CID_LASTP1;
unsigned int V4L2_CID_PRIVATE_BASE;
int V4L2_CID_USER_BASE;
unsigned int V4L2_CTRL_FLAG_NEXT_CTRL;
int /*<<< orphan*/ VIDIOC_QUERYCTRL;
scalar_t__ ioctl(int, int /*<<< orphan*/, struct v4l2_queryctrl *);
int /*<<< orphan*/ memset(struct v4l2_queryctrl *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strncmp(int /*<<< orphan*/, char const *, size_t const);
size_t strnlen(char const *, int);
unsigned int _get_control_id(int fd, const char *control) {
  const size_t length = strnlen(control, 1024);
  const unsigned next = V4L2_CTRL_FLAG_NEXT_CTRL;
  struct v4l2_queryctrl qctrl;
  int id;
  memset(&qctrl, 0, sizeof(qctrl));
  while (ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0) {
    if (!strncmp(qctrl.name, control, length))
      return qctrl.id;
    qctrl.id |= next;
  }
  for (id = V4L2_CID_USER_BASE; id < V4L2_CID_LASTP1; id++) {
    qctrl.id = id;
    if (ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0) {
      if (!strncmp(qctrl.name, control, length))
        return qctrl.id;
    }
  }
  for (qctrl.id = V4L2_CID_PRIVATE_BASE;
       ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0; qctrl.id++) {
    if (!strncmp(qctrl.name, control, length)) {
      unsigned int id = qctrl.id;
      return id;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<_get_control_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x400,%esi
call   1060 <strnlen@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jne    11ce <_get_control_id+0x8e>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11c0 <_get_control_id+0x80>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12bc <_get_control_id+0x17c>
mov    -0x1c(%rbp),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    117d <_get_control_id+0x3d>
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2dec(%rip),%rcx
cmp    (%rcx),%eax
jge    124d <_get_control_id+0x10d>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jne    123a <_get_control_id+0xfa>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1235 <_get_control_id+0xf5>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12bc <_get_control_id+0x17c>
jmp    123a <_get_control_id+0xfa>
jmp    123f <_get_control_id+0xff>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11da <_get_control_id+0x9a>
mov    0x2d8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d75(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jne    12b5 <_get_control_id+0x175>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    12a2 <_get_control_id+0x162>
mov    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12bc <_get_control_id+0x17c>
jmp    12a7 <_get_control_id+0x167>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1259 <_get_control_id+0x119>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_get_control_id>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
mov    %rsi,%rdi
mov    $0x400,%esi
call   1060 <strnlen@plt>
mov    %rax,%r14
mov    0x2e59(%rip),%rax
mov    (%rax),%r12d
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e55(%rip),%r13
mov    0x0(%r13),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
nopl   0x0(%rax)
call   1050 <ioctl@plt>
test   %rax,%rax
jne    11c5 <_get_control_id+0x85>
mov    0x4(%rsp),%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <strncmp@plt>
mov    (%rsp),%ebx
test   %eax,%eax
je     1283 <_get_control_id+0x143>
or     %r12d,%ebx
mov    %ebx,(%rsp)
mov    0x0(%r13),%esi
mov    %ebp,%edi
mov    %rsp,%rdx
jmp    1190 <_get_control_id+0x50>
mov    0x2e1c(%rip),%rax
mov    (%rax),%ebx
mov    0x2dfb(%rip),%r13
cmp    0x0(%r13),%ebx
jge    121c <_get_control_id+0xdc>
mov    %rsp,%r12
jmp    11e9 <_get_control_id+0xa9>
add    $0x1,%ebx
cmp    0x0(%r13),%ebx
jge    121c <_get_control_id+0xdc>
mov    %ebx,(%rsp)
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r12,%rdx
call   1050 <ioctl@plt>
test   %rax,%rax
jne    11e0 <_get_control_id+0xa0>
mov    0x4(%rsp),%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11e0 <_get_control_id+0xa0>
mov    (%rsp),%ebx
jmp    1283 <_get_control_id+0x143>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    0x2da9(%rip),%r13
mov    0x0(%r13),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
call   1050 <ioctl@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    1283 <_get_control_id+0x143>
mov    %rsp,%r12
nopw   0x0(%rax,%rax,1)
mov    0x4(%rsp),%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <strncmp@plt>
mov    (%rsp),%ecx
test   %eax,%eax
je     1281 <_get_control_id+0x141>
add    $0x1,%ecx
mov    %ecx,(%rsp)
mov    0x0(%r13),%esi
mov    %ebp,%edi
mov    %r12,%rdx
call   1050 <ioctl@plt>
test   %rax,%rax
je     1250 <_get_control_id+0x110>
jmp    1283 <_get_control_id+0x143>
mov    %ecx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.v4l2_queryctrl = type { i32, i32 }
@V4L2_CTRL_FLAG_NEXT_CTRL = global i32 0
@VIDIOC_QUERYCTRL = global i32 0
@V4L2_CID_USER_BASE = global i32 0
@V4L2_CID_LASTP1 = global i32 0
@V4L2_CID_PRIVATE_BASE = global i32 0
define i32 @_get_control_id(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca %struct.v4l2_queryctrl
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%11 = load i8*, i8** %5
%12 = call i64 @strnlen(i8* %11, i32 1024)
store i64 %12, i64* %6
%13 = load i32, i32* @V4L2_CTRL_FLAG_NEXT_CTRL
store i32 %13, i32* %7
%14 = call i32 @memset(%struct.v4l2_queryctrl* %8, i32 0, i32 8)
br label %15
15: ; preds = %30, %2
%16 = load i32, i32* %4
%17 = load i32, i32* @VIDIOC_QUERYCTRL
%18 = call i64 @ioctl(i32 %16, i32 %17, %struct.v4l2_queryctrl* %8)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %35
20: ; preds = %15
%21 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %8, i32 0, i32 1
%22 = load i32, i32* %21
%23 = load i8*, i8** %5
%24 = load i64, i64* %6
%25 = call i32 @strncmp(i32 %22, i8* %23, i64 %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %20
%28 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %8, i32 0, i32 0
%29 = load i32, i32* %28
store i32 %29, i32* %3
br label %88
30: ; preds = %20
%31 = load i32, i32* %7
%32 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %8, i32 0, i32 0
%33 = load i32, i32* %32
%34 = or i32 %33, %31
store i32 %34, i32* %32
br label %15
35: ; preds = %15
%36 = load i32, i32* @V4L2_CID_USER_BASE
store i32 %36, i32* %9
br label %37
37: ; preds = %60, %35
%38 = load i32, i32* %9
%39 = load i32, i32* @V4L2_CID_LASTP1
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %63
41: ; preds = %37
%42 = load i32, i32* %9
%43 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %8, i32 0, i32 0
store i32 %42, i32* %43
%44 = load i32, i32* %4
%45 = load i32, i32* @VIDIOC_QUERYCTRL
%46 = call i64 @ioctl(i32 %44, i32 %45, %struct.v4l2_queryctrl* %8)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %59
48: ; preds = %41
%49 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %8, i32 0, i32 1
%50 = load i32, i32* %49
%51 = load i8*, i8** %5
%52 = load i64, i64* %6
%53 = call i32 @strncmp(i32 %50, i8* %51, i64 %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %58, label %55
55: ; preds = %48
%56 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %8, i32 0, i32 0
%57 = load i32, i32* %56
store i32 %57, i32* %3
br label %88
58: ; preds = %48
br label %59
59: ; preds = %58, %41
br label %60
60: ; preds = %59
%61 = load i32, i32* %9
%62 = add nsw i32 %61, 1
store i32 %62, i32* %9
br label %37
63: ; preds = %37
%64 = load i32, i32* @V4L2_CID_PRIVATE_BASE
%65 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %8, i32 0, i32 0
store i32 %64, i32* %65
br label %66
66: ; preds = %83, %63
%67 = load i32, i32* %4
%68 = load i32, i32* @VIDIOC_QUERYCTRL
%69 = call i64 @ioctl(i32 %67, i32 %68, %struct.v4l2_queryctrl* %8)
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %87
71: ; preds = %66
%72 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %8, i32 0, i32 1
%73 = load i32, i32* %72
%74 = load i8*, i8** %5
%75 = load i64, i64* %6
%76 = call i32 @strncmp(i32 %73, i8* %74, i64 %75)
%77 = icmp ne i32 %76, 0
br i1 %77, label %82, label %78
78: ; preds = %71
%79 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %8, i32 0, i32 0
%80 = load i32, i32* %79
store i32 %80, i32* %10
%81 = load i32, i32* %10
store i32 %81, i32* %3
br label %88
82: ; preds = %71
br label %83
83: ; preds = %82
%84 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %8, i32 0, i32 0
%85 = load i32, i32* %84
%86 = add i32 %85, 1
store i32 %86, i32* %84
br label %66
87: ; preds = %66
store i32 0, i32* %3
br label %88
88: ; preds = %87, %78, %55, %27
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
%struct.v4l2_queryctrl = type { i32, i32 }
@V4L2_CTRL_FLAG_NEXT_CTRL = global i32 0
@VIDIOC_QUERYCTRL = global i32 0
@V4L2_CID_USER_BASE = global i32 0
@V4L2_CID_LASTP1 = global i32 0
@V4L2_CID_PRIVATE_BASE = global i32 0
define i32 @_get_control_id(i32 %0, i8* %1) {
%3 = alloca %struct.v4l2_queryctrl
%4 = tail call i64 @strnlen(i8* %1, i32 1024)
%5 = load i32, i32* @V4L2_CTRL_FLAG_NEXT_CTRL
%6 = bitcast %struct.v4l2_queryctrl* %3 to i8*
%7 = call i32 @memset(%struct.v4l2_queryctrl* %3, i32 0, i32 8)
%8 = load i32, i32* @VIDIOC_QUERYCTRL
%9 = call i64 @ioctl(i32 %0, i32 %8, %struct.v4l2_queryctrl* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %2
%12 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %3, i64 0, i32 1
%13 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %3, i64 0, i32 0
br label %14
14: ; preds = %11, %19
%15 = load i32, i32* %12
%16 = call i32 @strncmp(i32 %15, i8* %1, i64 %4)
%17 = icmp eq i32 %16, 0
%18 = load i32, i32* %13
br i1 %17, label %64, label %19
19: ; preds = %14
%20 = or i32 %18, %5
store i32 %20, i32* %13
%21 = load i32, i32* @VIDIOC_QUERYCTRL
%22 = call i64 @ioctl(i32 %0, i32 %21, %struct.v4l2_queryctrl* %3)
%23 = icmp eq i64 %22, 0
br i1 %23, label %14, label %24
24: ; preds = %19, %2
%25 = load i32, i32* @V4L2_CID_USER_BASE
%26 = load i32, i32* @V4L2_CID_LASTP1
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %46
28: ; preds = %24
%29 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %3, i64 0, i32 0
%30 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %3, i64 0, i32 1
br label %31
31: ; preds = %28, %42
%32 = phi i32 [ %25, %28 ], [ %43, %42 ]
store i32 %32, i32* %29
%33 = load i32, i32* @VIDIOC_QUERYCTRL
%34 = call i64 @ioctl(i32 %0, i32 %33, %struct.v4l2_queryctrl* %3)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %31
%37 = load i32, i32* %30
%38 = call i32 @strncmp(i32 %37, i8* %1, i64 %4)
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = load i32, i32* %29
br label %64
42: ; preds = %31, %36
%43 = add nsw i32 %32, 1
%44 = load i32, i32* @V4L2_CID_LASTP1
%45 = icmp slt i32 %43, %44
br i1 %45, label %31, label %46
46: ; preds = %42, %24
%47 = load i32, i32* @V4L2_CID_PRIVATE_BASE
%48 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %3, i64 0, i32 0
store i32 %47, i32* %48
%49 = load i32, i32* @VIDIOC_QUERYCTRL
%50 = call i64 @ioctl(i32 %0, i32 %49, %struct.v4l2_queryctrl* %3)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %64
52: ; preds = %46
%53 = getelementptr inbounds %struct.v4l2_queryctrl, %struct.v4l2_queryctrl* %3, i64 0, i32 1
br label %54
54: ; preds = %52, %59
%55 = load i32, i32* %53
%56 = call i32 @strncmp(i32 %55, i8* %1, i64 %4)
%57 = icmp eq i32 %56, 0
%58 = load i32, i32* %48
br i1 %57, label %64, label %59
59: ; preds = %54
%60 = add i32 %58, 1
store i32 %60, i32* %48
%61 = load i32, i32* @VIDIOC_QUERYCTRL
%62 = call i64 @ioctl(i32 %0, i32 %61, %struct.v4l2_queryctrl* %3)
%63 = icmp eq i64 %62, 0
br i1 %63, label %54, label %64
64: ; preds = %14, %59, %54, %46, %40
%65 = phi i32 [ %41, %40 ], [ 0, %46 ], [ %58, %54 ], [ 0, %59 ], [ %18, %14 ]
ret i32 %65
}