#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 /*<<< orphan*/ buffer;

/* Variables and functions */
scalar_t__ isprint(char);
int /*<<< orphan*/ lprintf(int, char *);
int /*<<< orphan*/ lputc(int, char);
int mdm_read_byte(int, char *);
char *mdm_get_line(int fd) {
  static char buffer[200];
  int bufferp;
  char c;
  bufferp = 0;
  lprintf(6, "got:");
  do {
    if (mdm_read_byte(fd, &c) != 1) {
      lprintf(1, "mdm_get_line: cannot read byte, return");
      return NULL;
    }
    lputc(6, c);
    if (isprint(c) && bufferp < sizeof(buffer)) {
      buffer[bufferp++] = c;
    }
  } while (bufferp == 0 || (c != 0x0a && c != 0x0d));
  buffer[bufferp] = 0;
  return buffer;
}


x86 assembly (clang, -O0):
<mdm_get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x6,%edi
lea    0xea2(%rip),%rsi
call   1060 <lprintf@plt>
mov    -0xc(%rbp),%edi
lea    -0x11(%rbp),%rsi
call   1040 <mdm_read_byte@plt>
cmp    $0x1,%eax
je     1196 <mdm_get_line+0x56>
mov    $0x1,%edi
lea    0xe81(%rip),%rsi
call   1060 <lprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1240 <mdm_get_line+0x100>
mov    $0x6,%edi
movsbl -0x11(%rbp),%esi
call   1030 <lputc@plt>
movsbl -0x11(%rbp),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     11e2 <mdm_get_line+0xa2>
movslq -0x10(%rbp),%rax
cmp    $0xc8,%rax
jae    11e2 <mdm_get_line+0xa2>
mov    -0x11(%rbp),%dl
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
movslq %eax,%rcx
lea    0x2e71(%rip),%rax
mov    %dl,(%rax,%rcx,1)
jmp    11e7 <mdm_get_line+0xa7>
mov    $0x1,%al
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x12(%rbp)
je     121b <mdm_get_line+0xdb>
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x13(%rbp)
je     1215 <mdm_get_line+0xd5>
movsbl -0x11(%rbp),%eax
cmp    $0xd,%eax
setne  %al
mov    %al,-0x13(%rbp)
mov    -0x13(%rbp),%al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    1163 <mdm_get_line+0x23>
movslq -0x10(%rbp),%rcx
lea    0x2e1f(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e14(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mdm_get_line>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xeb0(%rip),%rsi
mov    $0x6,%edi
call   1060 <lprintf@plt>
lea    0x7(%rsp),%rsi
mov    %ebx,%edi
call   1040 <mdm_read_byte@plt>
cmp    $0x1,%eax
jne    11fb <mdm_get_line+0xbb>
xor    %ebp,%ebp
lea    0x2ed8(%rip),%r14
lea    0x7(%rsp),%r15
jmp    119f <mdm_get_line+0x5f>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r15,%rsi
call   1040 <mdm_read_byte@plt>
cmp    $0x1,%eax
jne    11fb <mdm_get_line+0xbb>
movsbl 0x7(%rsp),%esi
mov    $0x6,%edi
call   1030 <lputc@plt>
movsbl 0x7(%rsp),%edi
call   1050 <isprint@plt>
test   %rax,%rax
je     11e0 <mdm_get_line+0xa0>
cmp    $0xc7,%ebp
ja     11e0 <mdm_get_line+0xa0>
mov    %ebp,%ecx
movzbl 0x7(%rsp),%eax
add    $0x1,%ebp
mov    %al,(%rcx,%r14,1)
cmp    $0xd,%al
jne    11ed <mdm_get_line+0xad>
jmp    11f1 <mdm_get_line+0xb1>
nopl   0x0(%rax)
test   %ebp,%ebp
je     117f <mdm_get_line+0x3f>
movzbl 0x7(%rsp),%eax
cmp    $0xd,%al
je     11f1 <mdm_get_line+0xb1>
cmp    $0xa,%al
jne    1190 <mdm_get_line+0x50>
movslq %ebp,%rax
movb   $0x0,(%rax,%r14,1)
jmp    120f <mdm_get_line+0xcf>
lea    0xe03(%rip),%rsi
mov    $0x1,%edi
call   1060 <lprintf@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@mdm_get_line.buffer = internal global [200 x i8] zeroinitializer
@.str = [5 x i8] c"got:\00"
@.str.1 = [39 x i8] c"mdm_get_line: cannot read byte, return\00"
define i8* @mdm_get_line(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 %0, i32* %3
store i32 0, i32* %4
%6 = call i32 @lprintf(i32 6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %43, %1
%8 = load i32, i32* %3
%9 = call i32 @mdm_read_byte(i32 %8, i8* %5)
%10 = icmp ne i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @lprintf(i32 1, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %49
13: ; preds = %7
%14 = load i8, i8* %5
%15 = call i32 @lputc(i32 6, i8 signext %14)
%16 = load i8, i8* %5
%17 = call i64 @isprint(i8 signext %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %29
19: ; preds = %13
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = icmp ult i64 %21, 200
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i8, i8* %5
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds [200 x i8], [200 x i8]* @mdm_get_line.buffer, i64 0, i64 %27
store i8 %24, i8* %28
br label %29
29: ; preds = %23, %19, %13
br label %30
30: ; preds = %29
%31 = load i32, i32* %4
%32 = icmp eq i32 %31, 0
br i1 %32, label %43, label %33
33: ; preds = %30
%34 = load i8, i8* %5
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 10
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i8, i8* %5
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 13
br label %41
41: ; preds = %37, %33
%42 = phi i1 [ false, %33 ], [ %40, %37 ]
br label %43
43: ; preds = %41, %30
%44 = phi i1 [ true, %30 ], [ %42, %41 ]
br i1 %44, label %7, label %45
45: ; preds = %43
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [200 x i8], [200 x i8]* @mdm_get_line.buffer, i64 0, i64 %47
store i8 0, i8* %48
store i8* getelementptr inbounds ([200 x i8], [200 x i8]* @mdm_get_line.buffer, i64 0, i64 0), i8** %2
br label %49
49: ; preds = %45, %11
%50 = load i8*, i8** %2
ret i8* %50
}

LLVM IR (-O2):
@mdm_get_line.buffer = internal global [200 x i8] zeroinitializer
@.str = [5 x i8] c"got:\00"
@.str.1 = [39 x i8] c"mdm_get_line: cannot read byte, return\00"
define i8* @mdm_get_line(i32 %0) {
%2 = alloca i8
%3 = tail call i32 @lprintf(i32 6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @mdm_read_byte(i32 %0, i8* %2)
%5 = icmp eq i32 %4, 1
br i1 %5, label %8, label %6
6: ; preds = %24, %1
%7 = call i32 @lprintf(i32 1, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %36
8: ; preds = %1, %24
%9 = phi i32 [ %25, %24 ], [ 0, %1 ]
%10 = load i8, i8* %2
%11 = call i32 @lputc(i32 6, i8 signext %10)
%12 = load i8, i8* %2
%13 = call i64 @isprint(i8 signext %12)
%14 = icmp ne i64 %13, 0
%15 = icmp ult i32 %9, 200
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %17, label %22
17: ; preds = %8
%18 = zext i32 %9 to i64
%19 = load i8, i8* %2
%20 = add nuw nsw i32 %9, 1
%21 = getelementptr inbounds [200 x i8], [200 x i8]* @mdm_get_line.buffer, i64 0, i64 %18
store i8 %19, i8* %21
br label %30
22: ; preds = %8
%23 = icmp eq i32 %9, 0
br i1 %23, label %24, label %28
24: ; preds = %22, %30
%25 = phi i32 [ 0, %22 ], [ %32, %30 ]
%26 = call i32 @mdm_read_byte(i32 %0, i8* %2)
%27 = icmp eq i32 %26, 1
br i1 %27, label %8, label %6
28: ; preds = %22
%29 = load i8, i8* %2
br label %30
30: ; preds = %28, %17
%31 = phi i8 [ %29, %28 ], [ %19, %17 ]
%32 = phi i32 [ %9, %28 ], [ %20, %17 ]
switch i8 %31, label %24 [
i8 13, label %33
i8 10, label %33
]
33: ; preds = %30, %30
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds [200 x i8], [200 x i8]* @mdm_get_line.buffer, i64 0, i64 %34
store i8 0, i8* %35
br label %36
36: ; preds = %33, %6
%37 = phi i8* [ null, %6 ], [ getelementptr inbounds ([200 x i8], [200 x i8]* @mdm_get_line.buffer, i64 0, i64 0), %33 ]
ret i8* %37
}