#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dprintf(int, char *, ...);
int get_control_i(int, char *);
scalar_t__ my_execv(char **);
int open_videodevice(char const *, int /*<<< orphan*/);
char *realpath(char const *, char *);
int set_control_i(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int set_timeoutimage(const char *devicename, const char *imagefile,
                     int timeout) {
  int fd = -1;
  char imagearg[4096], imagefile2[4096], devicearg[4096];
  char *args[] = {"gst-launch-1.0",
                  "uridecodebin",
                  0,
                  "!",
                  "videoconvert",
                  "!",
                  "videoscale",
                  "!",
                  "imagefreeze",
                  "!",
                  "identity",
                  "error-after=3",
                  "!",
                  "v4l2sink",
                  "show-preroll-frame=false",
                  0,
                  0};
  snprintf(imagearg, 4096, "uri=file://%s", realpath(imagefile, imagefile2));
  snprintf(devicearg, 4096, "device=%s", devicename);
  imagearg[4095] = devicearg[4095] = 0;
  args[2] = imagearg;
  args[15] = devicearg;
  fd = open_videodevice(devicename, O_RDWR);
  if (fd >= 0) {
    set_control_i(fd, "timeout_image_io", 1);
    close(fd);
  }
  dprintf(2, "v================================================================"
             "======v\n");
  if (my_execv(args)) {
  }
  dprintf(2, "^================================================================"
             "======^\n");
  fd = open_videodevice(devicename, O_RDWR);
  if (fd >= 0) {
    if (timeout < 0) {
      timeout = get_control_i(fd, "timeout");
    } else {
      timeout = set_control_i(fd, "timeout", timeout);
    }
    if (timeout <= 0) {
      dprintf(2, "Timeout is currently disabled; you can set it to some "
                 "positive value, e.g.:\n");
      dprintf(2, "    $  v4l2-ctl -d %s -c timeout=3000\n", devicename);
    }
    close(fd);
  }
}


x86 assembly (clang, -O0):
<set_timeoutimage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30c0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
lea    -0x30b0(%rbp),%rdi
lea    0x2bd5(%rip),%rsi
mov    $0x88,%edx
call   1090 <memcpy@plt>
lea    -0x1020(%rbp),%rax
mov    %rax,-0x30b8(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x2020(%rbp),%rsi
call   1080 <realpath@plt>
mov    -0x30b8(%rbp),%rdi
mov    %rax,%rcx
mov    $0x1000,%esi
lea    0xe82(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x3020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1000,%esi
lea    0xe74(%rip),%rdx
call   1040 <snprintf@plt>
movb   $0x0,-0x2021(%rbp)
movb   $0x0,-0x21(%rbp)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x30a0(%rbp)
lea    -0x3020(%rbp),%rax
mov    %rax,-0x3038(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
call   10a0 <open_videodevice@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     127c <set_timeoutimage+0xec>
mov    -0x20(%rbp),%edi
lea    0xe29(%rip),%rsi
mov    $0x1,%edx
call   1070 <set_control_i@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    $0x2,%edi
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1060 <dprintf@plt>
lea    -0x30b0(%rbp),%rdi
call   10b0 <my_execv@plt>
cmp    $0x0,%rax
je     12aa <set_timeoutimage+0x11a>
jmp    12aa <set_timeoutimage+0x11a>
mov    $0x2,%edi
lea    0xe38(%rip),%rsi
mov    $0x0,%al
call   1060 <dprintf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d20(%rip),%rax
mov    (%rax),%esi
call   10a0 <open_videodevice@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     134e <set_timeoutimage+0x1be>
cmpl   $0x0,-0x1c(%rbp)
jge    12fd <set_timeoutimage+0x16d>
mov    -0x20(%rbp),%edi
lea    0xe48(%rip),%rsi
call   1030 <get_control_i@plt>
mov    %eax,-0x1c(%rbp)
jmp    1312 <set_timeoutimage+0x182>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%edx
lea    0xe2e(%rip),%rsi
call   1070 <set_control_i@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     1346 <set_timeoutimage+0x1b6>
mov    $0x2,%edi
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1060 <dprintf@plt>
mov    -0x10(%rbp),%rdx
mov    $0x2,%edi
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   1060 <dprintf@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x30c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_timeoutimage>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3098,%rsp
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%r15
lea    0x2be3(%rip),%rsi
mov    %rsp,%rdi
mov    $0x88,%edx
call   1090 <memcpy@plt>
lea    0x2090(%rsp),%rsi
mov    %rbp,%rdi
call   1080 <realpath@plt>
lea    0xeaa(%rip),%rdx
lea    0x1090(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x1000,%esi
mov    %rax,%rcx
call   1040 <snprintf@plt>
lea    0xe99(%rip),%rdx
lea    0x90(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r15,%rcx
call   1040 <snprintf@plt>
movb   $0x0,0x108f(%rsp)
movb   $0x0,0x208f(%rsp)
mov    %rbp,0x10(%rsp)
mov    %rbx,0x78(%rsp)
mov    0x2dbf(%rip),%rbx
mov    (%rbx),%esi
mov    %r15,%rdi
call   10a0 <open_videodevice@plt>
test   %eax,%eax
js     1253 <set_timeoutimage+0xc3>
mov    %eax,%ebp
lea    0xe53(%rip),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1070 <set_control_i@plt>
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xe4a(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   1060 <dprintf@plt>
mov    %rsp,%rdi
call   10b0 <my_execv@plt>
lea    0xe79(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   1060 <dprintf@plt>
mov    (%rbx),%esi
mov    %r15,%rdi
call   10a0 <open_videodevice@plt>
test   %eax,%eax
js     12db <set_timeoutimage+0x14b>
mov    %eax,%ebp
lea    0xea0(%rip),%rsi
mov    %eax,%edi
test   %r14d,%r14d
js     12e9 <set_timeoutimage+0x159>
mov    %r14d,%edx
call   1070 <set_control_i@plt>
test   %eax,%eax
jg     12d4 <set_timeoutimage+0x144>
lea    0xe8e(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   1060 <dprintf@plt>
lea    0xec8(%rip),%rsi
mov    $0x2,%edi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <dprintf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
add    $0x3098,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
call   1030 <get_control_i@plt>
test   %eax,%eax
jg     12d4 <set_timeoutimage+0x144>
jmp    12ab <set_timeoutimage+0x11b>

LLVM IR (-O0):
@.str = [15 x i8] c"gst-launch-1.0\00"
@.str.1 = [13 x i8] c"uridecodebin\00"
@.str.2 = [2 x i8] c"!\00"
@.str.3 = [13 x i8] c"videoconvert\00"
@.str.4 = [11 x i8] c"videoscale\00"
@.str.5 = [12 x i8] c"imagefreeze\00"
@.str.6 = [9 x i8] c"identity\00"
@.str.7 = [14 x i8] c"error-after=3\00"
@.str.8 = [9 x i8] c"v4l2sink\00"
@.str.9 = [25 x i8] c"show-preroll-frame=false\00"
@__const.set_timeoutimage.args = [17 x i8*] [i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i32 0, i32 0), i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i32 0, i32 0), i8* null, i8* null]
@.str.10 = [14 x i8] c"uri=file://%s\00"
@.str.11 = [10 x i8] c"device=%s\00"
@O_RDWR = global i32 0
@.str.12 = [17 x i8] c"timeout_image_io\00"
@.str.13 = [74 x i8] c"v======================================================================v\0A\00"
@.str.14 = [74 x i8] c"^======================================================================^\0A\00"
@.str.15 = [8 x i8] c"timeout\00"
@.str.16 = [77 x i8] c"Timeout is currently disabled; you can set it to some positive value, e.g.:\0A\00"
@.str.17 = [39 x i8] c" $ v4l2-ctl -d %s -c timeout=3000\0A\00"
define i32 @set_timeoutimage(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4096 x i8]
%10 = alloca [4096 x i8]
%11 = alloca [4096 x i8]
%12 = alloca [17 x i8*]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 -1, i32* %8
%13 = bitcast [17 x i8*]* %12 to i8*
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%15 = load i8*, i8** %6
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%17 = call i8* @realpath(i8* %15, i8* %16)
%18 = call i32 @snprintf(i8* %14, i32 4096, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%20 = load i8*, i8** %5
%21 = call i32 @snprintf(i8* %19, i32 4096, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 4095
store i8 0, i8* %22
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 4095
store i8 0, i8* %23
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%25 = getelementptr inbounds [17 x i8*], [17 x i8*]* %12, i64 0, i64 2
store i8* %24, i8** %25
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%27 = getelementptr inbounds [17 x i8*], [17 x i8*]* %12, i64 0, i64 15
store i8* %26, i8** %27
%28 = load i8*, i8** %5
%29 = load i32, i32* @O_RDWR
%30 = call i32 @open_videodevice(i8* %28, i32 %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp sge i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %3
%34 = load i32, i32* %8
%35 = call i32 @set_control_i(i32 %34, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0), i32 1)
%36 = load i32, i32* %8
%37 = call i32 @close(i32 %36)
br label %38
38: ; preds = %33, %3
%39 = call i32 (i32, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.13, i64 0, i64 0))
%40 = getelementptr inbounds [17 x i8*], [17 x i8*]* %12, i64 0, i64 0
%41 = call i64 @my_execv(i8** %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %38
br label %44
44: ; preds = %43, %38
%45 = call i32 (i32, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.14, i64 0, i64 0))
%46 = load i8*, i8** %5
%47 = load i32, i32* @O_RDWR
%48 = call i32 @open_videodevice(i8* %46, i32 %47)
store i32 %48, i32* %8
%49 = load i32, i32* %8
%50 = icmp sge i32 %49, 0
br i1 %50, label %51, label %71
51: ; preds = %44
%52 = load i32, i32* %7
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32, i32* %8
%56 = call i32 @get_control_i(i32 %55, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i64 0, i64 0))
store i32 %56, i32* %7
br label %61
57: ; preds = %51
%58 = load i32, i32* %8
%59 = load i32, i32* %7
%60 = call i32 @set_control_i(i32 %58, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i64 0, i64 0), i32 %59)
store i32 %60, i32* %7
br label %61
61: ; preds = %57, %54
%62 = load i32, i32* %7
%63 = icmp sle i32 %62, 0
br i1 %63, label %64, label %68
64: ; preds = %61
%65 = call i32 (i32, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.16, i64 0, i64 0))
%66 = load i8*, i8** %5
%67 = call i32 (i32, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.17, i64 0, i64 0), i8* %66)
br label %68
68: ; preds = %64, %61
%69 = load i32, i32* %8
%70 = call i32 @close(i32 %69)
br label %71
71: ; preds = %68, %44
%72 = load i32, i32* %4
ret i32 %72
}

LLVM IR (-O2):
@.str = [15 x i8] c"gst-launch-1.0\00"
@.str.1 = [13 x i8] c"uridecodebin\00"
@.str.2 = [2 x i8] c"!\00"
@.str.3 = [13 x i8] c"videoconvert\00"
@.str.4 = [11 x i8] c"videoscale\00"
@.str.5 = [12 x i8] c"imagefreeze\00"
@.str.6 = [9 x i8] c"identity\00"
@.str.7 = [14 x i8] c"error-after=3\00"
@.str.8 = [9 x i8] c"v4l2sink\00"
@.str.9 = [25 x i8] c"show-preroll-frame=false\00"
@__const.set_timeoutimage.args = [17 x i8*] [i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i32 0, i32 0), i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i32 0, i32 0), i8* null, i8* null]
@.str.10 = [14 x i8] c"uri=file://%s\00"
@.str.11 = [10 x i8] c"device=%s\00"
@O_RDWR = global i32 0
@.str.12 = [17 x i8] c"timeout_image_io\00"
@.str.13 = [74 x i8] c"v======================================================================v\0A\00"
@.str.14 = [74 x i8] c"^======================================================================^\0A\00"
@.str.15 = [8 x i8] c"timeout\00"
@.str.16 = [77 x i8] c"Timeout is currently disabled; you can set it to some positive value, e.g.:\0A\00"
@.str.17 = [39 x i8] c" $ v4l2-ctl -d %s -c timeout=3000\0A\00"
define i32 @set_timeoutimage(i8* %0, i8* nocapture %1, i32 %2) {
%4 = alloca [4096 x i8]
%5 = alloca [4096 x i8]
%6 = alloca [4096 x i8]
%7 = alloca [17 x i8*]
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%11 = bitcast [17 x i8*]* %7 to i8*
%12 = call i8* @realpath(i8* %1, i8* %9)
%13 = call i32 @snprintf(i8* %8, i32 4096, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i8* %12)
%14 = call i32 @snprintf(i8* %10, i32 4096, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8* %0)
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 4095
store i8 0, i8* %15
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 4095
store i8 0, i8* %16
%17 = getelementptr inbounds [17 x i8*], [17 x i8*]* %7, i64 0, i64 2
store i8* %8, i8** %17
%18 = getelementptr inbounds [17 x i8*], [17 x i8*]* %7, i64 0, i64 15
store i8* %10, i8** %18
%19 = load i32, i32* @O_RDWR
%20 = call i32 @open_videodevice(i8* %0, i32 %19)
%21 = icmp sgt i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %3
%23 = call i32 @set_control_i(i32 %20, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0), i32 1)
%24 = call i32 @close(i32 %20)
br label %25
25: ; preds = %22, %3
%26 = call i32 (i32, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.13, i64 0, i64 0))
%27 = getelementptr inbounds [17 x i8*], [17 x i8*]* %7, i64 0, i64 0
%28 = call i64 @my_execv(i8** %27)
%29 = call i32 (i32, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.14, i64 0, i64 0))
%30 = load i32, i32* @O_RDWR
%31 = call i32 @open_videodevice(i8* %0, i32 %30)
%32 = icmp sgt i32 %31, -1
br i1 %32, label %33, label %47
33: ; preds = %25
%34 = icmp slt i32 %2, 0
br i1 %34, label %35, label %37
35: ; preds = %33
%36 = call i32 @get_control_i(i32 %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i64 0, i64 0))
br label %39
37: ; preds = %33
%38 = call i32 @set_control_i(i32 %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i64 0, i64 0), i32 %2)
br label %39
39: ; preds = %37, %35
%40 = phi i32 [ %36, %35 ], [ %38, %37 ]
%41 = icmp slt i32 %40, 1
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = call i32 (i32, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.16, i64 0, i64 0))
%44 = call i32 (i32, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.17, i64 0, i64 0), i8* %0)
br label %45
45: ; preds = %42, %39
%46 = call i32 @close(i32 %31)
br label %47
47: ; preds = %45, %25
ret i32 undef
}