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

/* Variables and functions */
int read(int, char *, int);
int skip_newline(int fd) {
  char newline[1];
  if (read(fd, newline, sizeof(newline)) != sizeof(newline)) {
    return -1;
  }
  if (newline[0] == '\r') {
    if (read(fd, newline, sizeof(newline)) != sizeof(newline)) {
      return -1;
    }
  }
  if (newline[0] != '\n') {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<skip_newline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cltq
cmp    $0x1,%rax
je     1144 <skip_newline+0x34>
movl   $0xffffffff,-0x4(%rbp)
jmp    119f <skip_newline+0x8f>
movsbl -0x9(%rbp),%eax
cmp    $0xd,%eax
jne    117f <skip_newline+0x6f>
mov    -0x8(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cltq
cmp    $0x1,%rax
je     117a <skip_newline+0x6a>
movl   $0xffffffff,-0x4(%rbp)
jmp    119f <skip_newline+0x8f>
jmp    117f <skip_newline+0x6f>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
je     1198 <skip_newline+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    119f <skip_newline+0x8f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skip_newline>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    $0xffffffff,%ebx
cmp    $0x1,%eax
jne    1159 <skip_newline+0x49>
mov    0x7(%rsp),%al
cmp    $0xd,%al
jne    1150 <skip_newline+0x40>
lea    0x7(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
jne    1159 <skip_newline+0x49>
mov    0x7(%rsp),%al
xor    %ebx,%ebx
cmp    $0xa,%al
setne  %bl
neg    %ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @skip_newline(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1 x i8]
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%7 = call i32 @read(i32 %5, i8* %6, i32 1)
%8 = sext i32 %7 to i64
%9 = icmp ne i64 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %31
11: ; preds = %1
%12 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 13
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = load i32, i32* %3
%18 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%19 = call i32 @read(i32 %17, i8* %18, i32 1)
%20 = sext i32 %19 to i64
%21 = icmp ne i64 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %16
store i32 -1, i32* %2
br label %31
23: ; preds = %16
br label %24
24: ; preds = %23, %11
%25 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 10
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 -1, i32* %2
br label %31
30: ; preds = %24
store i32 0, i32* %2
br label %31
31: ; preds = %30, %29, %22, %10
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
define i32 @skip_newline(i32 %0) {
%2 = alloca [1 x i8]
%3 = getelementptr inbounds [1 x i8], [1 x i8]* %2, i64 0, i64 0
%4 = call i32 @read(i32 %0, i8* %3, i32 1)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %18
6: ; preds = %1
%7 = load i8, i8* %3
%8 = icmp eq i8 %7, 13
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = call i32 @read(i32 %0, i8* %3, i32 1)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = load i8, i8* %3
br label %14
14: ; preds = %12, %6
%15 = phi i8 [ %13, %12 ], [ %7, %6 ]
%16 = icmp ne i8 %15, 10
%17 = sext i1 %16 to i32
br label %18
18: ; preds = %14, %9, %1
%19 = phi i32 [ -1, %1 ], [ -1, %9 ], [ %17, %14 ]
ret i32 %19
}