#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 i0(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
int show_database(char *info, size_t n) {
  int return_code;
  char bss_command[1024];
  char bss_result[1024];
  sprintf(bss_command, "info databases");
  if ((return_code = i0(bss_command, bss_result)) == 0) {
    strncpy(info, bss_result, n);
    return 0;
  } else {
    return -1;
  }
}


x86 assembly (clang, -O0):
<show_database>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
lea    0xeaf(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x420(%rbp),%rdi
lea    -0x820(%rbp),%rsi
call   1050 <i0@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    1195 <show_database+0x65>
mov    -0x10(%rbp),%rdi
lea    -0x820(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    119c <show_database+0x6c>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_database>:
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movabs $0x746164206f666e69,%rax
64 61 74
mov    %rax,(%rsp)
movabs $0x73657361626174,%rax
mov    %rax,0x7(%rsp)
mov    %rsp,%rdi
lea    0x400(%rsp),%rsi
call   1040 <i0@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
jne    117d <show_database+0x5d>
lea    0x400(%rsp),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <strncpy@plt>
xor    %eax,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [15 x i8] c"info databases\00"
define i32 @show_database(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
store i8* %0, i8** %4
store i64 %1, i64* %5
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%10 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%13 = call i32 @i0(i8* %11, i8* %12)
store i32 %13, i32* %6
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%18 = load i64, i64* %5
%19 = call i32 @strncpy(i8* %16, i8* %17, i64 %18)
store i32 0, i32* %3
br label %21
20: ; preds = %2
store i32 -1, i32* %3
br label %21
21: ; preds = %20, %15
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@.str = [15 x i8] c"info databases\00"
define i32 @show_database(i8* %0, i64 %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32 @i0(i8* %5, i8* %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @strncpy(i8* %0, i8* %6, i64 %1)
br label %11
11: ; preds = %2, %9
%12 = phi i32 [ 0, %9 ], [ -1, %2 ]
ret i32 %12
}