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

/* Variables and functions */
int get_cut_part(int);
int get_file_duration(char *);
int get_file_size(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, int, int, int, int,
                           char *);
int system(char *);
int main(int argc, char **argv) {
  char cmd[(256)] = {0};
  int duration = 0, i_size;
  int hh = 0, mm = 0, ss = 0, ret = 0, ms = 0, part = 0, part_index = 1,
      time_len = 0;
  char *file_name = NULL;
  if (argc != 2) {
    printf("###INFO: Please Chech Input Parm Again.\r\n");
    printf("example: ./prog sample.mp3\r\n");
    return -1;
  }
  file_name = argv[1];
  i_size = get_file_size(file_name);
  if (i_size < 0) {
    printf("###ERR: Get File Size Err.\r\n");
    return -2;
  }
  part = get_cut_part(i_size);
  if (part < 0) {
    printf("###ERR: Get Cut Part Err.\r\n");
    return -3;
  }
  duration = get_file_duration(file_name);
  if (duration < 0) {
    printf("###ERR: Get File Duration Err.\r\n");
    return -4;
  }
  time_len = duration / (60) / part;
  for (hh = 0, mm = 0, ss = 0, part_index = 1; part_index < part;
       hh = mm / 60, ms = mm - hh * 60, mm += time_len, part_index++) {
    sprintf(cmd,
            "ffmpeg -i %s -ss %d:%d:%d -t 00:%d:00 -vcodec copy -acodec copy "
            "Part%d-%s",
            file_name, hh, ms, ss, time_len, part_index, file_name);
    ret = system(cmd);
    if (ret < 0) {
      printf("###ERR: Exec Cmd Err.\r\n");
      return -5;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
movl   $0x0,-0x114(%rbp)
movl   $0x0,-0x11c(%rbp)
movl   $0x0,-0x120(%rbp)
movl   $0x0,-0x124(%rbp)
movl   $0x0,-0x128(%rbp)
movl   $0x0,-0x12c(%rbp)
movl   $0x0,-0x130(%rbp)
movl   $0x1,-0x134(%rbp)
movl   $0x0,-0x138(%rbp)
movq   $0x0,-0x140(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     122f <main+0xbf>
lea    0xdee(%rip),%rdi
call   1060 <printf@plt>
lea    0xe0c(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    141a <main+0x2aa>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x140(%rbp)
mov    -0x140(%rbp),%rdi
call   1080 <get_file_size@plt>
mov    %eax,-0x118(%rbp)
cmpl   $0x0,-0x118(%rbp)
jge    1275 <main+0x105>
lea    0xde3(%rip),%rdi
call   1060 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    141a <main+0x2aa>
mov    -0x118(%rbp),%edi
call   1030 <get_cut_part@plt>
mov    %eax,-0x130(%rbp)
cmpl   $0x0,-0x130(%rbp)
jge    12ab <main+0x13b>
lea    0xdca(%rip),%rdi
call   1060 <printf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    141a <main+0x2aa>
mov    -0x140(%rbp),%rdi
call   1040 <get_file_duration@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jge    12e2 <main+0x172>
lea    0xdaf(%rip),%rdi
call   1060 <printf@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    141a <main+0x2aa>
mov    -0x114(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
cltd
idivl  -0x130(%rbp)
mov    %eax,-0x138(%rbp)
movl   $0x0,-0x11c(%rbp)
movl   $0x0,-0x120(%rbp)
movl   $0x0,-0x124(%rbp)
movl   $0x1,-0x134(%rbp)
mov    -0x134(%rbp),%eax
cmp    -0x130(%rbp),%eax
jge    1413 <main+0x2a3>
lea    -0x110(%rbp),%rdi
mov    -0x140(%rbp),%rdx
mov    -0x11c(%rbp),%ecx
mov    -0x12c(%rbp),%r8d
mov    -0x124(%rbp),%r9d
mov    -0x138(%rbp),%r11d
mov    -0x134(%rbp),%r10d
mov    -0x140(%rbp),%rax
lea    0xd2c(%rip),%rsi
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1090 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1050 <system@plt>
mov    %eax,-0x128(%rbp)
cmpl   $0x0,-0x128(%rbp)
jge    13bf <main+0x24f>
lea    0xd3d(%rip),%rdi
call   1060 <printf@plt>
movl   $0xfffffffb,-0x4(%rbp)
jmp    141a <main+0x2aa>
jmp    13c4 <main+0x254>
mov    -0x120(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x11c(%rbp)
mov    -0x120(%rbp),%eax
imul   $0x3c,-0x11c(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x12c(%rbp)
mov    -0x138(%rbp),%eax
add    -0x120(%rbp),%eax
mov    %eax,-0x120(%rbp)
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
jmp    1325 <main+0x1b5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
xorps  %xmm0,%xmm0
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)
cmp    $0x2,%edi
jne    12ba <main+0x15a>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1070 <get_file_size@plt>
test   %eax,%eax
js     12d5 <main+0x175>
mov    %eax,%edi
call   1030 <get_cut_part@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
js     12e4 <main+0x184>
mov    %rbx,%rdi
call   1050 <get_file_duration@plt>
test   %eax,%eax
js     12f3 <main+0x193>
mov    %eax,%eax
mov    $0x88888889,%ecx
imul   %rcx,%rax
shr    $0x25,%rax
xor    %r12d,%r12d
xor    %edx,%edx
mov    0xc(%rsp),%ecx
div    %ecx
cmp    $0x2,%ecx
jb     1314 <main+0x1b4>
mov    %eax,%r15d
xor    %r8d,%r8d
mov    $0x1,%r13d
xor    %r14d,%r14d
xor    %ecx,%ecx
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
sub    $0x8,%rsp
lea    0x18(%rsp),%rbp
mov    %rbp,%rdi
lea    0xd8d(%rip),%rsi
mov    %rbx,%rdx
xor    %r9d,%r9d
push   %rbx
push   %r13
push   %r15
call   1080 <sprintf@plt>
add    $0x20,%rsp
mov    %rbp,%rdi
call   1060 <system@plt>
test   %eax,%eax
js     1302 <main+0x1a2>
mov    %r14d,%ecx
mov    $0x88888889,%eax
imul   %rax,%rcx
shr    $0x25,%rcx
imul   $0xffffffc4,%ecx,%r8d
add    %r14d,%r8d
add    %r15d,%r14d
add    $0x1,%r13d
cmp    %r13d,0xc(%rsp)
jne    1260 <main+0x100>
jmp    1314 <main+0x1b4>
lea    0xdf7(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%r12d
lea    0xe0e(%rip),%rdi
jmp    130f <main+0x1af>
mov    $0xfffffffe,%r12d
lea    0xdba(%rip),%rdi
jmp    130f <main+0x1af>
mov    $0xfffffffd,%r12d
lea    0xd90(%rip),%rdi
jmp    130f <main+0x1af>
mov    $0xfffffffc,%r12d
lea    0xd61(%rip),%rdi
jmp    130f <main+0x1af>
mov    $0xfffffffb,%r12d
lea    0xd3b(%rip),%rdi
call   1040 <puts@plt>
mov    %r12d,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"###INFO: Please Chech Input Parm Again.\0D\0A\00"
@.str.1 = [29 x i8] c"example: ./prog sample.mp3\0D\0A\00"
@.str.2 = [29 x i8] c"###ERR: Get File Size Err.\0D\0A\00"
@.str.3 = [28 x i8] c"###ERR: Get Cut Part Err.\0D\0A\00"
@.str.4 = [33 x i8] c"###ERR: Get File Duration Err.\0D\0A\00"
@.str.5 = [74 x i8] c"ffmpeg -i %s -ss %d:%d:%d -t 00:%d:00 -vcodec copy -acodec copy Part%d-%s\00"
@.str.6 = [24 x i8] c"###ERR: Exec Cmd Err.\0D\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = bitcast [256 x i8]* %6 to i8*
store i32 0, i32* %7
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 1, i32* %15
store i32 0, i32* %16
store i8* null, i8** %17
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 2
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %87
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
store i8* %27, i8** %17
%28 = load i8*, i8** %17
%29 = call i32 @get_file_size(i8* %28)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %24
%33 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 -2, i32* %3
br label %87
34: ; preds = %24
%35 = load i32, i32* %8
%36 = call i32 @get_cut_part(i32 %35)
store i32 %36, i32* %14
%37 = load i32, i32* %14
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
store i32 -3, i32* %3
br label %87
41: ; preds = %34
%42 = load i8*, i8** %17
%43 = call i32 @get_file_duration(i8* %42)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
store i32 -4, i32* %3
br label %87
48: ; preds = %41
%49 = load i32, i32* %7
%50 = sdiv i32 %49, 60
%51 = load i32, i32* %14
%52 = sdiv i32 %50, %51
store i32 %52, i32* %16
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 1, i32* %15
br label %53
53: ; preds = %74, %48
%54 = load i32, i32* %15
%55 = load i32, i32* %14
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %86
57: ; preds = %53
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%59 = load i8*, i8** %17
%60 = load i32, i32* %9
%61 = load i32, i32* %13
%62 = load i32, i32* %11
%63 = load i32, i32* %16
%64 = load i32, i32* %15
%65 = load i8*, i8** %17
%66 = call i32 @sprintf(i8* %58, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.5, i64 0, i64 0), i8* %59, i32 %60, i32 %61, i32 %62, i32 %63, i32 %64, i8* %65)
%67 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%68 = call i32 @system(i8* %67)
store i32 %68, i32* %12
%69 = load i32, i32* %12
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %57
%72 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
store i32 -5, i32* %3
br label %87
73: ; preds = %57
br label %74
74: ; preds = %73
%75 = load i32, i32* %10
%76 = sdiv i32 %75, 60
store i32 %76, i32* %9
%77 = load i32, i32* %10
%78 = load i32, i32* %9
%79 = mul nsw i32 %78, 60
%80 = sub nsw i32 %77, %79
store i32 %80, i32* %13
%81 = load i32, i32* %16
%82 = load i32, i32* %10
%83 = add nsw i32 %82, %81
store i32 %83, i32* %10
%84 = load i32, i32* %15
%85 = add nsw i32 %84, 1
store i32 %85, i32* %15
br label %53
86: ; preds = %53
store i32 0, i32* %3
br label %87
87: ; preds = %86, %71, %46, %39, %32, %21
%88 = load i32, i32* %3
ret i32 %88
}

LLVM IR (-O2):
@.str.5 = [74 x i8] c"ffmpeg -i %s -ss %d:%d:%d -t 00:%d:00 -vcodec copy -acodec copy Part%d-%s\00"
@str = [23 x i8] c"###ERR: Exec Cmd Err.\0D\00"
@str.7 = [32 x i8] c"###ERR: Get File Duration Err.\0D\00"
@str.8 = [27 x i8] c"###ERR: Get Cut Part Err.\0D\00"
@str.9 = [28 x i8] c"###ERR: Get File Size Err.\0D\00"
@str.10 = [41 x i8] c"###INFO: Please Chech Input Parm Again.\0D\00"
@str.11 = [28 x i8] c"example: ./prog sample.mp3\0D\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.10, i64 0, i64 0))
br label %38
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @get_file_size(i8* %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %38, label %13
13: ; preds = %8
%14 = tail call i32 @get_cut_part(i32 %11)
%15 = icmp slt i32 %14, 0
br i1 %15, label %38, label %16
16: ; preds = %13
%17 = tail call i32 @get_file_duration(i8* %10)
%18 = icmp slt i32 %17, 0
br i1 %18, label %38, label %19
19: ; preds = %16
%20 = udiv i32 %17, 60
%21 = udiv i32 %20, %14
%22 = icmp ugt i32 %14, 1
br i1 %22, label %23, label %42
23: ; preds = %19, %31
%24 = phi i32 [ %36, %31 ], [ 1, %19 ]
%25 = phi i32 [ %34, %31 ], [ 0, %19 ]
%26 = phi i32 [ %35, %31 ], [ 0, %19 ]
%27 = phi i32 [ %32, %31 ], [ 0, %19 ]
%28 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @.str.5, i64 0, i64 0), i8* %10, i32 %27, i32 %25, i32 0, i32 %21, i32 %24, i8* %10)
%29 = call i32 @system(i8* %4)
%30 = icmp slt i32 %29, 0
br i1 %30, label %38, label %31
31: ; preds = %23
%32 = udiv i32 %26, 60
%33 = mul nsw i32 %32, -60
%34 = add i32 %33, %26
%35 = add nuw nsw i32 %26, %21
%36 = add nuw nsw i32 %24, 1
%37 = icmp eq i32 %36, %14
br i1 %37, label %42, label %23
38: ; preds = %23, %16, %13, %8, %6
%39 = phi i8* [ getelementptr inbounds ([28 x i8], [28 x i8]* @str.11, i64 0, i64 0), %6 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @str.9, i64 0, i64 0), %8 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @str.8, i64 0, i64 0), %13 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @str.7, i64 0, i64 0), %16 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0), %23 ]
%40 = phi i32 [ -1, %6 ], [ -2, %8 ], [ -3, %13 ], [ -4, %16 ], [ -5, %23 ]
%41 = tail call i32 @puts(i8* dereferenceable(1) %39)
br label %42
42: ; preds = %31, %38, %19
%43 = phi i32 [ 0, %19 ], [ %40, %38 ], [ 0, %31 ]
ret i32 %43
}