#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);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *Clean(char *linea) {
  int n = strlen(linea);
  int i;
  char *rstr;
  rstr = malloc(sizeof(char) * 500);
  for (i = 0; i < n; i++) {
    if (linea[i] == '#') {
      if (i == 0) {
        return "";
      } else {
        strncpy(rstr, linea, i);
        return rstr;
      }
    }
  }
  return linea;
}


x86 assembly (clang, -O0):
<Clean>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    $0x1f4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c8 <Clean+0x98>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x23,%eax
jne    11b5 <Clean+0x85>
cmpl   $0x0,-0x18(%rbp)
jne    1198 <Clean+0x68>
lea    0xe71(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11d0 <Clean+0xa0>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d0 <Clean+0xa0>
jmp    11ba <Clean+0x8a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115d <Clean+0x2d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Clean>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    $0x1f4,%edi
call   1050 <malloc@plt>
test   %ebp,%ebp
jle    116f <Clean+0x3f>
mov    %rax,%r14
mov    %ebp,%eax
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0x23,(%rbx,%rdx,1)
je     1174 <Clean+0x44>
add    $0x1,%rdx
cmp    %rdx,%rax
jne    1160 <Clean+0x30>
mov    %rbx,%r14
jmp    118c <Clean+0x5c>
test   %edx,%edx
je     1185 <Clean+0x55>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
jmp    118c <Clean+0x5c>
lea    0xe74(%rip),%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @Clean(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %4
%9 = call i8* @malloc(i32 500)
store i8* %9, i8** %6
store i32 0, i32* %5
br label %10
10: ; preds = %33, %1
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %36
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 35
br i1 %21, label %22, label %32
22: ; preds = %14
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
br label %38
26: ; preds = %22
%27 = load i8*, i8** %6
%28 = load i8*, i8** %3
%29 = load i32, i32* %5
%30 = call i32 @strncpy(i8* %27, i8* %28, i32 %29)
%31 = load i8*, i8** %6
store i8* %31, i8** %2
br label %38
32: ; preds = %14
br label %33
33: ; preds = %32
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %10
36: ; preds = %10
%37 = load i8*, i8** %3
store i8* %37, i8** %2
br label %38
38: ; preds = %36, %26, %25
%39 = load i8*, i8** %2
ret i8* %39
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @Clean(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call dereferenceable_or_null(500) i8* @malloc(i32 500)
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %20
5: ; preds = %1
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %17
%8 = phi i64 [ 0, %5 ], [ %18, %17 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 35
br i1 %11, label %12, label %17
12: ; preds = %7
%13 = trunc i64 %8 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %12
%16 = tail call i32 @strncpy(i8* %3, i8* %0, i32 %13)
br label %20
17: ; preds = %7
%18 = add nuw nsw i64 %8, 1
%19 = icmp eq i64 %18, %6
br i1 %19, label %20, label %7
20: ; preds = %17, %1, %12, %15
%21 = phi i8* [ %3, %15 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %12 ], [ %0, %1 ], [ %0, %17 ]
ret i8* %21
}