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

/* Variables and functions */
int /*<<< orphan*/ inet_close(int);
int mpd_command(int, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int mpd_play(int sock, char *entry) {
  char buf[1280];
  if (mpd_command(sock, "clear\n") == -1)
    return -1;
  if (mpd_command(sock, "random 0\n") == -1)
    return -1;
  snprintf(buf, sizeof(buf), "add \"%s\"\n", entry);
  if (mpd_command(sock, buf) == -1)
    return -1;
  if (mpd_command(sock, "play\n") == -1)
    inet_close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<mpd_play>:
push   %rbp
mov    %rsp,%rbp
sub    $0x510,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    0xeb4(%rip),%rsi
call   1030 <mpd_command@plt>
cmp    $0xffffffff,%eax
jne    1166 <mpd_play+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <mpd_play+0xc1>
mov    -0x8(%rbp),%edi
lea    0xe97(%rip),%rsi
call   1030 <mpd_command@plt>
cmp    $0xffffffff,%eax
jne    118a <mpd_play+0x5a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <mpd_play+0xc1>
lea    -0x510(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x500,%esi
lea    0xe70(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x510(%rbp),%rsi
call   1030 <mpd_command@plt>
cmp    $0xffffffff,%eax
jne    11ca <mpd_play+0x9a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <mpd_play+0xc1>
mov    -0x8(%rbp),%edi
lea    0xe47(%rip),%rsi
call   1030 <mpd_command@plt>
cmp    $0xffffffff,%eax
jne    11ea <mpd_play+0xba>
mov    -0x8(%rbp),%edi
call   1040 <inet_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x510,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpd_play>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x508,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xeb7(%rip),%rsi
call   1030 <mpd_command@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     11b0 <mpd_play+0x80>
lea    0xea8(%rip),%rsi
mov    %ebx,%edi
call   1030 <mpd_command@plt>
cmp    $0xffffffff,%eax
je     11b0 <mpd_play+0x80>
lea    0xe9f(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x500,%esi
mov    %r14,%rcx
call   1050 <snprintf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1030 <mpd_command@plt>
cmp    $0xffffffff,%eax
je     11b0 <mpd_play+0x80>
lea    0xe80(%rip),%rsi
mov    %ebx,%edi
call   1030 <mpd_command@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
jne    11b0 <mpd_play+0x80>
mov    %ebx,%edi
call   1040 <inet_close@plt>
mov    %ebp,%eax
add    $0x508,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"clear\0A\00"
@.str.1 = [10 x i8] c"random 0\0A\00"
@.str.2 = [10 x i8] c"add \22%s\22\0A\00"
@.str.3 = [6 x i8] c"play\0A\00"
define i32 @mpd_play(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [1280 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i32, i32* %4
%8 = call i32 @mpd_command(i32 %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %33
11: ; preds = %2
%12 = load i32, i32* %4
%13 = call i32 @mpd_command(i32 %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 -1, i32* %3
br label %33
16: ; preds = %11
%17 = getelementptr inbounds [1280 x i8], [1280 x i8]* %6, i64 0, i64 0
%18 = load i8*, i8** %5
%19 = call i32 @snprintf(i8* %17, i32 1280, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %4
%21 = getelementptr inbounds [1280 x i8], [1280 x i8]* %6, i64 0, i64 0
%22 = call i32 @mpd_command(i32 %20, i8* %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %25
24: ; preds = %16
store i32 -1, i32* %3
br label %33
25: ; preds = %16
%26 = load i32, i32* %4
%27 = call i32 @mpd_command(i32 %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i32, i32* %4
%31 = call i32 @inet_close(i32 %30)
br label %32
32: ; preds = %29, %25
store i32 0, i32* %3
br label %33
33: ; preds = %32, %24, %15, %10
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [7 x i8] c"clear\0A\00"
@.str.1 = [10 x i8] c"random 0\0A\00"
@.str.2 = [10 x i8] c"add \22%s\22\0A\00"
@.str.3 = [6 x i8] c"play\0A\00"
define i32 @mpd_play(i32 %0, i8* %1) {
%3 = alloca [1280 x i8]
%4 = getelementptr inbounds [1280 x i8], [1280 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @mpd_command(i32 %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, -1
br i1 %6, label %19, label %7
7: ; preds = %2
%8 = tail call i32 @mpd_command(i32 %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32 %8, -1
br i1 %9, label %19, label %10
10: ; preds = %7
%11 = call i32 @snprintf(i8* %4, i32 1280, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%12 = call i32 @mpd_command(i32 %0, i8* %4)
%13 = icmp eq i32 %12, -1
br i1 %13, label %19, label %14
14: ; preds = %10
%15 = call i32 @mpd_command(i32 %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @inet_close(i32 %0)
br label %19
19: ; preds = %14, %17, %10, %7, %2
%20 = phi i32 [ -1, %2 ], [ -1, %7 ], [ -1, %10 ], [ 0, %17 ], [ 0, %14 ]
ret i32 %20
}