#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ get_camcap(int);
int /*<<< orphan*/ get_camfmt(int);
int /*<<< orphan*/ get_caminfo(int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ set_camfmt(int, char *);
int main(int argc, char const *argv[]) {
  int camfd = open(argv[1], O_RDWR);
  if (camfd == -1) {
    perror("open video failed");
    exit(0);
  }
  get_caminfo(camfd);
  get_camcap(camfd);
  printf("\n[配置前] 摄像头当前采集格式信息：\n");
  get_camfmt(camfd);
  set_camfmt(camfd, "MJPG");
  printf("\n[配置后] 摄像头当前采集格式信息：\n");
  get_camfmt(camfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11cc <main+0x4c>
lea    0xe40(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
call   1050 <get_caminfo@plt>
mov    -0x14(%rbp),%edi
call   1040 <get_camcap@plt>
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   10a0 <get_camfmt@plt>
mov    -0x14(%rbp),%edi
lea    0xe4b(%rip),%rsi
call   1070 <set_camfmt@plt>
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   10a0 <get_camfmt@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x8(%rsi),%rdi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11e0 <main+0x60>
mov    %eax,%ebx
mov    %eax,%edi
call   1050 <get_caminfo@plt>
mov    %ebx,%edi
call   1040 <get_camcap@plt>
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   10a0 <get_camfmt@plt>
lea    0xe50(%rip),%rsi
mov    %ebx,%edi
call   1070 <set_camfmt@plt>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   10a0 <get_camfmt@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe19(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [18 x i8] c"open video failed\00"
@.str.1 = [51 x i8] c"\0A[\E9\85\8D\E7\BD\AE\E5\89\8D] \E6\91\84\E5\83\8F\E5\A4\B4\E5\BD\93\E5\89\8D\E9\87\87\E9\9B\86\E6\A0\BC\E5\BC\8F\E4\BF\A1\E6\81\AF\EF\BC\9A\0A\00"
@.str.2 = [5 x i8] c"MJPG\00"
@.str.3 = [51 x i8] c"\0A[\E9\85\8D\E7\BD\AE\E5\90\8E] \E6\91\84\E5\83\8F\E5\A4\B4\E5\BD\93\E5\89\8D\E9\87\87\E9\9B\86\E6\A0\BC\E5\BC\8F\E4\BF\A1\E6\81\AF\EF\BC\9A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_RDWR
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %2
%18 = load i32, i32* %6
%19 = call i32 @get_caminfo(i32 %18)
%20 = load i32, i32* %6
%21 = call i32 @get_camcap(i32 %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* %6
%24 = call i32 @get_camfmt(i32 %23)
%25 = load i32, i32* %6
%26 = call i32 @set_camfmt(i32 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* %6
%29 = call i32 @get_camfmt(i32 %28)
ret i32 0
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [18 x i8] c"open video failed\00"
@.str.2 = [5 x i8] c"MJPG\00"
@str = [50 x i8] c"\0A[\E9\85\8D\E7\BD\AE\E5\89\8D] \E6\91\84\E5\83\8F\E5\A4\B4\E5\BD\93\E5\89\8D\E9\87\87\E9\9B\86\E6\A0\BC\E5\BC\8F\E4\BF\A1\E6\81\AF\EF\BC\9A\00"
@str.4 = [50 x i8] c"\0A[\E9\85\8D\E7\BD\AE\E5\90\8E] \E6\91\84\E5\83\8F\E5\A4\B4\E5\BD\93\E5\89\8D\E9\87\87\E9\9B\86\E6\A0\BC\E5\BC\8F\E4\BF\A1\E6\81\AF\EF\BC\9A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* %4, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %2
%12 = tail call i32 @get_caminfo(i32 %6)
%13 = tail call i32 @get_camcap(i32 %6)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @get_camfmt(i32 %6)
%16 = tail call i32 @set_camfmt(i32 %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.4, i64 0, i64 0))
%18 = tail call i32 @get_camfmt(i32 %6)
ret i32 0
}