#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*/ newname;

/* Variables and functions */
int /*<<< orphan*/ *strchr(char const *const, char);
int /*<<< orphan*/ strcpy(char *, char const *const);
int strlen(char const *const);
const char *aim_normalize_room_name(const char *const name) {
  static char newname[2048];
  if (name == NULL)
    return (NULL);
  if (strchr(name + 1, ':') != NULL)
    return name;
  if (strlen(name) >= (sizeof(newname) - 2))
    return (NULL);
  strcpy(newname, "4:");
  strcpy(newname + 2, name);
  return (newname);
}


x86 assembly (clang, -O0):
<aim_normalize_room_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <aim_normalize_room_name+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11cf <aim_normalize_room_name+0x9f>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     117d <aim_normalize_room_name+0x4d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11cf <aim_normalize_room_name+0x9f>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cltq
cmp    $0x7fe,%rax
jb     11a1 <aim_normalize_room_name+0x71>
movq   $0x0,-0x8(%rbp)
jmp    11cf <aim_normalize_room_name+0x9f>
lea    0x2ea8(%rip),%rdi
lea    0xe51(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rsi
lea    0x2e93(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2e85(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aim_normalize_room_name>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     115e <aim_normalize_room_name+0x2e>
mov    %rdi,%rbx
add    $0x1,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
jne    118a <aim_normalize_room_name+0x5a>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x7fd,%eax
jbe    1162 <aim_normalize_room_name+0x32>
xor    %ebx,%ebx
jmp    118a <aim_normalize_room_name+0x5a>
lea    0x2ee7(%rip),%r14
lea    0xe90(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
lea    0x2ed3(%rip),%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@aim_normalize_room_name.newname = internal global [2048 x i8] zeroinitializer
@.str = [3 x i8] c"4:\00"
define i8* @aim_normalize_room_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %7
6: ; preds = %1
store i8* null, i8** %2
br label %24
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = call i32* @strchr(i8* %9, i8 signext 58)
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = load i8*, i8** %3
store i8* %13, i8** %2
br label %24
14: ; preds = %7
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = sext i32 %16 to i64
%18 = icmp uge i64 %17, 2046
br i1 %18, label %19, label %20
19: ; preds = %14
store i8* null, i8** %2
br label %24
20: ; preds = %14
%21 = call i32 @strcpy(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @aim_normalize_room_name.newname, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%22 = load i8*, i8** %3
%23 = call i32 @strcpy(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @aim_normalize_room_name.newname, i64 0, i64 2), i8* %22)
store i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @aim_normalize_room_name.newname, i64 0, i64 0), i8** %2
br label %24
24: ; preds = %20, %19, %12, %6
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
@aim_normalize_room_name.newname = internal global [2048 x i8] zeroinitializer
@.str = [3 x i8] c"4:\00"
define i8* @aim_normalize_room_name(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %13, label %3
3: ; preds = %1
%4 = getelementptr inbounds i8, i8* %0, i64 1
%5 = tail call i32* @strchr(i8* %4, i8 signext 58)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %13
7: ; preds = %3
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp ugt i32 %8, 2045
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32 @strcpy(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @aim_normalize_room_name.newname, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @strcpy(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @aim_normalize_room_name.newname, i64 0, i64 2), i8* %0)
br label %13
13: ; preds = %7, %3, %1, %10
%14 = phi i8* [ getelementptr inbounds ([2048 x i8], [2048 x i8]* @aim_normalize_room_name.newname, i64 0, i64 0), %10 ], [ null, %1 ], [ %0, %3 ], [ null, %7 ]
ret i8* %14
}