#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_S_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 set_control_i(int fd, const char *control, int value) {
  struct v4l2_control ctrl;
  memset(&ctrl, 0, sizeof(ctrl));
  ctrl.id = _get_control_id(fd, control);
  ctrl.value = value;
  if (ctrl.id && ioctl(fd, VIDIOC_S_CTRL, &ctrl) == 0) {
    int value = ctrl.value;
    return value;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_control_i>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x28(%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,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a3 <set_control_i+0x73>
mov    -0x8(%rbp),%edi
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jne    11a3 <set_control_i+0x73>
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11aa <set_control_i+0x7a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_control_i>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %edi,%r15d
lea    0x8(%rsp),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
call   1050 <_get_control_id@plt>
mov    %rax,0x10(%rsp)
mov    %r14d,0x8(%rsp)
test   %rax,%rax
je     1191 <set_control_i+0x61>
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r15d,%edi
call   1040 <ioctl@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    1191 <set_control_i+0x61>
mov    0x8(%rsp),%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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