#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*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int remove_lf(char *buffer) {
  int loopcnt;
  for (loopcnt = 0; loopcnt < 1024; loopcnt++) {
    if ('\n' == buffer[loopcnt]) {
      buffer[loopcnt] = '\0';
      return (0);
    }
  }
  fprintf(stderr, "Max line length is %d\n", 1024);
  return (-1);
}


x86 assembly (clang, -O0):
<remove_lf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x400,-0x14(%rbp)
jge    1174 <remove_lf+0x64>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
jne    1161 <remove_lf+0x51>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
jmp    1195 <remove_lf+0x85>
jmp    1166 <remove_lf+0x56>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1123 <remove_lf+0x13>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
mov    $0x400,%edx
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_lf>:
push   %rax
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0xa,(%rdi,%rax,1)
je     1178 <remove_lf+0x68>
cmpb   $0xa,0x1(%rdi,%rax,1)
je     1168 <remove_lf+0x58>
cmpb   $0xa,0x2(%rdi,%rax,1)
je     116e <remove_lf+0x5e>
cmpb   $0xa,0x3(%rdi,%rax,1)
je     1174 <remove_lf+0x64>
add    $0x4,%rax
cmp    $0x400,%rax
jne    1120 <remove_lf+0x10>
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
lea    0xea9(%rip),%rsi
mov    $0x400,%edx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
add    $0x1,%rax
jmp    1178 <remove_lf+0x68>
add    $0x2,%rax
jmp    1178 <remove_lf+0x68>
add    $0x3,%rax
mov    %eax,%eax
movb   $0x0,(%rdi,%rax,1)
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Max line length is %d\0A\00"
define i32 @remove_lf(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
br label %5
5: ; preds = %22, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 1024
br i1 %7, label %8, label %25
8: ; preds = %5
%9 = load i8*, i8** %3
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 10, %14
br i1 %15, label %16, label %21
16: ; preds = %8
%17 = load i8*, i8** %3
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
store i8 0, i8* %20
store i32 0, i32* %2
br label %28
21: ; preds = %8
br label %22
22: ; preds = %21
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %5
25: ; preds = %5
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 1024)
store i32 -1, i32* %2
br label %28
28: ; preds = %25, %16
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Max line length is %d\0A\00"
define i32 @remove_lf(i8* nocapture %0) {
br label %2
2: ; preds = %26, %1
%3 = phi i64 [ 0, %1 ], [ %27, %26 ]
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 10
br i1 %6, label %7, label %11
7: ; preds = %21, %16, %11, %2
%8 = phi i64 [ %3, %2 ], [ %12, %11 ], [ %17, %16 ], [ %22, %21 ]
%9 = and i64 %8, 4294967295
%10 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 0, i8* %10
br label %32
11: ; preds = %2
%12 = or i64 %3, 1
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 10
br i1 %15, label %7, label %16
16: ; preds = %11
%17 = or i64 %3, 2
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 10
br i1 %20, label %7, label %21
21: ; preds = %16
%22 = or i64 %3, 3
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 10
br i1 %25, label %7, label %26
26: ; preds = %21
%27 = add nuw nsw i64 %3, 4
%28 = icmp eq i64 %27, 1024
br i1 %28, label %29, label %2
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 1024)
br label %32
32: ; preds = %29, %7
%33 = phi i32 [ 0, %7 ], [ -1, %29 ]
ret i32 %33
}