#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 *remove_line_comment(char *line) {
  int within_quoted_str = 0;
  int i = 0;
  int len = strlen(line);
  while (i < len) {
    char character = line[i];
    if (character == 0x22) {
      within_quoted_str = !within_quoted_str;
    }
    if (character == 0x3B && !within_quoted_str) {
      char *result = malloc(sizeof(char) * i);
      strncpy(result, line, i);
      return result;
    }
    i++;
  }
  return line;
}


x86 assembly (clang, -O0):
<remove_line_comment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e3 <remove_line_comment+0xb3>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0x22,%eax
jne    118e <remove_line_comment+0x5e>
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0x3b,%eax
jne    11d5 <remove_line_comment+0xa5>
cmpl   $0x0,-0x14(%rbp)
jne    11d5 <remove_line_comment+0xa5>
movslq -0x18(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11eb <remove_line_comment+0xbb>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1156 <remove_line_comment+0x26>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_line_comment>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
test   %eax,%eax
jle    118e <remove_line_comment+0x5e>
mov    %eax,%esi
xor    %ebx,%ebx
xor    %ecx,%ecx
jmp    1159 <remove_line_comment+0x29>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%rsi
je     118e <remove_line_comment+0x5e>
mov    %ecx,%edx
movzbl (%r14,%rbx,1),%eax
xor    %ecx,%ecx
test   %edx,%edx
sete   %cl
cmp    $0x22,%al
cmovne %edx,%ecx
cmp    $0x3b,%al
jne    1150 <remove_line_comment+0x20>
test   %ecx,%ecx
jne    1150 <remove_line_comment+0x20>
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
mov    %r15,%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @remove_line_comment(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %25
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %22
%7 = phi i64 [ 0, %4 ], [ %23, %22 ]
%8 = phi i32 [ 0, %4 ], [ %14, %22 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 34
%12 = icmp eq i32 %8, 0
%13 = zext i1 %12 to i32
%14 = select i1 %11, i32 %13, i32 %8
%15 = icmp ne i8 %10, 59
%16 = icmp ne i32 %14, 0
%17 = select i1 %15, i1 true, i1 %16
br i1 %17, label %22, label %18
18: ; preds = %6
%19 = trunc i64 %7 to i32
%20 = tail call i8* @malloc(i32 %19)
%21 = tail call i32 @strncpy(i8* %20, i8* %0, i32 %19)
br label %25
22: ; preds = %6
%23 = add nuw nsw i64 %7, 1
%24 = icmp eq i64 %23, %5
br i1 %24, label %25, label %6
25: ; preds = %22, %1, %18
%26 = phi i8* [ %20, %18 ], [ %0, %1 ], [ %0, %22 ]
ret i8* %26
}