#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 */
char **calloc(size_t, int);
int /*<<< orphan*/ errno;
scalar_t__ execvp(char *, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int /*<<< orphan*/ free(char const **);
scalar_t__ push_back(size_t *, size_t *, char const ***, char *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
char *strerror(int /*<<< orphan*/);
int handle_play(char *out) {
  size_t size = 0;
  size_t capacity = 8;
  const char **argv = calloc(capacity, sizeof(char *));
  if (!argv) {
    fprintf(stderr,
            "line %d: "
            "failed to allocate argv"
            "\n",
            188);
    return -1;
  }
  push_back(&size, &capacity, &argv, "mpv");
  for (char *end = strchr(out, '\n'); end;
       out = end + 1, end = strchr(out, '\n')) {
    *end = '\0';
    if (push_back(&size, &capacity, &argv, out)) {
      fprintf(stderr,
              "line %d: "
              "push_back failed"
              "\n",
              200);
      free(argv);
      return -1;
    }
  }
  if (size == 1) {
    free(argv);
    return 0;
  }
  push_back(&size, &capacity, &argv, "--no-video");
  push_back(&size, &capacity, &argv, NULL);
  if (execvp("mpv", (char **)argv)) {
    fprintf(stderr,
            "line %d: "
            "execv failed: %s"
            "\n",
            219, strerror(errno));
    free(argv);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<handle_play>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x8,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d1 <handle_play+0x61>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
mov    $0xbc,%edx
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133b <handle_play+0x1cb>
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    0xe3e(%rip),%rcx
call   1070 <push_back@plt>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1285 <handle_play+0x115>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1070 <push_back@plt>
cmp    $0x0,%rax
je     125d <handle_play+0xed>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
mov    $0xc8,%edx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133b <handle_play+0x1cb>
jmp    1262 <handle_play+0xf2>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
jmp    11fb <handle_play+0x8b>
cmpq   $0x1,-0x18(%rbp)
jne    12a5 <handle_play+0x135>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    133b <handle_play+0x1cb>
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    0xd89(%rip),%rcx
call   1070 <push_back@plt>
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1070 <push_back@plt>
mov    -0x28(%rbp),%rsi
lea    0xd45(%rip),%rdi
call   1080 <execvp@plt>
cmp    $0x0,%rax
je     1334 <handle_play+0x1c4>
mov    0x2ced(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rcx
lea    0xd39(%rip),%rsi
mov    $0xdb,%edx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133b <handle_play+0x1cb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_play>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movq   $0x0,0x10(%rsp)
movq   $0x8,0x18(%rsp)
mov    $0x8,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1244 <handle_play+0xd4>
lea    0xe6c(%rip),%rcx
lea    0x10(%rsp),%rdi
lea    0x18(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1070 <push_back@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     122b <handle_play+0xbb>
mov    %rax,%r12
lea    0x10(%rsp),%r14
lea    0x18(%rsp),%r15
lea    0x8(%rsp),%r13
xchg   %ax,%ax
movb   $0x0,(%r12)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1070 <push_back@plt>
test   %rax,%rax
jne    12e2 <handle_play+0x172>
mov    %r12,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11f0 <handle_play+0x80>
cmpq   $0x1,0x10(%rsp)
jne    1265 <handle_play+0xf5>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
jmp    130d <handle_play+0x19d>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xdac(%rip),%rsi
mov    $0xbc,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1308 <handle_play+0x198>
lea    0xdd5(%rip),%rcx
lea    0x10(%rsp),%r14
lea    0x18(%rsp),%r15
lea    0x8(%rsp),%r12
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1070 <push_back@plt>
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
call   1070 <push_back@plt>
mov    0x8(%rsp),%rsi
lea    0xd7b(%rip),%rdi
call   1080 <execvp@plt>
test   %rax,%rax
je     130d <handle_play+0x19d>
mov    0x2d28(%rip),%rax
mov    (%rax),%ebx
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd7d(%rip),%rsi
mov    %ebx,%edi
mov    $0xdb,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12fe <handle_play+0x18e>
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
lea    0xd34(%rip),%rsi
mov    $0xc8,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"line %d: failed to allocate argv\0A\00"
@.str.1 = [4 x i8] c"mpv\00"
@.str.2 = [27 x i8] c"line %d: push_back failed\0A\00"
@.str.3 = [11 x i8] c"--no-video\00"
@.str.4 = [27 x i8] c"line %d: execv failed: %s\0A\00"
@errno = global i32 0
define i32 @handle_play(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8**
%7 = alloca i8*
store i8* %0, i8** %3
store i64 0, i64* %4
store i64 8, i64* %5
%8 = load i64, i64* %5
%9 = call i8** @calloc(i64 %8, i32 8)
store i8** %9, i8*** %6
%10 = load i8**, i8*** %6
%11 = icmp ne i8** %10, null
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 188)
store i32 -1, i32* %2
br label %58
15: ; preds = %1
%16 = call i64 @push_back(i64* %4, i64* %5, i8*** %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8*, i8** %3
%18 = call i8* @strchr(i8* %17, i8 signext 10)
store i8* %18, i8** %7
br label %19
19: ; preds = %33, %15
%20 = load i8*, i8** %7
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %38
22: ; preds = %19
%23 = load i8*, i8** %7
store i8 0, i8* %23
%24 = load i8*, i8** %3
%25 = call i64 @push_back(i64* %4, i64* %5, i8*** %6, i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 200)
%30 = load i8**, i8*** %6
%31 = call i32 @free(i8** %30)
store i32 -1, i32* %2
br label %58
32: ; preds = %22
br label %33
33: ; preds = %32
%34 = load i8*, i8** %7
%35 = getelementptr inbounds i8, i8* %34, i64 1
store i8* %35, i8** %3
%36 = load i8*, i8** %3
%37 = call i8* @strchr(i8* %36, i8 signext 10)
store i8* %37, i8** %7
br label %19
38: ; preds = %19
%39 = load i64, i64* %4
%40 = icmp eq i64 %39, 1
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i8**, i8*** %6
%43 = call i32 @free(i8** %42)
store i32 0, i32* %2
br label %58
44: ; preds = %38
%45 = call i64 @push_back(i64* %4, i64* %5, i8*** %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%46 = call i64 @push_back(i64* %4, i64* %5, i8*** %6, i8* null)
%47 = load i8**, i8*** %6
%48 = call i64 @execvp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %57
50: ; preds = %44
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 219, i8* %53)
%55 = load i8**, i8*** %6
%56 = call i32 @free(i8** %55)
store i32 -1, i32* %2
br label %58
57: ; preds = %44
store i32 0, i32* %2
br label %58
58: ; preds = %57, %50, %41, %27, %12
%59 = load i32, i32* %2
ret i32 %59
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"line %d: failed to allocate argv\0A\00"
@.str.1 = [4 x i8] c"mpv\00"
@.str.2 = [27 x i8] c"line %d: push_back failed\0A\00"
@.str.3 = [11 x i8] c"--no-video\00"
@.str.4 = [27 x i8] c"line %d: execv failed: %s\0A\00"
@errno = global i32 0
define i32 @handle_play(i8* %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8**
%5 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%6 = bitcast i64* %3 to i8*
store i64 8, i64* %3
%7 = bitcast i8*** %4 to i8*
%8 = tail call i8** @calloc(i64 8, i32 8)
store i8** %8, i8*** %4
%9 = icmp eq i8** %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 188)
br label %50
13: ; preds = %1
%14 = call i64 @push_back(i64* %2, i64* %3, i8*** %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%15 = call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%16 = icmp eq i8* %15, null
br i1 %16, label %31, label %17
17: ; preds = %13, %27
%18 = phi i8* [ %29, %27 ], [ %15, %13 ]
%19 = phi i8* [ %28, %27 ], [ %0, %13 ]
store i8 0, i8* %18
%20 = call i64 @push_back(i64* %2, i64* %3, i8*** %4, i8* %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 200)
%25 = load i8**, i8*** %4
%26 = call i32 @free(i8** %25)
br label %50
27: ; preds = %17
%28 = getelementptr inbounds i8, i8* %18, i64 1
%29 = call i8* @strchr(i8* %28, i8 signext 10)
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %17
31: ; preds = %27, %13
%32 = load i64, i64* %2
%33 = icmp eq i64 %32, 1
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i8**, i8*** %4
%36 = call i32 @free(i8** %35)
br label %50
37: ; preds = %31
%38 = call i64 @push_back(i64* %2, i64* %3, i8*** %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%39 = call i64 @push_back(i64* %2, i64* %3, i8*** %4, i8* null)
%40 = load i8**, i8*** %4
%41 = call i64 @execvp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %50, label %43
43: ; preds = %37
%44 = load i32, i32* @stderr
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 219, i8* %46)
%48 = load i8**, i8*** %4
%49 = call i32 @free(i8** %48)
br label %50
50: ; preds = %22, %37, %43, %34, %10
%51 = phi i32 [ 0, %34 ], [ -1, %43 ], [ -1, %22 ], [ -1, %10 ], [ 0, %37 ]
ret i32 %51
}