#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);
char *index(char *, char);
char *malloc(int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *DoComment(char *line) {
  char *tag;
  char *eol;
  char *ret;
  int len;
  if ((tag = index(line, '$')) == NULL)
    return NULL;
  if ((eol = index(tag + 1, '$')) == NULL)
    return NULL;
  len = eol - tag;
  if ((ret = malloc(len)) == NULL)
    exit(1);
  (void)strncpy(ret, tag + 1, len - 1);
  ret[len - 2] = 0;
  return ret;
}


x86 assembly (clang, -O0):
<DoComment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x24,%esi
call   1040 <index@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1175 <DoComment+0x35>
movq   $0x0,-0x8(%rbp)
jmp    1200 <DoComment+0xc0>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    $0x24,%esi
call   1040 <index@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a2 <DoComment+0x62>
movq   $0x0,-0x8(%rbp)
jmp    1200 <DoComment+0xc0>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11d0 <DoComment+0x90>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
mov    -0x2c(%rbp),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoComment>:
push   %r15
push   %r14
push   %rbx
mov    $0x24,%esi
call   1040 <index@plt>
test   %rax,%rax
je     119d <DoComment+0x5d>
mov    %rax,%r15
lea    0x1(%rax),%r14
mov    %r14,%rdi
mov    $0x24,%esi
call   1040 <index@plt>
test   %rax,%rax
je     119d <DoComment+0x5d>
mov    %rax,%rbx
sub    %r15,%rbx
mov    %ebx,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11a9 <DoComment+0x69>
mov    %rax,%r15
lea    -0x1(%rbx),%edx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strncpy@plt>
add    $0xfffffffe,%ebx
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
jmp    11a0 <DoComment+0x60>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0x1,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
define i8* @DoComment(i8* %0) {
%2 = tail call i8* @index(i8* %0, i8 signext 36)
%3 = icmp eq i8* %2, null
br i1 %3, label %24, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %2, i64 1
%6 = tail call i8* @index(i8* %5, i8 signext 36)
%7 = icmp eq i8* %6, null
br i1 %7, label %24, label %8
8: ; preds = %4
%9 = ptrtoint i8* %6 to i64
%10 = ptrtoint i8* %2 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = tail call i8* @malloc(i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %8
%18 = add nsw i32 %12, -1
%19 = tail call i32 @strncpy(i8* %13, i8* %5, i32 %18)
%20 = shl i64 %11, 32
%21 = add i64 %20, -8589934592
%22 = ashr exact i64 %21, 32
%23 = getelementptr inbounds i8, i8* %13, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %4, %1, %17
%25 = phi i8* [ %13, %17 ], [ null, %1 ], [ null, %4 ]
ret i8* %25
}