#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ isalnum(char);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int strlen(char *);
char *getValidatedNick(char *nick) {
  int i, j = 0, len = strlen(nick);
  char *newnick = (char *)malloc(sizeof(char) * len + 1);
  if (newnick == NULL) {
    fprintf(stderr, "Speicherallokationsfehler\n");
    exit(1);
  }
  for (i = 0; i < len; i++) {
    if (isalnum(nick[i]))
      newnick[j++] = nick[i];
  }
  newnick[j] = '\0';
  return newnick;
}


x86 assembly (clang, -O0):
<getValidatedNick>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b0 <getValidatedNick+0x60>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1211 <getValidatedNick+0xc1>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%rax
je     11fe <getValidatedNick+0xae>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1203 <getValidatedNick+0xb3>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b7 <getValidatedNick+0x67>
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getValidatedNick>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%r15d
lea    0x1(%r15),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11cf <getValidatedNick+0x7f>
mov    %rax,%r14
test   %r15d,%r15d
jle    11b9 <getValidatedNick+0x69>
mov    %r15d,%r15d
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1199 <getValidatedNick+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r15
je     11bb <getValidatedNick+0x6b>
movsbl (%r12,%rbx,1),%edi
call   1040 <isalnum@plt>
test   %rax,%rax
je     1190 <getValidatedNick+0x40>
movzbl (%r12,%rbx,1),%eax
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %al,(%r14,%rcx,1)
jmp    1190 <getValidatedNick+0x40>
xor    %ebp,%ebp
movslq %ebp,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Speicherallokationsfehler\0A\00"
define i8* @getValidatedNick(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %4
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = mul i64 1, %10
%12 = add i64 %11, 1
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %1
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %1
store i32 0, i32* %3
br label %23
23: ; preds = %47, %22
%24 = load i32, i32* %3
%25 = load i32, i32* %5
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %50
27: ; preds = %23
%28 = load i8*, i8** %2
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = call i64 @isalnum(i8 signext %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %46
35: ; preds = %27
%36 = load i8*, i8** %2
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = load i8*, i8** %6
%42 = load i32, i32* %4
%43 = add nsw i32 %42, 1
store i32 %43, i32* %4
%44 = sext i32 %42 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
store i8 %40, i8* %45
br label %46
46: ; preds = %35, %27
br label %47
47: ; preds = %46
%48 = load i32, i32* %3
%49 = add nsw i32 %48, 1
store i32 %49, i32* %3
br label %23
50: ; preds = %23
%51 = load i8*, i8** %6
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 0, i8* %54
%55 = load i8*, i8** %6
ret i8* %55
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Speicherallokationsfehler\0A\00"
define i8* @getValidatedNick(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add i32 %2, 1
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %31
9: ; preds = %7
%10 = zext i32 %2 to i64
br label %15
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %9, %27
%16 = phi i64 [ 0, %9 ], [ %29, %27 ]
%17 = phi i32 [ 0, %9 ], [ %28, %27 ]
%18 = getelementptr inbounds i8, i8* %0, i64 %16
%19 = load i8, i8* %18
%20 = tail call i64 @isalnum(i8 signext %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %15
%23 = load i8, i8* %18
%24 = add nsw i32 %17, 1
%25 = sext i32 %17 to i64
%26 = getelementptr inbounds i8, i8* %5, i64 %25
store i8 %23, i8* %26
br label %27
27: ; preds = %15, %22
%28 = phi i32 [ %24, %22 ], [ %17, %15 ]
%29 = add nuw nsw i64 %16, 1
%30 = icmp eq i64 %29, %10
br i1 %30, label %31, label %15
31: ; preds = %27, %7
%32 = phi i32 [ 0, %7 ], [ %28, %27 ]
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %5, i64 %33
store i8 0, i8* %34
ret i8* %5
}