#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);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
char *strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void printremark(char *str) {
  char *strtmp;
  int substrlen;
  char *substrend;
  char *strend;
  char *strbfr;
  strbfr = (char *)malloc(strlen((char *)str) + 1);
  if (!strbfr) {
    printf("No memory.\n");
    exit(-1);
  }
  strtmp = str;
  strend = &str[strlen(str)];
  while (strtmp < strend) {
    substrend = strchr(strtmp, '\n');
    substrlen = (substrend ? (substrend - strtmp) : strlen(strtmp));
    strncpy(strbfr, strtmp, substrlen);
    strbfr[substrlen] = (char)0;
    printf("\\  %s\n", strbfr);
    strtmp = &strtmp[substrlen + (substrend ? 1 : 0)];
  }
  free(strbfr);
}


x86 assembly (clang, -O0):
<printremark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11b6 <printremark+0x46>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    128c <printremark+0x11c>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     121e <printremark+0xae>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x40(%rbp)
jmp    122d <printremark+0xbd>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cltq
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %eax,-0x14(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rsi
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%rdi
xor    %edx,%edx
mov    $0x1,%esi
cmp    $0x0,%rdi
cmovne %esi,%edx
add    %edx,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    11df <printremark+0x6f>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printremark>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1241 <printremark+0xc1>
mov    %rax,%r14
mov    %r13,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    122b <printremark+0xab>
movslq %eax,%rbp
add    %r13,%rbp
lea    0xe40(%rip),%r15
jmp    120e <printremark+0x8e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1040 <strncpy@plt>
movslq %ebx,%rbx
movb   $0x0,(%r14,%rbx,1)
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
cmp    $0x1,%r12
sbb    $0xffffffff,%ebx
movslq %ebx,%rax
add    %rax,%r13
cmp    %rbp,%r13
jae    122b <printremark+0xab>
mov    %r13,%rdi
mov    $0xa,%esi
call   1070 <strchr@plt>
mov    %rax,%r12
test   %rax,%rax
je     11d0 <printremark+0x50>
mov    %r12,%rbx
sub    %r13,%rbx
jmp    11da <printremark+0x5a>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
lea    0xdbf(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"No memory.\0A\00"
@.str.1 = [7 x i8] c"\\ %s\0A\00"
define void @printremark(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, 1
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %1
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %1
%19 = load i8*, i8** %2
store i8* %19, i8** %3
%20 = load i8*, i8** %2
%21 = load i8*, i8** %2
%22 = call i32 @strlen(i8* %21)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8* %24, i8** %6
br label %25
25: ; preds = %44, %18
%26 = load i8*, i8** %3
%27 = load i8*, i8** %6
%28 = icmp ult i8* %26, %27
br i1 %28, label %29, label %66
29: ; preds = %25
%30 = load i8*, i8** %3
%31 = call i8* @strchr(i8* %30, i8 signext 10)
store i8* %31, i8** %5
%32 = load i8*, i8** %5
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %40
34: ; preds = %29
%35 = load i8*, i8** %5
%36 = load i8*, i8** %3
%37 = ptrtoint i8* %35 to i64
%38 = ptrtoint i8* %36 to i64
%39 = sub i64 %37, %38
br label %44
40: ; preds = %29
%41 = load i8*, i8** %3
%42 = call i32 @strlen(i8* %41)
%43 = sext i32 %42 to i64
br label %44
44: ; preds = %40, %34
%45 = phi i64 [ %39, %34 ], [ %43, %40 ]
%46 = trunc i64 %45 to i32
store i32 %46, i32* %4
%47 = load i8*, i8** %7
%48 = load i8*, i8** %3
%49 = load i32, i32* %4
%50 = call i32 @strncpy(i8* %47, i8* %48, i32 %49)
%51 = load i8*, i8** %7
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 0, i8* %54
%55 = load i8*, i8** %7
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %55)
%57 = load i8*, i8** %3
%58 = load i32, i32* %4
%59 = load i8*, i8** %5
%60 = icmp ne i8* %59, null
%61 = zext i1 %60 to i64
%62 = select i1 %60, i32 1, i32 0
%63 = add nsw i32 %58, %62
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %57, i64 %64
store i8* %65, i8** %3
br label %25
66: ; preds = %25
%67 = load i8*, i8** %7
%68 = call i32 @free(i8* %67)
ret void
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"\\ %s\0A\00"
@str = [11 x i8] c"No memory.\00"
define void @printremark(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %1
%11 = tail call i32 @strlen(i8* %0)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = icmp sgt i32 %11, 0
br i1 %14, label %15, label %41
15: ; preds = %10, %26
%16 = phi i8* [ %39, %26 ], [ %0, %10 ]
%17 = tail call i8* @strchr(i8* dereferenceable(1) %16, i8 signext 10)
%18 = icmp eq i8* %17, null
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = ptrtoint i8* %17 to i64
%21 = ptrtoint i8* %16 to i64
%22 = sub i64 %20, %21
br label %26
23: ; preds = %15
%24 = tail call i32 @strlen(i8* %16)
%25 = zext i32 %24 to i64
br label %26
26: ; preds = %23, %19
%27 = phi i64 [ %22, %19 ], [ %25, %23 ]
%28 = trunc i64 %27 to i32
%29 = tail call i32 @strncpy(i8* %5, i8* %16, i32 %28)
%30 = shl i64 %27, 32
%31 = ashr exact i64 %30, 32
%32 = getelementptr inbounds i8, i8* %5, i64 %31
store i8 0, i8* %32
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%34 = xor i1 %18, true
%35 = zext i1 %34 to i64
%36 = add i64 %27, %35
%37 = shl i64 %36, 32
%38 = ashr exact i64 %37, 32
%39 = getelementptr inbounds i8, i8* %16, i64 %38
%40 = icmp ult i8* %39, %13
br i1 %40, label %15, label %41
41: ; preds = %26, %10
%42 = tail call i32 @free(i8* %5)
ret void
}