#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 */
typedef scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
char *realloc(char *, scalar_t__);
scalar_t__ sanitize_fast(char *, char *, scalar_t__, int, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char const *argv[]) {
  char *src = NULL;
  size_t srccap = 0;
  ssize_t srclen = 0;
  char *attrs = malloc(1024);
  size_t attrlen = 1024;
  while ((srclen = getline(&src, &srccap, stdin)) > 0) {
    char dest[1024];
    if (srclen > 0)
      src[--srclen] = 0;
    if (srclen > attrlen) {
      attrs = realloc(attrs, srclen);
      attrlen = srclen;
    }
    if (sanitize_fast(src, dest, srclen - 1, 1024, attrs) == 0)
      printf("%s\n", dest);
    else
      fprintf(stderr, "Error: output bigger than DESTLEN");
  }
  free(src);
  free(attrs);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
movq   $0x400,-0x38(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <getline@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jle    1282 <main+0x112>
cmpq   $0x0,-0x28(%rbp)
jle    11fe <main+0x8e>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x28(%rbp)
movb   $0x0,-0x1(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
cmp    -0x38(%rbp),%rax
jbe    1225 <main+0xb5>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <realloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x440(%rbp),%rsi
mov    -0x28(%rbp),%rdx
sub    $0x1,%rdx
mov    -0x30(%rbp),%r8
mov    $0x400,%ecx
call   1050 <sanitize_fast@plt>
cmp    $0x0,%rax
jne    1268 <main+0xf8>
lea    -0x440(%rbp),%rsi
lea    0xda2(%rip),%rdi
call   1040 <printf@plt>
jmp    127d <main+0x10d>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xd8c(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11b7 <main+0x47>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1090 <getline@plt>
test   %rax,%rax
jle    1266 <main+0xf6>
mov    %rax,%r15
mov    $0x400,%r12d
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r13
jmp    1211 <main+0xa1>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    %r13,%rsi
call   1090 <getline@plt>
mov    %rax,%r15
test   %rax,%rax
jle    1266 <main+0xf6>
mov    (%rsp),%rax
lea    -0x1(%r15),%rbp
movb   $0x0,-0x1(%rax,%r15,1)
cmp    %r12,%rbp
jbe    1235 <main+0xc5>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <realloc@plt>
mov    %rax,%rbx
mov    %rbp,%r12
mov    (%rsp),%rdi
add    $0xfffffffffffffffe,%r15
mov    %r14,%rsi
mov    %r15,%rdx
mov    $0x400,%ecx
mov    %rbx,%r8
call   1050 <sanitize_fast@plt>
test   %rax,%rax
jne    11e0 <main+0x70>
lea    0xda4(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
jmp    11f5 <main+0x85>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Error: output bigger than DESTLEN\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i64 0, i64* %7
store i64 0, i64* %8
%12 = call i8* @malloc(i32 1024)
store i8* %12, i8** %9
store i64 1024, i64* %10
br label %13
13: ; preds = %48, %2
%14 = load i32, i32* @stdin
%15 = call i64 @getline(i8** %6, i64* %7, i32 %14)
store i64 %15, i64* %8
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %49
17: ; preds = %13
%18 = load i64, i64* %8
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i8*, i8** %6
%22 = load i64, i64* %8
%23 = add nsw i64 %22, -1
store i64 %23, i64* %8
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %20, %17
%26 = load i64, i64* %8
%27 = load i64, i64* %10
%28 = icmp ugt i64 %26, %27
br i1 %28, label %29, label %34
29: ; preds = %25
%30 = load i8*, i8** %9
%31 = load i64, i64* %8
%32 = call i8* @realloc(i8* %30, i64 %31)
store i8* %32, i8** %9
%33 = load i64, i64* %8
store i64 %33, i64* %10
br label %34
34: ; preds = %29, %25
%35 = load i8*, i8** %6
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%37 = load i64, i64* %8
%38 = sub nsw i64 %37, 1
%39 = load i8*, i8** %9
%40 = call i64 @sanitize_fast(i8* %35, i8* %36, i64 %38, i32 1024, i8* %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %34
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %43)
br label %48
45: ; preds = %34
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %48
48: ; preds = %45, %42
br label %13
49: ; preds = %13
%50 = load i8*, i8** %6
%51 = call i32 @free(i8* %50)
%52 = load i8*, i8** %9
%53 = call i32 @free(i8* %52)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Error: output bigger than DESTLEN\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [1024 x i8]
%6 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%7 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%8 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%9 = load i32, i32* @stdin
%10 = call i64 @getline(i8** %3, i64* %4, i32 %9)
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %40
12: ; preds = %2
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
br label %14
14: ; preds = %12, %36
%15 = phi i64 [ %10, %12 ], [ %38, %36 ]
%16 = phi i64 [ 1024, %12 ], [ %26, %36 ]
%17 = phi i8* [ %8, %12 ], [ %25, %36 ]
%18 = load i8*, i8** %3
%19 = add nsw i64 %15, -1
%20 = getelementptr inbounds i8, i8* %18, i64 %19
store i8 0, i8* %20
%21 = icmp ugt i64 %19, %16
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i8* @realloc(i8* %17, i64 %19)
br label %24
24: ; preds = %22, %14
%25 = phi i8* [ %23, %22 ], [ %17, %14 ]
%26 = phi i64 [ %19, %22 ], [ %16, %14 ]
%27 = load i8*, i8** %3
%28 = add nsw i64 %15, -2
%29 = call i64 @sanitize_fast(i8* %27, i8* %13, i64 %28, i32 1024, i8* %25)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %36
33: ; preds = %24
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %33, %31
%37 = load i32, i32* @stdin
%38 = call i64 @getline(i8** %3, i64* %4, i32 %37)
%39 = icmp sgt i64 %38, 0
br i1 %39, label %14, label %40
40: ; preds = %36, %2
%41 = phi i8* [ %8, %2 ], [ %25, %36 ]
%42 = load i8*, i8** %3
%43 = call i32 @free(i8* %42)
%44 = call i32 @free(i8* %41)
ret i32 0
}