#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_output {
  int index;
  scalar_t__ name;
};

/* Variables and functions */
int /*<<< orphan*/ VIDIOC_ENUMOUTPUT;
scalar_t__ ioctl(int, int /*<<< orphan*/, struct v4l2_output *);
scalar_t__ strcasecmp(char *, char const *const);
int v4l2_set_output_by_index(int, int);
int __attribute__((unused))
v4l2_set_output_by_name(int videofd, const char *const name) {
  struct v4l2_output output;
  int output_idx;
  output.index = 0;
  output_idx = -1;
  while (ioctl(videofd, VIDIOC_ENUMOUTPUT, &output) == 0) {
    if (strcasecmp((char *)output.name, name) == 0) {
      output_idx = output.index;
      break;
    }
    ++output.index;
  }
  return v4l2_set_output_by_index(videofd, output_idx);
}


x86 assembly (clang, -O0):
<v4l2_set_output_by_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jne    119c <v4l2_set_output_by_name+0x6c>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    118e <v4l2_set_output_by_name+0x5e>
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    119c <v4l2_set_output_by_name+0x6c>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    114d <v4l2_set_output_by_name+0x1d>
mov    -0x4(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1040 <v4l2_set_output_by_index@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<v4l2_set_output_by_name>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
movl   $0x0,(%rsp)
mov    0x2e99(%rip),%r12
mov    (%r12),%esi
mov    %rsp,%rdx
call   1050 <ioctl@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
jne    11a3 <v4l2_set_output_by_name+0x73>
mov    %rsp,%rbp
nopl   0x0(%rax)
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
call   1030 <strcasecmp@plt>
mov    (%rsp),%ecx
test   %rax,%rax
je     11a0 <v4l2_set_output_by_name+0x70>
add    $0x1,%ecx
mov    %ecx,(%rsp)
mov    (%r12),%esi
mov    %ebx,%edi
mov    %rbp,%rdx
call   1050 <ioctl@plt>
test   %rax,%rax
je     1170 <v4l2_set_output_by_name+0x40>
jmp    11a3 <v4l2_set_output_by_name+0x73>
mov    %ecx,%r15d
mov    %ebx,%edi
mov    %r15d,%esi
call   1040 <v4l2_set_output_by_index@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.v4l2_output = type { i32, i64 }
@VIDIOC_ENUMOUTPUT = global i32 0
define i32 @v4l2_set_output_by_name(i32 %0, i8* nocapture %1) {
%3 = alloca %struct.v4l2_output
%4 = bitcast %struct.v4l2_output* %3 to i8*
%5 = getelementptr inbounds %struct.v4l2_output, %struct.v4l2_output* %3, i64 0, i32 0
store i32 0, i32* %5
%6 = load i32, i32* @VIDIOC_ENUMOUTPUT
%7 = call i64 @ioctl(i32 %0, i32 %6, %struct.v4l2_output* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %22
9: ; preds = %2
%10 = getelementptr inbounds %struct.v4l2_output, %struct.v4l2_output* %3, i64 0, i32 1
br label %11
11: ; preds = %9, %17
%12 = load i64, i64* %10
%13 = inttoptr i64 %12 to i8*
%14 = call i64 @strcasecmp(i8* %13, i8* %1)
%15 = icmp eq i64 %14, 0
%16 = load i32, i32* %5
br i1 %15, label %22, label %17
17: ; preds = %11
%18 = add nsw i32 %16, 1
store i32 %18, i32* %5
%19 = load i32, i32* @VIDIOC_ENUMOUTPUT
%20 = call i64 @ioctl(i32 %0, i32 %19, %struct.v4l2_output* %3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %11, label %22
22: ; preds = %17, %11, %2
%23 = phi i32 [ -1, %2 ], [ %16, %11 ], [ -1, %17 ]
%24 = call i32 @v4l2_set_output_by_index(i32 %0, i32 %23)
ret i32 %24
}