#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fget_u16(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *fp;
  unsigned width, height, count;
  fp = fopen("cons.shp", "rb");
  if (!fp)
    return -1;
  if (fget_u16(fp)) {
    printf("The file 'cons.shp' is not an shp(ts) video file!\nAborted.\n");
    return -2;
  }
  width = fget_u16(fp);
  height = fget_u16(fp);
  count = fget_u16(fp);
  fclose(fp);
  printf("The header of the shp(ts) video 'cons.shp' indicates that:\nPer "
         "image:\nWidth: %u pixel(s)\nHeight: %u pixel(s)\n\n%u frame(s) "
         "included.\n",
         width, height, count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117d <main+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f4 <main+0xb4>
mov    -0x10(%rbp),%rdi
call   1050 <fget_u16@plt>
cmp    $0x0,%eax
je     11a9 <main+0x69>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11f4 <main+0xb4>
mov    -0x10(%rbp),%rdi
call   1050 <fget_u16@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fget_u16@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fget_u16@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xea2(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1191 <main+0x41>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <fget_u16@plt>
test   %eax,%eax
je     1198 <main+0x48>
lea    0xf0c(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%ebx
jmp    11d8 <main+0x88>
mov    $0xffffffff,%ebx
jmp    11d8 <main+0x88>
mov    %rbx,%rdi
call   1060 <fget_u16@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1060 <fget_u16@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1060 <fget_u16@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe45(%rip),%rdi
xor    %ebx,%ebx
mov    %r14d,%esi
mov    %r15d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"cons.shp\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [60 x i8] c"The file 'cons.shp' is not an shp(ts) video file!\0AAborted.\0A\00"
@.str.3 = [133 x i8] c"The header of the shp(ts) video 'cons.shp' indicates that:\0APer image:\0AWidth: %u pixel(s)\0AHeight: %u pixel(s)\0A\0A%u frame(s) included.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp ne i32* %7, null
br i1 %8, label %10, label %9
9: ; preds = %0
store i32 -1, i32* %1
br label %29
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = call i32 @fget_u16(i32* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0))
store i32 -2, i32* %1
br label %29
16: ; preds = %10
%17 = load i32*, i32** %2
%18 = call i32 @fget_u16(i32* %17)
store i32 %18, i32* %3
%19 = load i32*, i32** %2
%20 = call i32 @fget_u16(i32* %19)
store i32 %20, i32* %4
%21 = load i32*, i32** %2
%22 = call i32 @fget_u16(i32* %21)
store i32 %22, i32* %5
%23 = load i32*, i32** %2
%24 = call i32 @fclose(i32* %23)
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = load i32, i32* %5
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 %26, i32 %27)
store i32 0, i32* %1
br label %29
29: ; preds = %16, %14, %9
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [9 x i8] c"cons.shp\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.3 = [133 x i8] c"The header of the shp(ts) video 'cons.shp' indicates that:\0APer image:\0AWidth: %u pixel(s)\0AHeight: %u pixel(s)\0A\0A%u frame(s) included.\0A\00"
@str = [59 x i8] c"The file 'cons.shp' is not an shp(ts) video file!\0AAborted.\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %14, label %3
3: ; preds = %0
%4 = tail call i32 @fget_u16(i32* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str, i64 0, i64 0))
br label %14
8: ; preds = %3
%9 = tail call i32 @fget_u16(i32* %1)
%10 = tail call i32 @fget_u16(i32* %1)
%11 = tail call i32 @fget_u16(i32* %1)
%12 = tail call i32 @fclose(i32* %1)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([133 x i8], [133 x i8]* @.str.3, i64 0, i64 0), i32 %9, i32 %10, i32 %11)
br label %14
14: ; preds = %0, %8, %6
%15 = phi i32 [ -2, %6 ], [ 0, %8 ], [ -1, %0 ]
ret i32 %15
}