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

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
scalar_t__ popen(char *, char *);
int snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ stderr;
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
int get_video_resolution(const char *file, int *x, int *y) {
  FILE *pipe;
  char cmd[512];
  char line[20];
  int cmdsize;
  cmdsize = snprintf(cmd, sizeof(cmd),
                     "ffprobe -loglevel error "
                     "-show_streams %s | egrep 'width|height' | "
                     "cut -d= -f2",
                     file);
  if (cmdsize == -1 || cmdsize > ((int)sizeof(cmd))) {
    fprintf(stderr, "The video path is too long!\n");
    return 0;
  }
  if (!(pipe = (FILE *)popen(cmd, "r"))) {
    perror("Cannot open pipe");
    return 0;
  }
  if (!fgets(line, sizeof(line), pipe) ||
      (*x = (int)strtol(line, NULL, 10)) == 0) {
    perror("Cannot determine the width");
    return 0;
  }
  if (!fgets(line, sizeof(line), pipe) ||
      (*y = (int)strtol(line, NULL, 10)) == 0) {
    perror("Cannot determine the height");
    return 0;
  }
  pclose(pipe);
  return 1;
}


x86 assembly (clang, -O0):
<get_video_resolution>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x230(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x200,%esi
lea    0xe62(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x254(%rbp)
cmpl   $0xffffffff,-0x254(%rbp)
je     11c6 <get_video_resolution+0x56>
cmpl   $0x200,-0x254(%rbp)
jle    11e7 <get_video_resolution+0x77>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e4 <get_video_resolution+0x174>
lea    -0x230(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1220 <get_video_resolution+0xb0>
lea    0xe5e(%rip),%rdi
call   1090 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e4 <get_video_resolution+0x174>
lea    -0x250(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x14,%esi
call   1050 <fgets@plt>
cmp    $0x0,%eax
je     1262 <get_video_resolution+0xf2>
lea    -0x250(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    -0x18(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0x0,%eax
jne    127a <get_video_resolution+0x10a>
lea    0xe15(%rip),%rdi
call   1090 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e4 <get_video_resolution+0x174>
lea    -0x250(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x14,%esi
call   1050 <fgets@plt>
cmp    $0x0,%eax
je     12bc <get_video_resolution+0x14c>
lea    -0x250(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    -0x20(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0x0,%eax
jne    12d4 <get_video_resolution+0x164>
lea    0xdd6(%rip),%rdi
call   1090 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e4 <get_video_resolution+0x174>
mov    -0x28(%rbp),%rdi
call   1030 <pclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_video_resolution>:
push   %r15
push   %r14
push   %rbx
sub    $0x220,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rcx
lea    0xe74(%rip),%rdx
lea    0x20(%rsp),%rdi
mov    $0x200,%esi
call   1040 <snprintf@plt>
cmp    $0xffffffff,%eax
je     122f <get_video_resolution+0xbf>
cmp    $0x201,%eax
jge    122f <get_video_resolution+0xbf>
lea    0xeb5(%rip),%rsi
lea    0x20(%rsp),%rdi
call   1080 <popen@plt>
test   %rax,%rax
je     1258 <get_video_resolution+0xe8>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x14,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %eax,%eax
je     1246 <get_video_resolution+0xd6>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,(%r15)
test   %eax,%eax
je     1246 <get_video_resolution+0xd6>
mov    %rsp,%rdi
mov    $0x14,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %eax,%eax
je     124f <get_video_resolution+0xdf>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,(%r14)
test   %eax,%eax
je     124f <get_video_resolution+0xdf>
mov    %rbx,%rdi
call   1030 <pclose@plt>
mov    $0x1,%eax
jmp    1266 <get_video_resolution+0xf6>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1264 <get_video_resolution+0xf4>
lea    0xe31(%rip),%rdi
jmp    125f <get_video_resolution+0xef>
lea    0xe43(%rip),%rdi
jmp    125f <get_video_resolution+0xef>
lea    0xe0e(%rip),%rdi
call   1090 <perror@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [78 x i8] c"ffprobe -loglevel error -show_streams %s | egrep 'width|height' | cut -d= -f2\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"The video path is too long!\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [17 x i8] c"Cannot open pipe\00"
@.str.4 = [27 x i8] c"Cannot determine the width\00"
@.str.5 = [28 x i8] c"Cannot determine the height\00"
define i32 @get_video_resolution(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [512 x i8]
%10 = alloca [20 x i8]
%11 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%13 = load i8*, i8** %5
%14 = call i32 @snprintf(i8* %12, i32 512, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 %14, i32* %11
%15 = load i32, i32* %11
%16 = icmp eq i32 %15, -1
br i1 %16, label %20, label %17
17: ; preds = %3
%18 = load i32, i32* %11
%19 = icmp sgt i32 %18, 512
br i1 %19, label %20, label %23
20: ; preds = %17, %3
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %59
23: ; preds = %17
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%25 = call i64 @popen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = inttoptr i64 %25 to i32*
store i32* %26, i32** %8
%27 = icmp ne i32* %26, null
br i1 %27, label %30, label %28
28: ; preds = %23
%29 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %59
30: ; preds = %23
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%32 = load i32*, i32** %8
%33 = call i32 @fgets(i8* %31, i32 20, i32* %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %30
%36 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%37 = call i64 @strtol(i8* %36, i32* null, i32 10)
%38 = trunc i64 %37 to i32
%39 = load i32*, i32** %6
store i32 %38, i32* %39
%40 = icmp eq i32 %38, 0
br i1 %40, label %41, label %43
41: ; preds = %35, %30
%42 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %4
br label %59
43: ; preds = %35
%44 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%45 = load i32*, i32** %8
%46 = call i32 @fgets(i8* %44, i32 20, i32* %45)
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %54
48: ; preds = %43
%49 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%50 = call i64 @strtol(i8* %49, i32* null, i32 10)
%51 = trunc i64 %50 to i32
%52 = load i32*, i32** %7
store i32 %51, i32* %52
%53 = icmp eq i32 %51, 0
br i1 %53, label %54, label %56
54: ; preds = %48, %43
%55 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %4
br label %59
56: ; preds = %48
%57 = load i32*, i32** %8
%58 = call i32 @pclose(i32* %57)
store i32 1, i32* %4
br label %59
59: ; preds = %56, %54, %41, %28, %20
%60 = load i32, i32* %4
ret i32 %60
}

LLVM IR (-O2):
@.str = [78 x i8] c"ffprobe -loglevel error -show_streams %s | egrep 'width|height' | cut -d= -f2\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"The video path is too long!\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [17 x i8] c"Cannot open pipe\00"
@.str.4 = [27 x i8] c"Cannot determine the width\00"
@.str.5 = [28 x i8] c"Cannot determine the height\00"
define i32 @get_video_resolution(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca [512 x i8]
%5 = alloca [20 x i8]
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%8 = call i32 @snprintf(i8* %6, i32 512, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = icmp eq i32 %8, -1
%10 = icmp sgt i32 %8, 512
%11 = or i1 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %41
15: ; preds = %3
%16 = call i64 @popen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = inttoptr i64 %16 to i32*
%18 = icmp eq i64 %16, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %41
21: ; preds = %15
%22 = call i32 @fgets(i8* %7, i32 20, i32* %17)
%23 = icmp eq i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = call i64 @strtol(i8* nocapture %7, i32* null, i32 10)
%26 = trunc i64 %25 to i32
store i32 %26, i32* %1
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24, %21
%29 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %41
30: ; preds = %24
%31 = call i32 @fgets(i8* %7, i32 20, i32* %17)
%32 = icmp eq i32 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %30
%34 = call i64 @strtol(i8* nocapture %7, i32* null, i32 10)
%35 = trunc i64 %34 to i32
store i32 %35, i32* %2
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %33, %30
%38 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %41
39: ; preds = %33
%40 = call i32 @pclose(i32* %17)
br label %41
41: ; preds = %39, %37, %28, %19, %12
%42 = phi i32 [ 0, %12 ], [ 0, %28 ], [ 0, %37 ], [ 1, %39 ], [ 0, %19 ]
ret i32 %42
}