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


x86 assembly (clang, -O0):
<mpd_listdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x520,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    0xe78(%rip),%rsi
call   1030 <inet_write@plt>
cmp    $0xffffffff,%eax
jne    11b7 <mpd_listdir+0x47>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1293 <mpd_listdir+0x123>
movq   $0x0,-0x518(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x510(%rbp),%rsi
lea    -0x518(%rbp),%rdx
mov    $0x500,%ecx
call   1050 <inet_readline@plt>
cmp    $0x0,%rax
je     1285 <mpd_listdir+0x115>
lea    -0x510(%rbp),%rdi
lea    0xe32(%rip),%rsi
mov    $0xb,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    121d <mpd_listdir+0xad>
lea    -0x510(%rbp),%rdi
add    $0xb,%rdi
call   1080 <add_directory@plt>
jmp    11c2 <mpd_listdir+0x52>
lea    -0x510(%rbp),%rdi
lea    0xe08(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    123e <mpd_listdir+0xce>
jmp    1285 <mpd_listdir+0x115>
lea    -0x510(%rbp),%rdi
lea    0xdea(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1280 <mpd_listdir+0x110>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1293 <mpd_listdir+0x123>
jmp    11c2 <mpd_listdir+0x52>
mov    $0x0,%al
call   1090 <init_current_DirList@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x520,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpd_listdir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x518,%rsp
mov    %edi,%ebp
lea    0xe86(%rip),%rsi
call   1030 <inet_write@plt>
cmp    $0xffffffff,%eax
je     1247 <mpd_listdir+0xe7>
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
mov    $0x500,%ecx
call   1050 <inet_readline@plt>
test   %rax,%rax
je     123c <mpd_listdir+0xdc>
lea    0xe70(%rip),%r15
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r12
mov    $0x4b4f,%r14d
lea    0xe68(%rip),%r13
jmp    11f1 <mpd_listdir+0x91>
lea    0x1b(%rsp),%rdi
call   1070 <add_directory@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    $0x500,%ecx
call   1050 <inet_readline@plt>
test   %rax,%rax
je     123c <mpd_listdir+0xdc>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0xb,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     11d0 <mpd_listdir+0x70>
mov    0x10(%rsp),%eax
xor    %r14d,%eax
movzbl 0x12(%rsp),%ecx
or     %ax,%cx
je     123c <mpd_listdir+0xdc>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    11da <mpd_listdir+0x7a>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
jmp    1257 <mpd_listdir+0xf7>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <init_current_DirList@plt>
jmp    1261 <mpd_listdir+0x101>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xdb2(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x518,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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