#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 */
scalar_t__ invalid_nick(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, ...);
scalar_t__ strchr(char *, char);
int strlen(char *);
char *normalize_ban(char *src, char *dest, int destlen) {
  if (strchr(src, '!'))
    return src;
  else if (invalid_nick(src)) {
    char *star;
    if (*src && src[strlen(src) - 1] == '.')
      star = "*";
    else
      star = "";
    snprintf(dest, destlen, "*!%s%s", src, star);
  } else
    snprintf(dest, destlen, "%s!*", src);
  return dest;
}


x86 assembly (clang, -O0):
<normalize_ban>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x21,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1178 <normalize_ban+0x38>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1228 <normalize_ban+0xe8>
mov    -0x10(%rbp),%rdi
call   1060 <invalid_nick@plt>
cmp    $0x0,%rax
je     1202 <normalize_ban+0xc2>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d5 <normalize_ban+0x95>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    11d5 <normalize_ban+0x95>
lea    0xe3e(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11e0 <normalize_ban+0xa0>
lea    0xe2f(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe0a(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
jmp    121b <normalize_ban+0xdb>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rcx
lea    0xdf3(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
jmp    1220 <normalize_ban+0xe0>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize_ban>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x21,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1160 <normalize_ban+0x20>
mov    %rbx,%r14
jmp    11c1 <normalize_ban+0x81>
mov    %rbx,%rdi
call   1060 <invalid_nick@plt>
test   %rax,%rax
je     11ab <normalize_ban+0x6b>
cmpb   $0x0,(%rbx)
je     118c <normalize_ban+0x4c>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x2e,-0x1(%rax,%rbx,1)
jne    118c <normalize_ban+0x4c>
lea    0xe80(%rip),%r8
jmp    1193 <normalize_ban+0x53>
lea    0xe78(%rip),%r8
lea    0xe66(%rip),%rdx
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <snprintf@plt>
jmp    11c1 <normalize_ban+0x81>
lea    0xe55(%rip),%rdx
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"*\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [7 x i8] c"*!%s%s\00"
@.str.3 = [5 x i8] c"%s!*\00"
define i8* @normalize_ban(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = call i64 @strchr(i8* %9, i8 signext 33)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = load i8*, i8** %5
store i8* %13, i8** %4
br label %49
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = call i64 @invalid_nick(i8* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %41
18: ; preds = %14
%19 = load i8*, i8** %5
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %34
23: ; preds = %18
%24 = load i8*, i8** %5
%25 = load i8*, i8** %5
%26 = call i32 @strlen(i8* %25)
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %24, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 46
br i1 %32, label %33, label %34
33: ; preds = %23
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %8
br label %35
34: ; preds = %23, %18
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %35
35: ; preds = %34, %33
%36 = load i8*, i8** %6
%37 = load i32, i32* %7
%38 = load i8*, i8** %5
%39 = load i8*, i8** %8
%40 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %36, i32 %37, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %38, i8* %39)
br label %46
41: ; preds = %14
%42 = load i8*, i8** %6
%43 = load i32, i32* %7
%44 = load i8*, i8** %5
%45 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %42, i32 %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %41, %35
br label %47
47: ; preds = %46
%48 = load i8*, i8** %6
store i8* %48, i8** %4
br label %49
49: ; preds = %47, %12
%50 = load i8*, i8** %4
ret i8* %50
}

LLVM IR (-O2):
@.str = [2 x i8] c"*\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [7 x i8] c"*!%s%s\00"
@.str.3 = [5 x i8] c"%s!*\00"
define i8* @normalize_ban(i8* %0, i8* %1, i32 %2) {
%4 = tail call i64 @strchr(i8* %0, i8 signext 33)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %25
6: ; preds = %3
%7 = tail call i64 @invalid_nick(i8* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %23, label %9
9: ; preds = %6
%10 = load i8, i8* %0
%11 = icmp eq i8 %10, 0
br i1 %11, label %19, label %12
12: ; preds = %9
%13 = tail call i32 @strlen(i8* %0)
%14 = add nsw i32 %13, -1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 46
br i1 %18, label %20, label %19
19: ; preds = %12, %9
br label %20
20: ; preds = %12, %19
%21 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %19 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %12 ]
%22 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %21)
br label %25
23: ; preds = %6
%24 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %25
25: ; preds = %23, %20, %3
%26 = phi i8* [ %0, %3 ], [ %1, %20 ], [ %1, %23 ]
ret i8* %26
}