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

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
int /*<<< orphan*/ strncmp(char *, char *, int);
double strtod(char *, int /*<<< orphan*/ *);
int system(char *);
double get_fps(const char *uri) {
  int rc;
  double ret = -1;
  const char *binary;
  char buffer[1024];
  char cmd[1024];
  ssize_t bytes;
  FILE *fp;
  rc = system("which "
              "mplayer2");
  if (rc == 0) {
    binary = "mplayer2";
    goto found_player;
  }
  rc = system("which "
              "mplayer");
  if (rc == 0) {
    binary = "mplayer";
    goto found_player;
  }
  rc = system("which "
              "mpv");
  if (rc == 0) {
    binary = "mpv";
    goto found_player;
  }
  goto exit;
found_player:
  snprintf(cmd, 1024,
           "LANGUAGE=en LANG=en %s \"%s\" -identify -frames 0 2>/dev/null | "
           "grep ID_VIDEO_FPS",
           binary, uri);
  fp = popen(cmd, "r");
  fgets(buffer, 1024, fp);
  if (!(strncmp(buffer, "ID_VIDEO_FPS=", 13))) {
    ret = strtod(buffer + 13, NULL);
  }
  pclose(fp);
exit:
  return ret;
}


x86 assembly (clang, -O0):
<get_fps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
movsd  0xe79(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    0xe75(%rip),%rdi
call   1050 <system@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11b5 <get_fps+0x45>
lea    0xe62(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    120c <get_fps+0x9c>
lea    0xe5b(%rip),%rdi
call   1050 <system@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11de <get_fps+0x6e>
lea    0xe48(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    120c <get_fps+0x9c>
lea    0xe40(%rip),%rdi
call   1050 <system@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1207 <get_fps+0x97>
lea    0xe2d(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    120c <get_fps+0x9c>
jmp    12a4 <get_fps+0x134>
lea    -0x820(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%r8
mov    $0x400,%esi
lea    0xe08(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x820(%rbp),%rdi
lea    0xde9(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x830(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x830(%rbp),%rdx
mov    $0x400,%esi
call   1080 <fgets@plt>
lea    -0x420(%rbp),%rdi
lea    0xe13(%rip),%rsi
mov    $0xd,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1298 <get_fps+0x128>
lea    -0x420(%rbp),%rdi
add    $0xd,%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <strtod@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x830(%rbp),%rdi
call   1060 <pclose@plt>
movsd  -0x18(%rbp),%xmm0
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_fps>:
push   %r14
push   %rbx
sub    $0x818,%rsp
mov    %rdi,%r14
lea    0xe84(%rip),%rdi
call   1050 <system@plt>
test   %eax,%eax
je     11ba <get_fps+0x4a>
lea    0xe83(%rip),%rdi
call   1050 <system@plt>
test   %eax,%eax
je     11c3 <get_fps+0x53>
lea    0xe81(%rip),%rdi
call   1050 <system@plt>
test   %eax,%eax
je     11cc <get_fps+0x5c>
movsd  0xe4b(%rip),%xmm0
jmp    125b <get_fps+0xeb>
lea    0xe4d(%rip),%rcx
jmp    11d3 <get_fps+0x63>
lea    0xe53(%rip),%rcx
jmp    11d3 <get_fps+0x63>
lea    0xe58(%rip),%rcx
lea    0xe55(%rip),%rdx
lea    0x410(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%r8
call   1070 <snprintf@plt>
lea    0xe2a(%rip),%rsi
mov    %rbx,%rdi
call   1090 <popen@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
lea    0xe5f(%rip),%rsi
mov    %r14,%rdi
mov    $0xd,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     123b <get_fps+0xcb>
movsd  0xdc7(%rip),%xmm0
jmp    1247 <get_fps+0xd7>
lea    0x1d(%rsp),%rdi
xor    %esi,%esi
call   1040 <strtod@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1060 <pclose@plt>
movsd  0x8(%rsp),%xmm0
add    $0x818,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [15 x i8] c"which mplayer2\00"
@.str.1 = [9 x i8] c"mplayer2\00"
@.str.2 = [14 x i8] c"which mplayer\00"
@.str.3 = [8 x i8] c"mplayer\00"
@.str.4 = [10 x i8] c"which mpv\00"
@.str.5 = [4 x i8] c"mpv\00"
@.str.6 = [80 x i8] c"LANGUAGE=en LANG=en %s \22%s\22 -identify -frames 0 2>/dev/null | grep ID_VIDEO_FPS\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [14 x i8] c"ID_VIDEO_FPS=\00"
define double @get_fps(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca double
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32*
store i8* %0, i8** %2
store double -1.000000e+00, double* %4
%10 = call i32 @system(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8** %5
br label %25
14: ; preds = %1
%15 = call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %5
br label %25
19: ; preds = %14
%20 = call i32 @system(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8** %5
br label %25
24: ; preds = %19
br label %45
25: ; preds = %23, %18, %13
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%27 = load i8*, i8** %5
%28 = load i8*, i8** %2
%29 = call i32 @snprintf(i8* %26, i32 1024, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.6, i64 0, i64 0), i8* %27, i8* %28)
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%31 = call i32* @popen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %31, i32** %9
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%33 = load i32*, i32** %9
%34 = call i32 @fgets(i8* %32, i32 1024, i32* %33)
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%36 = call i32 @strncmp(i8* %35, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32 13)
%37 = icmp ne i32 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %25
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%40 = getelementptr inbounds i8, i8* %39, i64 13
%41 = call double @strtod(i8* %40, i32* null)
store double %41, double* %4
br label %42
42: ; preds = %38, %25
%43 = load i32*, i32** %9
%44 = call i32 @pclose(i32* %43)
br label %45
45: ; preds = %42, %24
%46 = load double, double* %4
ret double %46
}

LLVM IR (-O2):
@.str = [15 x i8] c"which mplayer2\00"
@.str.1 = [9 x i8] c"mplayer2\00"
@.str.2 = [14 x i8] c"which mplayer\00"
@.str.3 = [8 x i8] c"mplayer\00"
@.str.4 = [10 x i8] c"which mpv\00"
@.str.5 = [4 x i8] c"mpv\00"
@.str.6 = [80 x i8] c"LANGUAGE=en LANG=en %s \22%s\22 -identify -frames 0 2>/dev/null | grep ID_VIDEO_FPS\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [14 x i8] c"ID_VIDEO_FPS=\00"
define double @get_fps(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = tail call i32 @system(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %1
%9 = tail call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = tail call i32 @system(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %11, %8, %1
%15 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %1 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), %8 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), %11 ]
%16 = call i32 @snprintf(i8* %5, i32 1024, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.6, i64 0, i64 0), i8* %15, i8* %0)
%17 = call i32* @popen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%18 = call i32 @fgets(i8* %4, i32 1024, i32* %17)
%19 = call i32 @strncmp(i8* %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32 13)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 13
%23 = call double @strtod(i8* nocapture %22, i32* null)
br label %24
24: ; preds = %21, %14
%25 = phi double [ -1.000000e+00, %14 ], [ %23, %21 ]
%26 = call i32 @pclose(i32* %17)
br label %27
27: ; preds = %11, %24
%28 = phi double [ %25, %24 ], [ -1.000000e+00, %11 ]
ret double %28
}