#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ *inet_readline(int, char *, char **, int);
int inet_write(int, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int mpd_command(int sock, char *command) {
  char buf[256], *rest;
  if (inet_write(sock, command) == -1) {
    fprintf(stderr, "error in connection with MPD\n");
    return -1;
  }
  rest = NULL;
  while (inet_readline(sock, buf, &rest, sizeof(buf)) != NULL) {
    if (!strcmp(buf, "OK"))
      break;
    if (!strncmp(buf, "ACK", 3)) {
      fprintf(stderr, "error from MPD: error listing music directory\n");
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<mpd_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <inet_write@plt>
cmp    $0xffffffff,%eax
jne    1198 <mpd_command+0x48>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1237 <mpd_command+0xe7>
movq   $0x0,-0x118(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
lea    -0x118(%rbp),%rdx
mov    $0x100,%ecx
call   1050 <inet_readline@plt>
cmp    $0x0,%rax
je     1230 <mpd_command+0xe0>
lea    -0x110(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11e9 <mpd_command+0x99>
jmp    1230 <mpd_command+0xe0>
lea    -0x110(%rbp),%rdi
lea    0xe2a(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    122b <mpd_command+0xdb>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1237 <mpd_command+0xe7>
jmp    11a3 <mpd_command+0x53>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpd_command>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x110,%rsp
mov    %edi,%ebx
call   1030 <inet_write@plt>
cmp    $0xffffffff,%eax
je     11d2 <mpd_command+0x92>
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r15
mov    $0x4b4f,%ebp
lea    0xea7(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    $0x100,%ecx
call   1050 <inet_readline@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     11ec <mpd_command+0xac>
mov    0x10(%rsp),%ecx
xor    %ebp,%ecx
movzbl 0x12(%rsp),%edx
or     %cx,%dx
je     11ec <mpd_command+0xac>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    1180 <mpd_command+0x40>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
jmp    11e2 <mpd_command+0xa2>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"error in connection with MPD\0A\00"
@.str.1 = [3 x i8] c"OK\00"
@.str.2 = [4 x i8] c"ACK\00"
@.str.3 = [47 x i8] c"error from MPD: error listing music directory\0A\00"
define i32 @mpd_command(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [256 x i8]
%7 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
%8 = load i32, i32* %4
%9 = load i8*, i8** %5
%10 = call i32 @inet_write(i32 %8, i8* %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %35
15: ; preds = %2
store i8* null, i8** %7
br label %16
16: ; preds = %33, %15
%17 = load i32, i32* %4
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%19 = call i32* @inet_readline(i32 %17, i8* %18, i8** %7, i32 256)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %34
21: ; preds = %16
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%23 = call i32 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %21
br label %34
26: ; preds = %21
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%28 = call i32 @strncmp(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%29 = icmp ne i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %35
33: ; preds = %26
br label %16
34: ; preds = %25, %16
store i32 0, i32* %3
br label %35
35: ; preds = %34, %30, %12
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"error in connection with MPD\0A\00"
@.str.1 = [3 x i8] c"OK\00"
@.str.2 = [4 x i8] c"ACK\00"
@.str.3 = [47 x i8] c"error from MPD: error listing music directory\0A\00"
define i32 @mpd_command(i32 %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = bitcast i8** %4 to i8*
%7 = tail call i32 @inet_write(i32 %0, i8* %1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %25
12: ; preds = %2
store i8* null, i8** %4
br label %13
13: ; preds = %19, %12
%14 = call i32* @inet_readline(i32 %0, i8* %5, i8** %4, i32 256)
%15 = icmp eq i32* %14, null
br i1 %15, label %25, label %16
16: ; preds = %13
%17 = call i32 @bcmp(i8* dereferenceable(3) %5, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 3)
%18 = icmp eq i32 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %16
%20 = call i32 @strncmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %13
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %13, %16, %22, %9
%26 = phi i32 [ -1, %9 ], [ -1, %22 ], [ 0, %16 ], [ 0, %13 ]
ret i32 %26
}