#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 */
scalar_t__ cddb_getresp(char *, int, int);
int /*<<< orphan*/ cddb_sendcmd(char *);
int /*<<< orphan*/ dagrab_stderr(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
char *strchr(char *, char);
char *strdup(char *);
int strlen(char *);
int cddb_query(char *qs, char **id, char **gnr) {
  char buf[2001], *p, *q;
  sprintf(buf, "cddb query %s\n", qs);
  cddb_sendcmd(buf);
  if (cddb_getresp(buf, 2000, 1) < 0)
    return 1;
  p = buf + 4;
  if (buf[1] == '1') {
    dagrab_stderr("cddb inexact matches found, picking first\n");
    p = strchr(buf, '\n') + 1;
  }
  q = strchr(p, ' ');
  *q = 0;
  *gnr = strdup(p);
  p = q + 1;
  q = strchr(p, ' ');
  *q = 0;
  *id = strdup(p);
  p = q + 1;
  if ((buf[1] == '1') && (p[strlen(p) - 3] != '.'))
    do
      cddb_getresp(buf, 2000, 1);
    while (buf[strlen(buf) - 3] != '.');
  return 0;
}


x86 assembly (clang, -O0):
<cddb_query>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x800(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe67(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x800(%rbp),%rdi
call   1060 <cddb_sendcmd@plt>
lea    -0x800(%rbp),%rdi
mov    $0x7d0,%esi
mov    $0x1,%edx
call   1090 <cddb_getresp@plt>
cmp    $0x0,%rax
jge    11d6 <cddb_query+0x66>
movl   $0x1,-0x4(%rbp)
jmp    1343 <cddb_query+0x1d3>
lea    -0x800(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x808(%rbp)
movsbl -0x7ff(%rbp),%eax
cmp    $0x31,%eax
jne    1220 <cddb_query+0xb0>
lea    0xe10(%rip),%rdi
call   1030 <dagrab_stderr@plt>
lea    -0x800(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
add    $0x1,%rax
mov    %rax,-0x808(%rbp)
mov    -0x808(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x810(%rbp)
mov    -0x810(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x808(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x810(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x808(%rbp)
mov    -0x808(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x810(%rbp)
mov    -0x810(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x808(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x810(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x808(%rbp)
movsbl -0x7ff(%rbp),%eax
cmp    $0x31,%eax
jne    133c <cddb_query+0x1cc>
mov    -0x808(%rbp),%rax
mov    %rax,-0x818(%rbp)
mov    -0x808(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x818(%rbp),%rax
sub    $0x3,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     133c <cddb_query+0x1cc>
jmp    12ff <cddb_query+0x18f>
lea    -0x800(%rbp),%rdi
mov    $0x7d0,%esi
mov    $0x1,%edx
call   1090 <cddb_getresp@plt>
lea    -0x800(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x3,%eax
cltq
movsbl -0x800(%rbp,%rax,1),%eax
ff
cmp    $0x2e,%eax
jne    12ff <cddb_query+0x18f>
jmp    133c <cddb_query+0x1cc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cddb_query>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x7e0,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rdx
lea    0xe71(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <cddb_sendcmd@plt>
mov    $0x1,%r12d
mov    %rbx,%rdi
mov    $0x7d0,%esi
mov    $0x1,%edx
call   1090 <cddb_getresp@plt>
test   %rax,%rax
js     1283 <cddb_query+0x113>
cmpb   $0x31,0x1(%rsp)
jne    11ec <cddb_query+0x7c>
lea    0xe3e(%rip),%rdi
call   1030 <dagrab_stderr@plt>
mov    %rsp,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,%r12
add    $0x1,%r12
jmp    11f1 <cddb_query+0x81>
lea    0x4(%rsp),%r12
mov    %r12,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,%rbp
movb   $0x0,(%rax)
mov    %r12,%rdi
call   1080 <strdup@plt>
mov    %rax,(%r15)
add    $0x1,%rbp
mov    %rbp,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,%r15
movb   $0x0,(%rax)
mov    %rbp,%rdi
call   1080 <strdup@plt>
mov    %rax,(%r14)
xor    %r12d,%r12d
cmpb   $0x31,0x1(%rsp)
jne    1283 <cddb_query+0x113>
add    $0x1,%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2e,-0x3(%rax,%r15,1)
je     1283 <cddb_query+0x113>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x7d0,%esi
mov    $0x1,%edx
call   1090 <cddb_getresp@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2e,-0x3(%rax,%rbx,1)
jne    1260 <cddb_query+0xf0>
mov    %r12d,%eax
add    $0x7e0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"cddb query %s\0A\00"
@.str.1 = [43 x i8] c"cddb inexact matches found, picking first\0A\00"
define i32 @cddb_query(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca [2001 x i8]
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%11 = getelementptr inbounds [2001 x i8], [2001 x i8]* %8, i64 0, i64 0
%12 = load i8*, i8** %5
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [2001 x i8], [2001 x i8]* %8, i64 0, i64 0
%15 = call i32 @cddb_sendcmd(i8* %14)
%16 = getelementptr inbounds [2001 x i8], [2001 x i8]* %8, i64 0, i64 0
%17 = call i64 @cddb_getresp(i8* %16, i32 2000, i32 1)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %3
store i32 1, i32* %4
br label %78
20: ; preds = %3
%21 = getelementptr inbounds [2001 x i8], [2001 x i8]* %8, i64 0, i64 0
%22 = getelementptr inbounds i8, i8* %21, i64 4
store i8* %22, i8** %9
%23 = getelementptr inbounds [2001 x i8], [2001 x i8]* %8, i64 0, i64 1
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 49
br i1 %26, label %27, label %32
27: ; preds = %20
%28 = call i32 @dagrab_stderr(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%29 = getelementptr inbounds [2001 x i8], [2001 x i8]* %8, i64 0, i64 0
%30 = call i8* @strchr(i8* %29, i8 signext 10)
%31 = getelementptr inbounds i8, i8* %30, i64 1
store i8* %31, i8** %9
br label %32
32: ; preds = %27, %20
%33 = load i8*, i8** %9
%34 = call i8* @strchr(i8* %33, i8 signext 32)
store i8* %34, i8** %10
%35 = load i8*, i8** %10
store i8 0, i8* %35
%36 = load i8*, i8** %9
%37 = call i8* @strdup(i8* %36)
%38 = load i8**, i8*** %7
store i8* %37, i8** %38
%39 = load i8*, i8** %10
%40 = getelementptr inbounds i8, i8* %39, i64 1
store i8* %40, i8** %9
%41 = load i8*, i8** %9
%42 = call i8* @strchr(i8* %41, i8 signext 32)
store i8* %42, i8** %10
%43 = load i8*, i8** %10
store i8 0, i8* %43
%44 = load i8*, i8** %9
%45 = call i8* @strdup(i8* %44)
%46 = load i8**, i8*** %6
store i8* %45, i8** %46
%47 = load i8*, i8** %10
%48 = getelementptr inbounds i8, i8* %47, i64 1
store i8* %48, i8** %9
%49 = getelementptr inbounds [2001 x i8], [2001 x i8]* %8, i64 0, i64 1
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 49
br i1 %52, label %53, label %77
53: ; preds = %32
%54 = load i8*, i8** %9
%55 = load i8*, i8** %9
%56 = call i32 @strlen(i8* %55)
%57 = sub nsw i32 %56, 3
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %54, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp ne i32 %61, 46
br i1 %62, label %63, label %77
63: ; preds = %53
br label %64
64: ; preds = %67, %63
%65 = getelementptr inbounds [2001 x i8], [2001 x i8]* %8, i64 0, i64 0
%66 = call i64 @cddb_getresp(i8* %65, i32 2000, i32 1)
br label %67
67: ; preds = %64
%68 = getelementptr inbounds [2001 x i8], [2001 x i8]* %8, i64 0, i64 0
%69 = call i32 @strlen(i8* %68)
%70 = sub nsw i32 %69, 3
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [2001 x i8], [2001 x i8]* %8, i64 0, i64 %71
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp ne i32 %74, 46
br i1 %75, label %64, label %76
76: ; preds = %67
br label %77
77: ; preds = %76, %53, %32
store i32 0, i32* %4
br label %78
78: ; preds = %77, %19
%79 = load i32, i32* %4
ret i32 %79
}

LLVM IR (-O2):
@.str = [15 x i8] c"cddb query %s\0A\00"
@.str.1 = [43 x i8] c"cddb inexact matches found, picking first\0A\00"
define i32 @cddb_query(i8* %0, i8** nocapture writeonly %1, i8** nocapture writeonly %2) {
%4 = alloca [2001 x i8]
%5 = getelementptr inbounds [2001 x i8], [2001 x i8]* %4, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32 @cddb_sendcmd(i8* %5)
%8 = call i64 @cddb_getresp(i8* %5, i32 2000, i32 1)
%9 = icmp slt i64 %8, 0
br i1 %9, label %44, label %10
10: ; preds = %3
%11 = getelementptr inbounds [2001 x i8], [2001 x i8]* %4, i64 0, i64 4
%12 = getelementptr inbounds [2001 x i8], [2001 x i8]* %4, i64 0, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 49
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = call i32 @dagrab_stderr(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%17 = call i8* @strchr(i8* %5, i8 signext 10)
%18 = getelementptr inbounds i8, i8* %17, i64 1
br label %19
19: ; preds = %15, %10
%20 = phi i8* [ %18, %15 ], [ %11, %10 ]
%21 = call i8* @strchr(i8* %20, i8 signext 32)
store i8 0, i8* %21
%22 = call i8* @strdup(i8* %20)
store i8* %22, i8** %2
%23 = getelementptr inbounds i8, i8* %21, i64 1
%24 = call i8* @strchr(i8* %23, i8 signext 32)
store i8 0, i8* %24
%25 = call i8* @strdup(i8* %23)
store i8* %25, i8** %1
%26 = getelementptr inbounds i8, i8* %24, i64 1
%27 = load i8, i8* %12
%28 = icmp eq i8 %27, 49
br i1 %28, label %29, label %44
29: ; preds = %19
%30 = call i32 @strlen(i8* %26)
%31 = add nsw i32 %30, -3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %26, i64 %32
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 46
br i1 %35, label %44, label %36
36: ; preds = %29, %36
%37 = call i64 @cddb_getresp(i8* %5, i32 2000, i32 1)
%38 = call i32 @strlen(i8* %5)
%39 = add nsw i32 %38, -3
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [2001 x i8], [2001 x i8]* %4, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 46
br i1 %43, label %44, label %36
44: ; preds = %36, %19, %29, %3
%45 = phi i32 [ 1, %3 ], [ 0, %29 ], [ 0, %19 ], [ 0, %36 ]
ret i32 %45
}