#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 int ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ isprint(char);
ssize_t my_getline(char **lineptr, size_t *n, FILE *stream) {
  ssize_t ris = getline(lineptr, n, stream);
  while (ris > 0 && !isprint((*lineptr)[ris - 1])) {
    (*lineptr)[ris - 1] = '\0';
    --ris;
  }
  return ris;
}


x86 assembly (clang, -O0):
<my_getline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <getline@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
jle    117b <my_getline+0x5b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isprint@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    118b <my_getline+0x6b>
jmp    11ad <my_getline+0x8d>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1148 <my_getline+0x28>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_getline>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <getline@plt>
mov    %eax,%r15d
test   %eax,%eax
jle    1170 <my_getline+0x50>
mov    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    (%r14),%rax
lea    -0x1(%r15),%rbx
mov    %ebx,%r12d
movsbl (%rax,%r12,1),%edi
call   1030 <isprint@plt>
test   %eax,%eax
jne    1170 <my_getline+0x50>
mov    (%r14),%rax
movb   $0x0,(%rax,%r12,1)
lea    0x1(%rbx),%rax
mov    %rbx,%r15
cmp    $0x1,%rax
ja     1140 <my_getline+0x20>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @my_getline(i8** %0, i64* %1, i32* %2) {
%4 = alloca i8**
%5 = alloca i64*
%6 = alloca i32*
%7 = alloca i32
store i8** %0, i8*** %4
store i64* %1, i64** %5
store i32* %2, i32** %6
%8 = load i8**, i8*** %4
%9 = load i64*, i64** %5
%10 = load i32*, i32** %6
%11 = call i32 @getline(i8** %8, i64* %9, i32* %10)
store i32 %11, i32* %7
br label %12
12: ; preds = %28, %3
%13 = load i32, i32* %7
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = load i8**, i8*** %4
%17 = load i8*, i8** %16
%18 = load i32, i32* %7
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = load i8, i8* %21
%23 = call i32 @isprint(i8 signext %22)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br label %26
26: ; preds = %15, %12
%27 = phi i1 [ false, %12 ], [ %25, %15 ]
br i1 %27, label %28, label %37
28: ; preds = %26
%29 = load i8**, i8*** %4
%30 = load i8*, i8** %29
%31 = load i32, i32* %7
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 0, i8* %34
%35 = load i32, i32* %7
%36 = add nsw i32 %35, -1
store i32 %36, i32* %7
br label %12
37: ; preds = %26
%38 = load i32, i32* %7
ret i32 %38
}

LLVM IR (-O2):
define i32 @my_getline(i8** %0, i64* %1, i32* %2) {
%4 = tail call i32 @getline(i8** %0, i64* %1, i32* %2)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %23
6: ; preds = %3
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %17
%9 = phi i64 [ %7, %6 ], [ %11, %17 ]
%10 = load i8*, i8** %0
%11 = add nsw i64 %9, -1
%12 = and i64 %11, 4294967295
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = tail call i32 @isprint(i8 signext %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %8
%18 = load i8*, i8** %0
%19 = getelementptr inbounds i8, i8* %18, i64 %12
store i8 0, i8* %19
%20 = icmp ugt i64 %9, 1
br i1 %20, label %8, label %23
21: ; preds = %8
%22 = trunc i64 %9 to i32
br label %23
23: ; preds = %17, %21, %3
%24 = phi i32 [ %4, %3 ], [ %22, %21 ], [ 0, %17 ]
ret i32 %24
}