#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 *conf_get_servername();
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
int pi_server_name(char *name, int *len) {
  char *servername;
  ;
  if ((!name) || (!len))
    return 0;
  servername = conf_get_servername();
  if ((servername) && (strlen(servername) < (size_t)len)) {
    strcpy(name, servername);
  } else {
    if ((size_t)len > strlen("Firefly Media Server"))
      strcpy(name, "Firefly Media Server");
  }
  free(servername);
  return 0;
}


x86 assembly (clang, -O0):
<pi_server_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1166 <pi_server_name+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1172 <pi_server_name+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11f9 <pi_server_name+0xb9>
mov    $0x0,%al
call   1060 <conf_get_servername@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b0 <pi_server_name+0x70>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x18(%rbp),%rcx
cmp    %rcx,%rax
jae    11b0 <pi_server_name+0x70>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    11e9 <pi_server_name+0xa9>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe41(%rip),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jbe    11e4 <pi_server_name+0xa4>
mov    -0x10(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1040 <strcpy@plt>
jmp    11e9 <pi_server_name+0xa9>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pi_server_name>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1196 <pi_server_name+0x56>
mov    %rsi,%rbx
test   %rsi,%rsi
je     1196 <pi_server_name+0x56>
mov    %rdi,%r15
xor    %eax,%eax
call   1060 <conf_get_servername@plt>
mov    %rax,%r14
test   %rax,%rax
je     1179 <pi_server_name+0x39>
mov    %r14,%rdi
call   1050 <strlen@plt>
cmp    %rbx,%rax
jae    1179 <pi_server_name+0x39>
mov    %r15,%rdi
mov    %r14,%rsi
jmp    1189 <pi_server_name+0x49>
cmp    $0x15,%rbx
jb     118e <pi_server_name+0x4e>
lea    0xe7a(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Firefly Media Server\00"
define i32 @pi_server_name(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %13, label %12
12: ; preds = %9, %2
store i32 0, i32* %3
br label %39
13: ; preds = %9
%14 = call i8* (...) @conf_get_servername()
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %27
17: ; preds = %13
%18 = load i8*, i8** %6
%19 = call i64 @strlen(i8* %18)
%20 = load i32*, i32** %5
%21 = ptrtoint i32* %20 to i64
%22 = icmp ult i64 %19, %21
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i8*, i8** %4
%25 = load i8*, i8** %6
%26 = call i32 @strcpy(i8* %24, i8* %25)
br label %36
27: ; preds = %17, %13
%28 = load i32*, i32** %5
%29 = ptrtoint i32* %28 to i64
%30 = call i64 @strlen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%31 = icmp ugt i64 %29, %30
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i8*, i8** %4
%34 = call i32 @strcpy(i8* %33, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %32, %27
br label %36
36: ; preds = %35, %23
%37 = load i8*, i8** %6
%38 = call i32 @free(i8* %37)
store i32 0, i32* %3
br label %39
39: ; preds = %36, %12
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [21 x i8] c"Firefly Media Server\00"
define i32 @pi_server_name(i8* %0, i32* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i32* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %21
6: ; preds = %2
%7 = tail call i8* (...) @conf_get_servername()
%8 = icmp eq i8* %7, null
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = tail call i64 @strlen(i8* %7)
%11 = ptrtoint i32* %1 to i64
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @strcpy(i8* %0, i8* %7)
br label %19
15: ; preds = %9, %6
%16 = icmp ugt i32* %1, inttoptr (i64 20 to i32*)
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %15, %17, %13
%20 = tail call i32 @free(i8* %7)
br label %21
21: ; preds = %2, %19
ret i32 0
}