#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int w;
  int h;
  int aspect_ratio;
};
typedef TYPE_1__ video_size_t;

/* Variables and functions */
#define VIDEO_FORMAT_16_9 130
#define VIDEO_FORMAT_221_1 129
#define VIDEO_FORMAT_4_3 128
int /*<<< orphan*/ VIDEO_GET_SIZE;
int ioctl(int, int /*<<< orphan*/, TYPE_1__ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int videoGetSize(int fd, char *arg) {
  video_size_t size;
  if (arg)
    return -1;
  if (ioctl(fd, VIDEO_GET_SIZE, &size) == -1) {
    perror("VIDEO_GET_SIZE");
    return 0;
  }
  printf("Video Size: %ux%u ", size.w, size.h);
  switch (size.aspect_ratio) {
  case VIDEO_FORMAT_4_3:
    printf("4:3 (%d)\n", size.aspect_ratio);
    break;
  case VIDEO_FORMAT_16_9:
    printf("16:9 (%d)\n", size.aspect_ratio);
    break;
  case VIDEO_FORMAT_221_1:
    printf("2.21:1 (%d)\n", size.aspect_ratio);
    break;
  default:
    printf("unknown aspect ratio (%d)\n", size.aspect_ratio);
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<videoGetSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1156 <videoGetSize+0x26>
movl   $0xffffffff,-0x4(%rbp)
jmp    1236 <videoGetSize+0x106>
mov    -0x8(%rbp),%edi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    118c <videoGetSize+0x5c>
lea    0xe85(%rip),%rdi
call   1050 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1236 <videoGetSize+0x106>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe76(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x80,%eax
je     11dc <videoGetSize+0xac>
jmp    11b6 <videoGetSize+0x86>
mov    -0x24(%rbp),%eax
sub    $0x81,%eax
je     1208 <videoGetSize+0xd8>
jmp    11c9 <videoGetSize+0x99>
mov    -0x24(%rbp),%eax
sub    $0x82,%eax
je     11f2 <videoGetSize+0xc2>
jmp    121e <videoGetSize+0xee>
mov    -0x18(%rbp),%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122f <videoGetSize+0xff>
mov    -0x18(%rbp),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122f <videoGetSize+0xff>
mov    -0x18(%rbp),%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122f <videoGetSize+0xff>
mov    -0x18(%rbp),%esi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<videoGetSize>:
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffff,%ebx
test   %rsi,%rsi
jne    11ca <videoGetSize+0x9a>
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     11d2 <videoGetSize+0xa2>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xea8(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x8(%rsp),%esi
cmp    $0x82,%esi
je     119c <videoGetSize+0x6c>
cmp    $0x81,%esi
je     11aa <videoGetSize+0x7a>
cmp    $0x80,%esi
jne    11ba <videoGetSize+0x8a>
lea    0xe8f(%rip),%rdi
xor    %ebx,%ebx
mov    $0x80,%esi
jmp    11c3 <videoGetSize+0x93>
lea    0xe89(%rip),%rdi
mov    $0x82,%esi
jmp    11c3 <videoGetSize+0x93>
lea    0xe86(%rip),%rdi
xor    %ebx,%ebx
mov    $0x81,%esi
jmp    11c3 <videoGetSize+0x93>
lea    0xe83(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe27(%rip),%rdi
call   1050 <perror@plt>
xor    %ebx,%ebx
jmp    11ca <videoGetSize+0x9a>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32, i32 }
@VIDEO_GET_SIZE = global i32 0
@.str = [15 x i8] c"VIDEO_GET_SIZE\00"
@.str.1 = [19 x i8] c"Video Size: %ux%u \00"
@.str.2 = [10 x i8] c"4:3 (%d)\0A\00"
@.str.3 = [11 x i8] c"16:9 (%d)\0A\00"
@.str.4 = [13 x i8] c"2.21:1 (%d)\0A\00"
@.str.5 = [27 x i8] c"unknown aspect ratio (%d)\0A\00"
define i32 @videoGetSize(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.TYPE_3__
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 -1, i32* %3
br label %42
10: ; preds = %2
%11 = load i32, i32* %4
%12 = load i32, i32* @VIDEO_GET_SIZE
%13 = call i32 @ioctl(i32 %11, i32 %12, %struct.TYPE_3__* %6)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %42
17: ; preds = %10
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 1
%21 = load i32, i32* %20
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %21)
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 2
%24 = load i32, i32* %23
switch i32 %24, label %37 [
i32 128, label %25
i32 130, label %29
i32 129, label %33
]
25: ; preds = %17
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 2
%27 = load i32, i32* %26
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %41
29: ; preds = %17
%30 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 2
%31 = load i32, i32* %30
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %31)
br label %41
33: ; preds = %17
%34 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 2
%35 = load i32, i32* %34
%36 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %35)
br label %41
37: ; preds = %17
%38 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 2
%39 = load i32, i32* %38
%40 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %37, %33, %29, %25
store i32 0, i32* %3
br label %42
42: ; preds = %41, %15, %9
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32, i32 }
@VIDEO_GET_SIZE = global i32 0
@.str = [15 x i8] c"VIDEO_GET_SIZE\00"
@.str.1 = [19 x i8] c"Video Size: %ux%u \00"
@.str.2 = [10 x i8] c"4:3 (%d)\0A\00"
@.str.3 = [11 x i8] c"16:9 (%d)\0A\00"
@.str.4 = [13 x i8] c"2.21:1 (%d)\0A\00"
@.str.5 = [27 x i8] c"unknown aspect ratio (%d)\0A\00"
define i32 @videoGetSize(i32 %0, i8* readnone %1) {
%3 = alloca %struct.TYPE_3__
%4 = bitcast %struct.TYPE_3__* %3 to i8*
%5 = icmp eq i8* %1, null
br i1 %5, label %6, label %28
6: ; preds = %2
%7 = load i32, i32* @VIDEO_GET_SIZE
%8 = call i32 @ioctl(i32 %0, i32 %7, %struct.TYPE_3__* %3)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %28
12: ; preds = %6
%13 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 0
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 1
%16 = load i32, i32* %15
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %16)
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 2
%19 = load i32, i32* %18
switch i32 %19, label %26 [
i32 128, label %20
i32 130, label %22
i32 129, label %24
]
20: ; preds = %12
%21 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 128)
br label %28
22: ; preds = %12
%23 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 130)
br label %28
24: ; preds = %12
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 129)
br label %28
26: ; preds = %12
%27 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %19)
br label %28
28: ; preds = %20, %22, %24, %26, %2, %10
%29 = phi i32 [ 0, %10 ], [ -1, %2 ], [ 0, %26 ], [ 0, %24 ], [ 0, %22 ], [ 0, %20 ]
ret i32 %29
}