#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_control {
  int value;
  scalar_t__ id;
};
typedef int /*<<< orphan*/ ctrl;

/* Variables and functions */
int /*<<< orphan*/ VIDIOC_G_CTRL;
scalar_t__ _get_control_id(int, char const *);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct v4l2_control *);
int /*<<< orphan*/ memset(struct v4l2_control *, int /*<<< orphan*/, int);
int get_control_i(int fd, const char *control) {
  struct v4l2_control ctrl;
  memset(&ctrl, 0, sizeof(ctrl));
  ctrl.id = _get_control_id(fd, control);
  if (ctrl.id && ioctl(fd, VIDIOC_G_CTRL, &ctrl) == 0) {
    int value = ctrl.value;
    return value;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_control_i>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <_get_control_id@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119a <get_control_i+0x6a>
mov    -0x8(%rbp),%edi
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jne    119a <get_control_i+0x6a>
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a1 <get_control_i+0x71>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_control_i>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%rdi
xor    %r14d,%r14d
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <_get_control_id@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     117f <get_control_i+0x4f>
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
jne    117f <get_control_i+0x4f>
mov    (%rsp),%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.v4l2_control = type { i32, i64 }
@VIDIOC_G_CTRL = global i32 0
define i32 @get_control_i(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.v4l2_control
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%8 = call i32 @memset(%struct.v4l2_control* %6, i32 0, i32 16)
%9 = load i32, i32* %4
%10 = load i8*, i8** %5
%11 = call i64 @_get_control_id(i32 %9, i8* %10)
%12 = getelementptr inbounds %struct.v4l2_control, %struct.v4l2_control* %6, i32 0, i32 1
store i64 %11, i64* %12
%13 = getelementptr inbounds %struct.v4l2_control, %struct.v4l2_control* %6, i32 0, i32 1
%14 = load i64, i64* %13
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %2
%17 = load i32, i32* %4
%18 = load i32, i32* @VIDIOC_G_CTRL
%19 = call i64 @ioctl(i32 %17, i32 %18, %struct.v4l2_control* %6)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = getelementptr inbounds %struct.v4l2_control, %struct.v4l2_control* %6, i32 0, i32 0
%23 = load i32, i32* %22
store i32 %23, i32* %7
%24 = load i32, i32* %7
store i32 %24, i32* %3
br label %26
25: ; preds = %16, %2
store i32 0, i32* %3
br label %26
26: ; preds = %25, %21
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.v4l2_control = type { i32, i64 }
@VIDIOC_G_CTRL = global i32 0
define i32 @get_control_i(i32 %0, i8* %1) {
%3 = alloca %struct.v4l2_control
%4 = bitcast %struct.v4l2_control* %3 to i8*
%5 = call i32 @memset(%struct.v4l2_control* %3, i32 0, i32 16)
%6 = call i64 @_get_control_id(i32 %0, i8* %1)
%7 = getelementptr inbounds %struct.v4l2_control, %struct.v4l2_control* %3, i64 0, i32 1
store i64 %6, i64* %7
%8 = icmp eq i64 %6, 0
br i1 %8, label %16, label %9
9: ; preds = %2
%10 = load i32, i32* @VIDIOC_G_CTRL
%11 = call i64 @ioctl(i32 %0, i32 %10, %struct.v4l2_control* %3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = getelementptr inbounds %struct.v4l2_control, %struct.v4l2_control* %3, i64 0, i32 0
%15 = load i32, i32* %14
br label %16
16: ; preds = %2, %9, %13
%17 = phi i32 [ %15, %13 ], [ 0, %9 ], [ 0, %2 ]
ret i32 %17
}