#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*/ str_duration;

/* Variables and functions */
int get_shell_stdout(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
scalar_t__ strtof(char *, int /*<<< orphan*/ *);
int get_file_duration(const char *file_name) {
  int ret = 0, i_duration = 0;
  char cmd[(256)] = {0}, str_duration[(256)] = {0};
  if (file_name == NULL)
    return -1;
  sprintf(cmd,
          "ffprobe -i %s -show_format -v quiet | sed -n \'s/duration=//p\'",
          file_name);
  ret = get_shell_stdout(cmd, str_duration, sizeof(str_duration));
  if (ret < 0) {
    printf("###ERR: Exec Cmd Err.\r\n");
    return -2;
  }
  i_duration = (int)strtof(str_duration, NULL);
  printf("%d\r\n", i_duration);
  return i_duration;
}


x86 assembly (clang, -O0):
<get_file_duration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11aa <get_file_duration+0x5a>
movl   $0xffffffff,-0x4(%rbp)
jmp    122a <get_file_duration+0xda>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe44(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x120(%rbp),%rdi
lea    -0x220(%rbp),%rsi
mov    $0x100,%edx
call   1060 <get_shell_stdout@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1200 <get_file_duration+0xb0>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    122a <get_file_duration+0xda>
lea    -0x220(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <strtof@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_duration>:
push   %rbx
sub    $0x200,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
test   %rdi,%rdi
je     1294 <get_file_duration+0x144>
mov    %rdi,%rdx
lea    0xdaf(%rip),%rsi
lea    0x100(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x100,%edx
call   1060 <get_shell_stdout@plt>
test   %eax,%eax
js     129b <get_file_duration+0x14b>
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <strtof@plt>
mov    %rax,%rbx
lea    0xdb5(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12ac <get_file_duration+0x15c>
mov    $0xffffffff,%ebx
jmp    12ac <get_file_duration+0x15c>
lea    0xda1(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%ebx
mov    %ebx,%eax
add    $0x200,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [62 x i8] c"ffprobe -i %s -show_format -v quiet | sed -n 's/duration=//p'\00"
@.str.1 = [24 x i8] c"###ERR: Exec Cmd Err.\0D\0A\00"
@.str.2 = [5 x i8] c"%d\0D\0A\00"
define i32 @get_file_duration(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
store i8* %0, i8** %3
store i32 0, i32* %4
store i32 0, i32* %5
%8 = bitcast [256 x i8]* %6 to i8*
%9 = bitcast [256 x i8]* %7 to i8*
%10 = load i8*, i8** %3
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %31
13: ; preds = %1
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%15 = load i8*, i8** %3
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%19 = call i32 @get_shell_stdout(i8* %17, i8* %18, i32 256)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %13
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %2
br label %31
24: ; preds = %13
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%26 = call i64 @strtof(i8* %25, i32* null)
%27 = trunc i64 %26 to i32
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %5
store i32 %30, i32* %2
br label %31
31: ; preds = %24, %22, %12
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@.str = [62 x i8] c"ffprobe -i %s -show_format -v quiet | sed -n 's/duration=//p'\00"
@.str.2 = [5 x i8] c"%d\0D\0A\00"
@str = [23 x i8] c"###ERR: Exec Cmd Err.\0D\00"
define i32 @get_file_duration(i8* %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = icmp eq i8* %0, null
br i1 %6, label %17, label %7
7: ; preds = %1
%8 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = call i32 @get_shell_stdout(i8* %4, i8* %5, i32 256)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %17
13: ; preds = %7
%14 = call i64 @strtof(i8* nocapture %5, i32* null)
%15 = trunc i64 %14 to i32
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %1, %13, %11
%18 = phi i32 [ -2, %11 ], [ %15, %13 ], [ -1, %1 ]
ret i32 %18
}