#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 */
char *config_get(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *get_user_name(int num) {
  char *p, *username, name[32];
  sprintf(name, "sharename%d", num);
  username = config_get(name);
  if (*username == '\0') {
    return username;
  }
  p = username;
  while (*p != ' ')
    p++;
  *p = '\0';
  return username;
}


x86 assembly (clang, -O0):
<get_user_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xec7(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x40(%rbp),%rdi
call   1030 <config_get@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1168 <get_user_name+0x48>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a0 <get_user_name+0x80>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     1191 <get_user_name+0x71>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1170 <get_user_name+0x50>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_user_name>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%edx
lea    0xed2(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <config_get@plt>
mov    (%rax),%dl
test   %dl,%dl
je     1170 <get_user_name+0x50>
mov    %rax,%rcx
cmp    $0x20,%dl
je     116d <get_user_name+0x4d>
mov    %rax,%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rdx),%rcx
cmpb   $0x20,0x1(%rdx)
mov    %rcx,%rdx
jne    1160 <get_user_name+0x40>
movb   $0x0,(%rcx)
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"sharename%d\00"
define i8* @get_user_name(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [32 x i8]
store i32 %0, i32* %3
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%8 = load i32, i32* %3
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%11 = call i8* @config_get(i8* %10)
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = load i8*, i8** %5
store i8* %17, i8** %2
br label %31
18: ; preds = %1
%19 = load i8*, i8** %5
store i8* %19, i8** %4
br label %20
20: ; preds = %25, %18
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 32
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
br label %20
28: ; preds = %20
%29 = load i8*, i8** %4
store i8 0, i8* %29
%30 = load i8*, i8** %5
store i8* %30, i8** %2
br label %31
31: ; preds = %28, %16
%32 = load i8*, i8** %2
ret i8* %32
}

LLVM IR (-O2):
@.str = [12 x i8] c"sharename%d\00"
define i8* @get_user_name(i32 %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = call i8* @config_get(i8* %3)
%6 = load i8, i8* %5
switch i8 %6, label %7 [
i8 0, label %14
i8 32, label %12
]
7: ; preds = %1, %7
%8 = phi i8* [ %9, %7 ], [ %5, %1 ]
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 32
br i1 %11, label %12, label %7
12: ; preds = %7, %1
%13 = phi i8* [ %5, %1 ], [ %9, %7 ]
store i8 0, i8* %13
br label %14
14: ; preds = %1, %12
ret i8* %5
}