#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 */
int /*<<< orphan*/ db_get_error(char **, int);
int db_sql_exec_fn(char **, int, char *, int, int);
int db_sql_fetch_int(char **, int *, char *, int, ...);
int /*<<< orphan*/ free(char *);
int db_sql_delete_playlist_item(char **pe, int playlistid, int songid) {
  int result;
  int playlist_type;
  int count;
  result = db_sql_fetch_int(
      pe, &playlist_type, "select type from playlists where id=%d", playlistid);
  if (result != 0x00) {
    if (result == 0x05) {
      if (pe) {
        free(*pe);
      };
      db_get_error(pe, 0x06);
      return 0x06;
    }
    return result;
  }
  if (playlist_type == 1) {
    db_get_error(pe, 0x04);
    return 0x04;
  }
  result = db_sql_fetch_int(pe, &count,
                            "select count(*) from playlistitems "
                            "where playlistid=%d and songid=%d",
                            playlistid, songid);
  if (result != 0x00) {
    if (result == 0x05) {
      if (pe) {
        free(*pe);
      };
      db_get_error(pe, 0x07);
      return 0x07;
    }
    return result;
  }
  result = db_sql_exec_fn(pe, 9,
                          "delete from playlistitems where "
                          "playlistid=%d and songid=%d",
                          playlistid, songid);
  return result;
}


