#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__ calloc(size_t, int);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
unsigned char *strchr(unsigned char *, char);
size_t strlen(unsigned char *);
int /*<<< orphan*/ strncpy(unsigned char *, unsigned char *, size_t);
unsigned char *remove_comment(unsigned char *in_str) {
  size_t in_str_len, alloc_size;
  unsigned char *out_str, *ret_str;
  in_str_len = strlen(in_str);
  out_str = strchr(in_str, ';');
  if (!out_str)
    out_str = in_str + in_str_len;
  alloc_size = out_str - in_str;
  ret_str = (unsigned char *)calloc(alloc_size + 1, sizeof(char));
  if (!(ret_str)) {
    perror(NULL);
    return NULL;
  };
  strncpy(ret_str, in_str, alloc_size);
  ret_str[alloc_size] = '\0';
  return ret_str;
}


x86 assembly (clang, -O0):
<remove_comment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3b,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1192 <remove_comment+0x42>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11d8 <remove_comment+0x88>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11fd <remove_comment+0xad>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_comment>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x3b,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1178 <remove_comment+0x28>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
add    %r14,%rbx
sub    %r14,%rbx
lea    0x1(%rbx),%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     11ad <remove_comment+0x5d>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %r15d,%r15d
xor    %edi,%edi
call   1070 <perror@plt>
jmp    11a4 <remove_comment+0x54>

LLVM IR (-O0):
define i8* @remove_comment(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %4
%10 = load i8*, i8** %3
%11 = call i8* @strchr(i8* %10, i8 signext 59)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %18, label %14
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = load i64, i64* %4
%17 = getelementptr inbounds i8, i8* %15, i64 %16
store i8* %17, i8** %6
br label %18
18: ; preds = %14, %1
%19 = load i8*, i8** %6
%20 = load i8*, i8** %3
%21 = ptrtoint i8* %19 to i64
%22 = ptrtoint i8* %20 to i64
%23 = sub i64 %21, %22
store i64 %23, i64* %5
%24 = load i64, i64* %5
%25 = add i64 %24, 1
%26 = call i64 @calloc(i64 %25, i32 1)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = icmp ne i8* %28, null
br i1 %29, label %32, label %30
30: ; preds = %18
%31 = call i32 @perror(i32* null)
store i8* null, i8** %2
br label %41
32: ; preds = %18
%33 = load i8*, i8** %7
%34 = load i8*, i8** %3
%35 = load i64, i64* %5
%36 = call i32 @strncpy(i8* %33, i8* %34, i64 %35)
%37 = load i8*, i8** %7
%38 = load i64, i64* %5
%39 = getelementptr inbounds i8, i8* %37, i64 %38
store i8 0, i8* %39
%40 = load i8*, i8** %7
store i8* %40, i8** %2
br label %41
41: ; preds = %32, %30
%42 = load i8*, i8** %2
ret i8* %42
}

LLVM IR (-O2):
define i8* @remove_comment(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 59)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = getelementptr inbounds i8, i8* %0, i64 %5
br label %7
7: ; preds = %4, %1
%8 = phi i8* [ %2, %1 ], [ %6, %4 ]
%9 = ptrtoint i8* %8 to i64
%10 = ptrtoint i8* %0 to i64
%11 = sub i64 %9, %10
%12 = add i64 %11, 1
%13 = tail call i64 @calloc(i64 %12, i32 1)
%14 = inttoptr i64 %13 to i8*
%15 = icmp eq i64 %13, 0
br i1 %15, label %16, label %18
16: ; preds = %7
%17 = tail call i32 @perror(i32* null)
br label %21
18: ; preds = %7
%19 = tail call i32 @strncpy(i8* %14, i8* %0, i64 %11)
%20 = getelementptr inbounds i8, i8* %14, i64 %11
store i8 0, i8* %20
br label %21
21: ; preds = %18, %16
%22 = phi i8* [ %14, %18 ], [ null, %16 ]
ret i8* %22
}