#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 *malloc(int);
size_t strlen(char *);
char *pickNameFunc(char str[]) {
  size_t len = strlen(str);
  char *name_func = malloc(8192 * sizeof(char));
  int i = 0;
  while (i < len && str[i] != '(') {
    name_func[i] = str[i];
    i++;
  }
  if (i == len) {
    return NULL;
  }
  name_func[i] = '\0';
  return (char *)name_func;
}


x86 assembly (clang, -O0):
<pickNameFunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    $0x2000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x25(%rbp)
jae    1176 <pickNameFunc+0x56>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x28,%eax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1186 <pickNameFunc+0x66>
jmp    11aa <pickNameFunc+0x8a>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114e <pickNameFunc+0x2e>
movslq -0x24(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11c5 <pickNameFunc+0xa5>
movq   $0x0,-0x8(%rbp)
jmp    11d9 <pickNameFunc+0xb9>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pickNameFunc>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r14
mov    $0x2000,%edi
call   1040 <malloc@plt>
test   %r14,%r14
je     115f <pickNameFunc+0x3f>
xor    %ecx,%ecx
movzbl (%rbx,%rcx,1),%edx
cmp    $0x28,%dl
je     1158 <pickNameFunc+0x38>
mov    %dl,(%rax,%rcx,1)
add    $0x1,%rcx
cmp    %rcx,%r14
jne    1140 <pickNameFunc+0x20>
mov    %r14,%rcx
mov    %ecx,%ecx
cmp    %rcx,%r14
jne    1163 <pickNameFunc+0x43>
xor    %eax,%eax
jmp    1167 <pickNameFunc+0x47>
movb   $0x0,(%rax,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @pickNameFunc(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %4
%9 = call i8* @malloc(i32 8192)
store i8* %9, i8** %5
store i32 0, i32* %6
br label %10
10: ; preds = %25, %1
%11 = load i32, i32* %6
%12 = sext i32 %11 to i64
%13 = load i64, i64* %4
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %23
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 40
br label %23
23: ; preds = %15, %10
%24 = phi i1 [ false, %10 ], [ %22, %15 ]
br i1 %24, label %25, label %37
25: ; preds = %23
%26 = load i8*, i8** %3
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = load i8*, i8** %5
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 %30, i8* %34
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %10
37: ; preds = %23
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = load i64, i64* %4
%41 = icmp eq i64 %39, %40
br i1 %41, label %42, label %43
42: ; preds = %37
store i8* null, i8** %2
br label %49
43: ; preds = %37
%44 = load i8*, i8** %5
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 0, i8* %47
%48 = load i8*, i8** %5
store i8* %48, i8** %2
br label %49
49: ; preds = %43, %42
%50 = load i8*, i8** %2
ret i8* %50
}

LLVM IR (-O2):
define noalias i8* @pickNameFunc(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = tail call dereferenceable_or_null(8192) i8* @malloc(i32 8192)
%4 = icmp eq i64 %2, 0
br i1 %4, label %20, label %5
5: ; preds = %1, %10
%6 = phi i64 [ %12, %10 ], [ 0, %1 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 40
br i1 %9, label %14, label %10
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %3, i64 %6
store i8 %8, i8* %11
%12 = add nuw i64 %6, 1
%13 = icmp eq i64 %12, %2
br i1 %13, label %14, label %5
14: ; preds = %5, %10
%15 = phi i64 [ %6, %5 ], [ %2, %10 ]
%16 = and i64 %15, 4294967295
%17 = icmp eq i64 %2, %16
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = getelementptr inbounds i8, i8* %3, i64 %16
store i8 0, i8* %19
br label %20
20: ; preds = %1, %14, %18
%21 = phi i8* [ %3, %18 ], [ null, %14 ], [ null, %1 ]
ret i8* %21
}