#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 EOF;
int getchar();
int /*<<< orphan*/ printf(char *);
int getline_my(char s[], int maxsize) {
  int c = 0;
  int i = 0;
  int lim = maxsize;
  printf("in getline_my.\n");
  while ((--lim > 0) && ((c = getchar()) != EOF) && c != '\n')
    s[i++] = c;
  if (c == '\n') {
    s[i++] = '\n';
  };
  s[i] = '\0';
  return i;
}


x86 assembly (clang, -O0):
<getline_my>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    0xeb6(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
jle    1190 <getline_my+0x70>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
xor    %eax,%eax
mov    0x2e6d(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x19(%rbp)
je     1190 <getline_my+0x70>
cmpl   $0xa,-0x10(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11a0 <getline_my+0x80>
jmp    11bf <getline_my+0x9f>
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    114f <getline_my+0x2f>
cmpl   $0xa,-0x10(%rbp)
jne    11df <getline_my+0xbf>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
movb   $0xa,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getline_my>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
lea    0xecb(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
cmp    $0x2,%r15d
jl     1183 <getline_my+0x63>
add    $0xffffffff,%r15d
mov    0x2e9b(%rip),%r12
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     1174 <getline_my+0x54>
cmp    (%r12),%eax
je     1174 <getline_my+0x54>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <getline_my+0x30>
mov    %r15d,%ebx
jmp    1183 <getline_my+0x63>
cmp    $0xa,%eax
jne    1183 <getline_my+0x63>
movb   $0xa,(%r14,%rbx,1)
lea    0x1(%rbx),%eax
mov    %eax,%ebx
movslq %ebx,%rax
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"in getline_my.\0A\00"
@EOF = global i32 0
define i32 @getline_my(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%8 = load i32, i32* %4
store i32 %8, i32* %7
%9 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %23, %2
%11 = load i32, i32* %7
%12 = add nsw i32 %11, -1
store i32 %12, i32* %7
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = call i32 (...) @getchar()
store i32 %15, i32* %5
%16 = load i32, i32* @EOF
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %5
%20 = icmp ne i32 %19, 10
br label %21
21: ; preds = %18, %14, %10
%22 = phi i1 [ false, %14 ], [ false, %10 ], [ %20, %18 ]
br i1 %22, label %23, label %31
23: ; preds = %21
%24 = load i32, i32* %5
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %3
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
store i8 %25, i8* %30
br label %10
31: ; preds = %21
%32 = load i32, i32* %5
%33 = icmp eq i32 %32, 10
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = load i8*, i8** %3
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
store i8 10, i8* %39
br label %40
40: ; preds = %34, %31
%41 = load i8*, i8** %3
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 0, i8* %44
%45 = load i32, i32* %6
ret i32 %45
}

LLVM IR (-O2):
@EOF = global i32 0
@str = [15 x i8] c"in getline_my.\00"
define i32 @getline_my(i8* nocapture writeonly %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%4 = icmp sgt i32 %1, 1
br i1 %4, label %5, label %27
5: ; preds = %2
%6 = add nsw i32 %1, -1
%7 = zext i32 %6 to i64
br label %8
8: ; preds = %5, %15
%9 = phi i64 [ 0, %5 ], [ %17, %15 ]
%10 = tail call i32 (...) @getchar()
%11 = load i32, i32* @EOF
%12 = icmp ne i32 %10, %11
%13 = icmp ne i32 %10, 10
%14 = and i1 %13, %12
br i1 %14, label %15, label %20
15: ; preds = %8
%16 = trunc i32 %10 to i8
%17 = add nuw nsw i64 %9, 1
%18 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 %16, i8* %18
%19 = icmp eq i64 %17, %7
br i1 %19, label %27, label %8
20: ; preds = %8
%21 = trunc i64 %9 to i32
%22 = icmp eq i32 %10, 10
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = add nuw nsw i32 %21, 1
%25 = and i64 %9, 4294967295
%26 = getelementptr inbounds i8, i8* %0, i64 %25
store i8 10, i8* %26
br label %27
27: ; preds = %15, %2, %23, %20
%28 = phi i32 [ %24, %23 ], [ %21, %20 ], [ 0, %2 ], [ %6, %15 ]
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %0, i64 %29
store i8 0, i8* %30
ret i32 %28
}