#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_playlist_count(char **, int *);
int /*<<< orphan*/ db_get_song_count(char **, int *);
int /*<<< orphan*/ err_log(int, int, char *, char *);
int /*<<< orphan*/ free(char *);
int pi_db_count_items(int what) {
  int count = 0;
  char *pe = NULL;
  switch (what) {
  case 0:
    db_get_song_count(&pe, &count);
    break;
  case 1:
    db_get_playlist_count(&pe, &count);
    break;
  }
  if (pe) {
    err_log(1, 0x00000004, "Error getting item count: %s\n", pe);
    free(pe);
  }
  return count;
}


x86 assembly (clang, -O0):
<pi_db_count_items>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
test   %eax,%eax
je     117e <pi_db_count_items+0x3e>
jmp    116d <pi_db_count_items+0x2d>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
je     1190 <pi_db_count_items+0x50>
jmp    119d <pi_db_count_items+0x5d>
lea    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <db_get_song_count@plt>
jmp    119d <pi_db_count_items+0x5d>
lea    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <db_get_playlist_count@plt>
cmpq   $0x0,-0x10(%rbp)
je     11cb <pi_db_count_items+0x8b>
mov    -0x10(%rbp),%rcx
mov    $0x1,%edi
mov    $0x4,%esi
lea    0xe43(%rip),%rdx
call   1040 <err_log@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pi_db_count_items>:
sub    $0x18,%rsp
movl   $0x0,0xc(%rsp)
movq   $0x0,0x10(%rsp)
cmp    $0x1,%edi
je     116f <pi_db_count_items+0x2f>
test   %edi,%edi
jne    11a8 <pi_db_count_items+0x68>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1060 <db_get_song_count@plt>
jmp    117e <pi_db_count_items+0x3e>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1050 <db_get_playlist_count@plt>
mov    0x10(%rsp),%rcx
test   %rcx,%rcx
je     11a8 <pi_db_count_items+0x68>
lea    0xe71(%rip),%rdx
mov    $0x1,%edi
mov    $0x4,%esi
call   1040 <err_log@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0xc(%rsp),%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Error getting item count: %s\0A\00"
define i32 @pi_db_count_items(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %2
store i32 0, i32* %3
store i8* null, i8** %4
%5 = load i32, i32* %2
switch i32 %5, label %10 [
i32 0, label %6
i32 1, label %8
]
6: ; preds = %1
%7 = call i32 @db_get_song_count(i8** %4, i32* %3)
br label %10
8: ; preds = %1
%9 = call i32 @db_get_playlist_count(i8** %4, i32* %3)
br label %10
10: ; preds = %1, %8, %6
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i8*, i8** %4
%15 = call i32 @err_log(i32 1, i32 4, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %4
%17 = call i32 @free(i8* %16)
br label %18
18: ; preds = %13, %10
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
@.str = [30 x i8] c"Error getting item count: %s\0A\00"
define i32 @pi_db_count_items(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
switch i32 %0, label %17 [
i32 0, label %6
i32 1, label %8
]
6: ; preds = %1
%7 = call i32 @db_get_song_count(i8** %3, i32* %2)
br label %10
8: ; preds = %1
%9 = call i32 @db_get_playlist_count(i8** %3, i32* %2)
br label %10
10: ; preds = %8, %6
%11 = load i8*, i8** %3
%12 = icmp eq i8* %11, null
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = call i32 @err_log(i32 1, i32 4, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %11)
%15 = load i8*, i8** %3
%16 = call i32 @free(i8* %15)
br label %17
17: ; preds = %1, %13, %10
%18 = load i32, i32* %2
ret i32 %18
}