#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 */
struct user_t {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ logprintf(int, char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ validate_nick(char *, struct user_t *);
void validate_fbuser(char *fbuser, struct user_t *user) {
  char *validateNickCmd = "$ValidateNick ";
  char *command = NULL;
  if (fbuser) {
    command = (char *)malloc(strlen(validateNickCmd) + strlen(fbuser) + 1);
    if (command) {
      strcpy(command, validateNickCmd);
      strcat(command, fbuser);
      validate_nick(command, user);
      free(command);
    } else {
      logprintf(4, "Malloc failed. validate_fbuser()");
    }
  }
}


x86 assembly (clang, -O0):
<validate_fbuser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe79(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     121e <validate_fbuser+0xae>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1208 <validate_fbuser+0x98>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <validate_nick@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    1219 <validate_fbuser+0xa9>
mov    $0x4,%edi
lea    0xdfb(%rip),%rsi
call   1090 <logprintf@plt>
jmp    121e <validate_fbuser+0xae>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_fbuser>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     11c8 <validate_fbuser+0x58>
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <strlen@plt>
lea    0xf(%rax),%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     11ce <validate_fbuser+0x5e>
mov    %rax,%rbx
lea    0xe63(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <validate_nick@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe3a(%rip),%rsi
mov    $0x4,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1090 <logprintf@plt>

LLVM IR (-O0):
%struct.user_t = type { i32 }
@.str = [15 x i8] c"$ValidateNick \00"
@.str.1 = [33 x i8] c"Malloc failed. validate_fbuser()\00"
define void @validate_fbuser(i8* %0, %struct.user_t* %1) {
%3 = alloca i8*
%4 = alloca %struct.user_t*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store %struct.user_t* %1, %struct.user_t** %4
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %5
store i8* null, i8** %6
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %35
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = load i8*, i8** %3
%13 = call i64 @strlen(i8* %12)
%14 = add nsw i64 %11, %13
%15 = add nsw i64 %14, 1
%16 = call i64 @malloc(i64 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %32
20: ; preds = %9
%21 = load i8*, i8** %6
%22 = load i8*, i8** %5
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = load i8*, i8** %6
%25 = load i8*, i8** %3
%26 = call i32 @strcat(i8* %24, i8* %25)
%27 = load i8*, i8** %6
%28 = load %struct.user_t*, %struct.user_t** %4
%29 = call i32 @validate_nick(i8* %27, %struct.user_t* %28)
%30 = load i8*, i8** %6
%31 = call i32 @free(i8* %30)
br label %34
32: ; preds = %9
%33 = call i32 @logprintf(i32 4, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %20
br label %35
35: ; preds = %34, %2
ret void
}

LLVM IR (-O2):
%struct.user_t = type { i32 }
@.str = [15 x i8] c"$ValidateNick \00"
@.str.1 = [33 x i8] c"Malloc failed. validate_fbuser()\00"
define void @validate_fbuser(i8* %0, %struct.user_t* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %17, label %4
4: ; preds = %2
%5 = tail call i64 @strlen(i8* %0)
%6 = add nsw i64 %5, 15
%7 = tail call i64 @malloc(i64 %6)
%8 = inttoptr i64 %7 to i8*
%9 = icmp eq i64 %7, 0
br i1 %9, label %15, label %10
10: ; preds = %4
%11 = tail call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @strcat(i8* %8, i8* %0)
%13 = tail call i32 @validate_nick(i8* %8, %struct.user_t* %1)
%14 = tail call i32 @free(i8* %8)
br label %17
15: ; preds = %4
%16 = tail call i32 @logprintf(i32 4, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %10, %15, %2
ret void
}