x86 assembly (clang, -O0):
<db_sql_delete_playlist_item>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%ecx
lea    -0x20(%rbp),%rsi
lea    0xe9c(%rip),%rdx
mov    $0x0,%al
call   1050 <db_sql_fetch_int@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11be <db_sql_delete_playlist_item+0x7e>
cmpl   $0x5,-0x1c(%rbp)
jne    11b3 <db_sql_delete_playlist_item+0x73>
cmpq   $0x0,-0x10(%rbp)
je     1199 <db_sql_delete_playlist_item+0x59>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
mov    $0x6,%esi
call   1060 <db_get_error@plt>
movl   $0x6,-0x4(%rbp)
jmp    1277 <db_sql_delete_playlist_item+0x137>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1277 <db_sql_delete_playlist_item+0x137>
cmpl   $0x1,-0x20(%rbp)
jne    11e2 <db_sql_delete_playlist_item+0xa2>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1060 <db_get_error@plt>
movl   $0x4,-0x4(%rbp)
jmp    1277 <db_sql_delete_playlist_item+0x137>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    -0x24(%rbp),%rsi
lea    0xe2f(%rip),%rdx
mov    $0x0,%al
call   1050 <db_sql_fetch_int@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1252 <db_sql_delete_playlist_item+0x112>
cmpl   $0x5,-0x1c(%rbp)
jne    1247 <db_sql_delete_playlist_item+0x107>
cmpq   $0x0,-0x10(%rbp)
je     122d <db_sql_delete_playlist_item+0xed>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
mov    $0x7,%esi
call   1060 <db_get_error@plt>
movl   $0x7,-0x4(%rbp)
jmp    1277 <db_sql_delete_playlist_item+0x137>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1277 <db_sql_delete_playlist_item+0x137>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    $0x9,%esi
lea    0xe03(%rip),%rdx
call   1040 <db_sql_exec_fn@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_sql_delete_playlist_item>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0xea9(%rip),%rdx
mov    %rsp,%rsi
mov    %r15d,%ecx
xor    %eax,%eax
call   1050 <db_sql_fetch_int@plt>
test   %eax,%eax
je     1194 <db_sql_delete_playlist_item+0x54>
mov    %eax,%ebp
cmp    $0x5,%eax
jne    1212 <db_sql_delete_playlist_item+0xd2>
test   %rbx,%rbx
je     1180 <db_sql_delete_playlist_item+0x40>
mov    (%rbx),%rdi
call   1030 <free@plt>
mov    $0x6,%ebp
mov    %rbx,%rdi
mov    $0x6,%esi
call   1060 <db_get_error@plt>
jmp    1212 <db_sql_delete_playlist_item+0xd2>
cmpl   $0x1,(%rsp)
jne    11ae <db_sql_delete_playlist_item+0x6e>
mov    $0x4,%ebp
mov    %rbx,%rdi
mov    $0x4,%esi
call   1060 <db_get_error@plt>
jmp    1212 <db_sql_delete_playlist_item+0xd2>
lea    0xe72(%rip),%rdx
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
mov    %r15d,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1050 <db_sql_fetch_int@plt>
test   %eax,%eax
je     11f6 <db_sql_delete_playlist_item+0xb6>
mov    %eax,%ebp
cmp    $0x5,%eax
jne    1212 <db_sql_delete_playlist_item+0xd2>
test   %rbx,%rbx
je     11e2 <db_sql_delete_playlist_item+0xa2>
mov    (%rbx),%rdi
call   1030 <free@plt>
mov    $0x7,%ebp
mov    %rbx,%rdi
mov    $0x7,%esi
call   1060 <db_get_error@plt>
jmp    1212 <db_sql_delete_playlist_item+0xd2>
lea    0xe6f(%rip),%rdx
mov    %rbx,%rdi
mov    $0x9,%esi
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1040 <db_sql_exec_fn@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"select type from playlists where id=%d\00"
@.str.1 = [69 x i8] c"select count(*) from playlistitems where playlistid=%d and songid=%d\00"
@.str.2 = [60 x i8] c"delete from playlistitems where playlistid=%d and songid=%d\00"
define i32 @db_sql_delete_playlist_item(i8** %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8** %0, i8*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load i8**, i8*** %5
%12 = load i32, i32* %6
%13 = call i32 (i8**, i32*, i8*, i32, ...) @db_sql_fetch_int(i8** %11, i32* %9, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %31
16: ; preds = %3
%17 = load i32, i32* %8
%18 = icmp eq i32 %17, 5
br i1 %18, label %19, label %29
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = icmp ne i8** %20, null
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i8**, i8*** %5
%24 = load i8*, i8** %23
%25 = call i32 @free(i8* %24)
br label %26
26: ; preds = %22, %19
%27 = load i8**, i8*** %5
%28 = call i32 @db_get_error(i8** %27, i32 6)
store i32 6, i32* %4
br label %65
29: ; preds = %16
%30 = load i32, i32* %8
store i32 %30, i32* %4
br label %65
31: ; preds = %3
%32 = load i32, i32* %9
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i8**, i8*** %5
%36 = call i32 @db_get_error(i8** %35, i32 4)
store i32 4, i32* %4
br label %65
37: ; preds = %31
%38 = load i8**, i8*** %5
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = call i32 (i8**, i32*, i8*, i32, ...) @db_sql_fetch_int(i8** %38, i32* %10, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i32 %39, i32 %40)
store i32 %41, i32* %8
%42 = load i32, i32* %8
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %59
44: ; preds = %37
%45 = load i32, i32* %8
%46 = icmp eq i32 %45, 5
br i1 %46, label %47, label %57
47: ; preds = %44
%48 = load i8**, i8*** %5
%49 = icmp ne i8** %48, null
br i1 %49, label %50, label %54
50: ; preds = %47
%51 = load i8**, i8*** %5
%52 = load i8*, i8** %51
%53 = call i32 @free(i8* %52)
br label %54
54: ; preds = %50, %47
%55 = load i8**, i8*** %5
%56 = call i32 @db_get_error(i8** %55, i32 7)
store i32 7, i32* %4
br label %65
57: ; preds = %44
%58 = load i32, i32* %8
store i32 %58, i32* %4
br label %65
59: ; preds = %37
%60 = load i8**, i8*** %5
%61 = load i32, i32* %6
%62 = load i32, i32* %7
%63 = call i32 @db_sql_exec_fn(i8** %60, i32 9, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i32 %61, i32 %62)
store i32 %63, i32* %8
%64 = load i32, i32* %8
store i32 %64, i32* %4
br label %65
65: ; preds = %59, %57, %54, %34, %29, %26
%66 = load i32, i32* %4
ret i32 %66
}

LLVM IR (-O2):
@.str = [39 x i8] c"select type from playlists where id=%d\00"
@.str.1 = [69 x i8] c"select count(*) from playlistitems where playlistid=%d and songid=%d\00"
@.str.2 = [60 x i8] c"delete from playlistitems where playlistid=%d and songid=%d\00"
define i32 @db_sql_delete_playlist_item(i8** %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
%7 = bitcast i32* %5 to i8*
%8 = call i32 (i8**, i32*, i8*, i32, ...) @db_sql_fetch_int(i8** %0, i32* %4, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %1)
switch i32 %8, label %32 [
i32 0, label %16
i32 5, label %9
]
9: ; preds = %3
%10 = icmp eq i8** %0, null
br i1 %10, label %14, label %11
11: ; preds = %9
%12 = load i8*, i8** %0
%13 = call i32 @free(i8* %12)
br label %14
14: ; preds = %11, %9
%15 = call i32 @db_get_error(i8** %0, i32 6)
br label %32
16: ; preds = %3
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @db_get_error(i8** %0, i32 4)
br label %32
21: ; preds = %16
%22 = call i32 (i8**, i32*, i8*, i32, ...) @db_sql_fetch_int(i8** %0, i32* %5, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %2)
switch i32 %22, label %32 [
i32 0, label %30
i32 5, label %23
]
23: ; preds = %21
%24 = icmp eq i8** %0, null
br i1 %24, label %28, label %25
25: ; preds = %23
%26 = load i8*, i8** %0
%27 = call i32 @free(i8* %26)
br label %28
28: ; preds = %25, %23
%29 = call i32 @db_get_error(i8** %0, i32 7)
br label %32
30: ; preds = %21
%31 = call i32 @db_sql_exec_fn(i8** %0, i32 9, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i32 %1, i32 %2)
br label %32
32: ; preds = %21, %3, %30, %28, %19, %14
%33 = phi i32 [ 6, %14 ], [ 4, %19 ], [ 7, %28 ], [ %31, %30 ], [ %8, %3 ], [ %22, %21 ]
ret i32 %33
}