#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  int totalLen = 0;
  FILE *db;
  db = fopen("data/userdata.db", "a");
  char *prefix = "UserName:";
  char *cardid = argv[1];
  char *username =
      (char *)malloc((strlen(prefix) + strlen(cardid)) * sizeof(char));
  strcat(username, prefix);
  strcat(username, cardid);
  fprintf(db, "%s\n", username);
  fclose(db);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe83(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    0xe7f(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xe23(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
lea    0xe8f(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
mov    0x8(%rbx),%rbx
lea    0xe88(%rip),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %eax,%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1080 <strcat@plt>
lea    0xe57(%rip),%rsi
mov    %r14,%rdi
mov    %rbp,%rdx
call   1050 <fprintf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"data/userdata.db\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [10 x i8] c"UserName:\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 0, i32* %5
%10 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %6
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8** %7
%11 = load i8**, i8*** %4
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %8
%14 = load i8*, i8** %7
%15 = call i32 @strlen(i8* %14)
%16 = load i8*, i8** %8
%17 = call i32 @strlen(i8* %16)
%18 = add nsw i32 %15, %17
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 1
%21 = trunc i64 %20 to i32
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %9
%24 = load i8*, i8** %9
%25 = load i8*, i8** %7
%26 = call i32 @strcat(i8* %24, i8* %25)
%27 = load i8*, i8** %9
%28 = load i8*, i8** %8
%29 = call i32 @strcat(i8* %27, i8* %28)
%30 = load i32*, i32** %6
%31 = load i8*, i8** %9
%32 = call i32 @fprintf(i32* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = load i32*, i32** %6
%34 = call i32 @fclose(i32* %33)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"data/userdata.db\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [10 x i8] c"UserName:\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @strlen(i8* %5)
%8 = add nsw i32 %7, %6
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @strcat(i8* %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @strcat(i8* %10, i8* %5)
%13 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%14 = tail call i32 @fclose(i32* %3)
ret i32 0
}