#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_capability {
  char *driver;
  char *card;
  char *bus_info;
  int version;
  int capabilities;
  int device_caps;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ VIDIOC_QUERYCAP;
int close(int);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int ioctl(int, int /*<<< orphan*/, struct v4l2_capability *);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
int main(int argc, char *argv[]) {
  char *device_name;
  if (argc > 1) {
    device_name = argv[1];
  } else {
    device_name = "/dev/video0";
  }
  int file_device = open(device_name, O_RDWR, 0);
  if (file_device == -1) {
    printf("%s error %d, %s\n", device_name, errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  struct v4l2_capability device_params;
  if (ioctl(file_device, VIDIOC_QUERYCAP, &device_params) == -1) {
    printf("\"VIDIOC_QUERYCAP\" error %d, %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("driver : %s\n", device_params.driver);
  printf("card : %s\n", device_params.card);
  printf("bus_info : %s\n", device_params.bus_info);
  printf("version : %d.%d.%d\n", ((device_params.version >> 16) & 0xFF),
         ((device_params.version >> 8) & 0xFF), (device_params.version & 0xFF));
  printf("capabilities: 0x%08x\n", device_params.capabilities);
  printf("device capabilities: 0x%08x\n", device_params.device_caps);
  if (-1 == close(file_device)) {
    printf("\"close\" error %d, %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  file_device = -1;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1191 <main+0x31>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    119c <main+0x3c>
lea    0xe68(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1205 <main+0xa5>
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x58(%rbp),%rsi
mov    -0x4c(%rbp),%edx
mov    %rax,%rcx
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    125f <main+0xff>
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x5c(%rbp),%esi
mov    %rax,%rdx
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x48(%rbp),%rsi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x40(%rbp),%rsi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rsi
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%esi
sar    $0x10,%esi
and    $0xff,%esi
mov    -0x30(%rbp),%edx
sar    $0x8,%edx
and    $0xff,%edx
mov    -0x30(%rbp),%ecx
and    $0xff,%ecx
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%esi
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1339 <main+0x1d9>
mov    0x2cd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x60(%rbp),%esi
mov    %rax,%rdx
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2c9e(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movl   $0xffffffff,-0x1c(%rbp)
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
cmp    $0x2,%edi
jl     1172 <main+0x12>
mov    0x8(%rsi),%r14
jmp    1179 <main+0x19>
lea    0xe87(%rip),%r14
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
xor    %edx,%edx
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1243 <main+0xe3>
mov    %eax,%ebx
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     126b <main+0x10b>
mov    (%rsp),%rsi
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x8(%rsp),%rsi
lea    0xe79(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x10(%rsp),%rsi
lea    0xe71(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x18(%rsp),%eax
movzbl %ah,%edx
movzbl %al,%ecx
shr    $0x10,%eax
movzbl %al,%esi
lea    0xe62(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x1c(%rsp),%esi
lea    0xe6b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x20(%rsp),%esi
lea    0xe52(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     1284 <main+0x124>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d8e(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1080 <strerror@plt>
lea    0xdb2(%rip),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    12a7 <main+0x147>
mov    0x2d66(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1080 <strerror@plt>
lea    0xd9b(%rip),%rdi
jmp    129b <main+0x13b>
mov    0x2d4d(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1080 <strerror@plt>
lea    0xdfa(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.v4l2_capability = type { i8*, i8*, i8*, i32, i32, i32 }
@.str = [12 x i8] c"/dev/video0\00"
@O_RDWR = global i32 0
@.str.1 = [17 x i8] c"%s error %d, %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@VIDIOC_QUERYCAP = global i32 0
@.str.2 = [32 x i8] c"\22VIDIOC_QUERYCAP\22 error %d, %s\0A\00"
@.str.3 = [13 x i8] c"driver : %s\0A\00"
@.str.4 = [11 x i8] c"card : %s\0A\00"
@.str.5 = [15 x i8] c"bus_info : %s\0A\00"
@.str.6 = [20 x i8] c"version : %d.%d.%d\0A\00"
@.str.7 = [22 x i8] c"capabilities: 0x%08x\0A\00"
@.str.8 = [29 x i8] c"device capabilities: 0x%08x\0A\00"
@.str.9 = [22 x i8] c"\22close\22 error %d, %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.v4l2_capability
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
store i8* %14, i8** %6
br label %16
15: ; preds = %2
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %6
br label %16
16: ; preds = %15, %11
%17 = load i8*, i8** %6
%18 = load i32, i32* @O_RDWR
%19 = call i32 @open(i8* %17, i32 %18, i32 0)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %30
22: ; preds = %16
%23 = load i8*, i8** %6
%24 = load i32, i32* @errno
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %23, i32 %24, i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %16
%31 = load i32, i32* %7
%32 = load i32, i32* @VIDIOC_QUERYCAP
%33 = call i32 @ioctl(i32 %31, i32 %32, %struct.v4l2_capability* %8)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %42
35: ; preds = %30
%36 = load i32, i32* @errno
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %36, i8* %38)
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %30
%43 = getelementptr inbounds %struct.v4l2_capability, %struct.v4l2_capability* %8, i32 0, i32 0
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %44)
%46 = getelementptr inbounds %struct.v4l2_capability, %struct.v4l2_capability* %8, i32 0, i32 1
%47 = load i8*, i8** %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %47)
%49 = getelementptr inbounds %struct.v4l2_capability, %struct.v4l2_capability* %8, i32 0, i32 2
%50 = load i8*, i8** %49
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %50)
%52 = getelementptr inbounds %struct.v4l2_capability, %struct.v4l2_capability* %8, i32 0, i32 3
%53 = load i32, i32* %52
%54 = ashr i32 %53, 16
%55 = and i32 %54, 255
%56 = getelementptr inbounds %struct.v4l2_capability, %struct.v4l2_capability* %8, i32 0, i32 3
%57 = load i32, i32* %56
%58 = ashr i32 %57, 8
%59 = and i32 %58, 255
%60 = getelementptr inbounds %struct.v4l2_capability, %struct.v4l2_capability* %8, i32 0, i32 3
%61 = load i32, i32* %60
%62 = and i32 %61, 255
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %55, i32 %59, i32 %62)
%64 = getelementptr inbounds %struct.v4l2_capability, %struct.v4l2_capability* %8, i32 0, i32 4
%65 = load i32, i32* %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %65)
%67 = getelementptr inbounds %struct.v4l2_capability, %struct.v4l2_capability* %8, i32 0, i32 5
%68 = load i32, i32* %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i32 %68)
%70 = load i32, i32* %7
%71 = call i32 @close(i32 %70)
%72 = icmp eq i32 -1, %71
br i1 %72, label %73, label %80
73: ; preds = %42
%74 = load i32, i32* @errno
%75 = load i32, i32* @errno
%76 = call i8* @strerror(i32 %75)
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %74, i8* %76)
%78 = load i32, i32* @EXIT_FAILURE
%79 = call i32 @exit(i32 %78)
unreachable
80: ; preds = %42
store i32 -1, i32* %7
ret i32 0
}

LLVM IR (-O2):
%struct.v4l2_capability = type { i8*, i8*, i8*, i32, i32, i32 }
@.str = [12 x i8] c"/dev/video0\00"
@O_RDWR = global i32 0
@.str.1 = [17 x i8] c"%s error %d, %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@VIDIOC_QUERYCAP = global i32 0
@.str.2 = [32 x i8] c"\22VIDIOC_QUERYCAP\22 error %d, %s\0A\00"
@.str.3 = [13 x i8] c"driver : %s\0A\00"
@.str.4 = [11 x i8] c"card : %s\0A\00"
@.str.5 = [15 x i8] c"bus_info : %s\0A\00"
@.str.6 = [20 x i8] c"version : %d.%d.%d\0A\00"
@.str.7 = [22 x i8] c"capabilities: 0x%08x\0A\00"
@.str.8 = [29 x i8] c"device capabilities: 0x%08x\0A\00"
@.str.9 = [22 x i8] c"\22close\22 error %d, %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.v4l2_capability
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
br label %8
8: ; preds = %2, %5
%9 = phi i8* [ %7, %5 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %2 ]
%10 = load i32, i32* @O_RDWR
%11 = tail call i32 @open(i8* %9, i32 %10, i32 0)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32 %14, i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %8
%20 = bitcast %struct.v4l2_capability* %3 to i8*
%21 = load i32, i32* @VIDIOC_QUERYCAP
%22 = call i32 @ioctl(i32 %11, i32 %21, %struct.v4l2_capability* %3)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %30
24: ; preds = %19
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %25, i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %19
%31 = getelementptr inbounds %struct.v4l2_capability, %struct.v4l2_capability* %3, i64 0, i32 0
%32 = load i8*, i8** %31
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds %struct.v4l2_capability, %struct.v4l2_capability* %3, i64 0, i32 1
%35 = load i8*, i8** %34
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %35)
%37 = getelementptr inbounds %struct.v4l2_capability, %struct.v4l2_capability* %3, i64 0, i32 2
%38 = load i8*, i8** %37
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %38)
%40 = getelementptr inbounds %struct.v4l2_capability, %struct.v4l2_capability* %3, i64 0, i32 3
%41 = load i32, i32* %40
%42 = lshr i32 %41, 16
%43 = and i32 %42, 255
%44 = lshr i32 %41, 8
%45 = and i32 %44, 255
%46 = and i32 %41, 255
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %43, i32 %45, i32 %46)
%48 = getelementptr inbounds %struct.v4l2_capability, %struct.v4l2_capability* %3, i64 0, i32 4
%49 = load i32, i32* %48
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %49)
%51 = getelementptr inbounds %struct.v4l2_capability, %struct.v4l2_capability* %3, i64 0, i32 5
%52 = load i32, i32* %51
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i32 %52)
%54 = call i32 @close(i32 %11)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %62
56: ; preds = %30
%57 = load i32, i32* @errno
%58 = call i8* @strerror(i32 %57)
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %57, i8* %58)
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %30
ret i32 0
}