#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 */
long atol(char *);
char *get_table_name(char *, char *);
char *pipe2string(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
long int folder_menu_fetch_folder_count(char *application_name,
                                        char *folder_name) {
  char *table_name;
  char sys_string[256];
  char *results;
  table_name = get_table_name(application_name, folder_name);
  sprintf(sys_string, "echo \"select count(*) from %s;\" | sql_timeout.sh 1",
          table_name);
  if ((results = pipe2string(sys_string)))
    return atol(pipe2string(sys_string));
  else
    return 0;
}


x86 assembly (clang, -O0):
<folder_menu_fetch_folder_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <get_table_name@plt>
mov    %rax,-0x20(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe8a(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x120(%rbp),%rdi
call   1040 <pipe2string@plt>
mov    %rax,-0x128(%rbp)
cmp    $0x0,%rax
je     11b5 <folder_menu_fetch_folder_count+0x75>
lea    -0x120(%rbp),%rdi
call   1040 <pipe2string@plt>
mov    %rax,%rdi
call   1050 <atol@plt>
mov    %rax,-0x8(%rbp)
jmp    11bd <folder_menu_fetch_folder_count+0x7d>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<folder_menu_fetch_folder_count>:
push   %rbx
sub    $0x100,%rsp
call   1030 <get_table_name@plt>
lea    0xeac(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rax,%rdx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <pipe2string@plt>
test   %rax,%rax
je     1181 <folder_menu_fetch_folder_count+0x41>
mov    %rsp,%rdi
call   1040 <pipe2string@plt>
mov    %rax,%rdi
call   1050 <atol@plt>
jmp    1183 <folder_menu_fetch_folder_count+0x43>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [51 x i8] c"echo \22select count(*) from %s;\22 | sql_timeout.sh 1\00"
define i64 @folder_menu_fetch_folder_count(i8* %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [256 x i8]
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i8* @get_table_name(i8* %9, i8* %10)
store i8* %11, i8** %6
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%13 = load i8*, i8** %6
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%16 = call i8* @pipe2string(i8* %15)
store i8* %16, i8** %8
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%20 = call i8* @pipe2string(i8* %19)
%21 = call i64 @atol(i8* %20)
store i64 %21, i64* %3
br label %23
22: ; preds = %2
store i64 0, i64* %3
br label %23
23: ; preds = %22, %18
%24 = load i64, i64* %3
ret i64 %24
}

LLVM IR (-O2):
@.str = [51 x i8] c"echo \22select count(*) from %s;\22 | sql_timeout.sh 1\00"
define i64 @folder_menu_fetch_folder_count(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i8* @get_table_name(i8* %0, i8* %1)
%6 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = call i8* @pipe2string(i8* %4)
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = call i8* @pipe2string(i8* %4)
%11 = call i64 @atol(i8* %10)
br label %12
12: ; preds = %2, %9
%13 = phi i64 [ %11, %9 ], [ 0, %2 ]
ret i64 %13
}