#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*/ closeDatabase();
int /*<<< orphan*/ executeSQL(char *, int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ openDB(char *);
int /*<<< orphan*/ print_sql_header();
int /*<<< orphan*/ showAffected();
int /*<<< orphan*/ sprintf(char *, char *, char const *);
void show_user(char *dbname, const char *user) {
  char *newSQL = malloc(255);
  if (user != NULL)
    sprintf(newSQL,
            "SELECT username, enabled FROM users WHERE username LIKE '%s'",
            user);
  else
    sprintf(newSQL, "SELECT username, enabled FROM users ORDER BY username ASC",
            user);
  openDB(dbname);
  print_sql_header();
  executeSQL(newSQL, 1);
  showAffected();
  closeDatabase();
  free(newSQL);
  return;
}


x86 assembly (clang, -O0):
<show_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0xff,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c2 <show_user+0x42>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe48(%rip),%rsi
call   10a0 <sprintf@plt>
jmp    11d6 <show_user+0x56>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe6c(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <openDB@plt>
mov    $0x0,%al
call   1090 <print_sql_header@plt>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1080 <executeSQL@plt>
mov    $0x0,%al
call   1060 <showAffected@plt>
mov    $0x0,%al
call   1070 <closeDatabase@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_user>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0xff,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
test   %rbx,%rbx
je     11ac <show_user+0x2c>
lea    0xe5c(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
jmp    11b8 <show_user+0x38>
lea    0xe8a(%rip),%rsi
mov    %r15,%rdi
xor    %edx,%edx
call   10a0 <sprintf@plt>
mov    %r14,%rdi
call   1040 <openDB@plt>
xor    %eax,%eax
call   1090 <print_sql_header@plt>
mov    %r15,%rdi
mov    $0x1,%esi
call   1080 <executeSQL@plt>
xor    %eax,%eax
call   1060 <showAffected@plt>
xor    %eax,%eax
call   1070 <closeDatabase@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [61 x i8] c"SELECT username, enabled FROM users WHERE username LIKE '%s'\00"
@.str.1 = [58 x i8] c"SELECT username, enabled FROM users ORDER BY username ASC\00"
define void @show_user(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = call i8* @malloc(i32 255)
store i8* %6, i8** %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = load i8*, i8** %4
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %17
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = load i8*, i8** %4
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %13, %9
%18 = load i8*, i8** %3
%19 = call i32 @openDB(i8* %18)
%20 = call i32 (...) @print_sql_header()
%21 = load i8*, i8** %5
%22 = call i32 @executeSQL(i8* %21, i32 1)
%23 = call i32 (...) @showAffected()
%24 = call i32 (...) @closeDatabase()
%25 = load i8*, i8** %5
%26 = call i32 @free(i8* %25)
ret void
}

LLVM IR (-O2):
@.str = [61 x i8] c"SELECT username, enabled FROM users WHERE username LIKE '%s'\00"
@.str.1 = [58 x i8] c"SELECT username, enabled FROM users ORDER BY username ASC\00"
define void @show_user(i8* %0, i8* %1) {
%3 = tail call dereferenceable_or_null(255) i8* @malloc(i32 255)
%4 = icmp eq i8* %1, null
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %9
7: ; preds = %2
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i8* null)
br label %9
9: ; preds = %7, %5
%10 = tail call i32 @openDB(i8* %0)
%11 = tail call i32 (...) @print_sql_header()
%12 = tail call i32 @executeSQL(i8* %3, i32 1)
%13 = tail call i32 (...) @showAffected()
%14 = tail call i32 (...) @closeDatabase()
%15 = tail call i32 @free(i8* %3)
ret void
}