#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*/ F_OK;
int access(char *, int /*<<< orphan*/);
char *calloc(scalar_t__, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strlen(char *);
char *username();
char *user_has_prof() {
  char *uname = username();
  if (!uname) {
    return NULL;
  }
  char *new = calloc(strlen(uname) + 5 + strlen("/etc/ttydm/"), sizeof(char));
  if (new) {
    strcat(new, "/etc/ttydm/");
    strcat(new, uname);
    strcat(new, ".bmp");
    if (access(new, F_OK) != -1) {
      return new;
    }
    free(new);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<user_has_prof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <username@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118b <user_has_prof+0x2b>
movq   $0x0,-0x8(%rbp)
jmp    122e <user_has_prof+0xce>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x5,%rax
mov    %rax,-0x20(%rbp)
lea    0xe5d(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1226 <user_has_prof+0xc6>
mov    -0x18(%rbp),%rdi
lea    0xe2d(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xe1c(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     121d <user_has_prof+0xbd>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    122e <user_has_prof+0xce>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<user_has_prof>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <username@plt>
test   %rax,%rax
je     11dc <user_has_prof+0x7c>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x10(%rax),%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     11da <user_has_prof+0x7a>
mov    %rax,%rbx
lea    0xe66(%rip),%rsi
mov    %rax,%rdi
call   1080 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
jne    11dc <user_has_prof+0x7c>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/etc/ttydm/\00"
@.str.1 = [5 x i8] c".bmp\00"
@F_OK = global i32 0
define i8* @user_has_prof() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i8* (...) @username()
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %0
store i8* null, i8** %1
br label %35
8: ; preds = %0
%9 = load i8*, i8** %2
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %10, 5
%12 = call i64 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = add nsw i64 %11, %12
%14 = call i8* @calloc(i64 %13, i32 1)
store i8* %14, i8** %3
%15 = load i8*, i8** %3
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %34
17: ; preds = %8
%18 = load i8*, i8** %3
%19 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%20 = load i8*, i8** %3
%21 = load i8*, i8** %2
%22 = call i32 @strcat(i8* %20, i8* %21)
%23 = load i8*, i8** %3
%24 = call i32 @strcat(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%25 = load i8*, i8** %3
%26 = load i32, i32* @F_OK
%27 = call i32 @access(i8* %25, i32 %26)
%28 = icmp ne i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %17
%30 = load i8*, i8** %3
store i8* %30, i8** %1
br label %35
31: ; preds = %17
%32 = load i8*, i8** %3
%33 = call i32 @free(i8* %32)
br label %34
34: ; preds = %31, %8
store i8* null, i8** %1
br label %35
35: ; preds = %34, %29, %7
%36 = load i8*, i8** %1
ret i8* %36
}

LLVM IR (-O2):
@.str = [12 x i8] c"/etc/ttydm/\00"
@.str.1 = [5 x i8] c".bmp\00"
@F_OK = global i32 0
define i8* @user_has_prof() {
%1 = tail call i8* (...) @username()
%2 = icmp eq i8* %1, null
br i1 %2, label %17, label %3
3: ; preds = %0
%4 = tail call i64 @strlen(i8* %1)
%5 = add nsw i64 %4, 16
%6 = tail call i8* @calloc(i64 %5, i32 1)
%7 = icmp eq i8* %6, null
br i1 %7, label %17, label %8
8: ; preds = %3
%9 = tail call i32 @strcat(i8* %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @strcat(i8* %6, i8* %1)
%11 = tail call i32 @strcat(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @F_OK
%13 = tail call i32 @access(i8* %6, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = tail call i32 @free(i8* %6)
br label %17
17: ; preds = %8, %15, %3, %0
%18 = phi i8* [ null, %0 ], [ %6, %8 ], [ null, %15 ], [ null, %3 ]
ret i8* %18
}