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

/* Variables and functions */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ putchar(char);
int main() {
  FILE *my_tty;
  char ch;
  int xx;
  my_tty = fopen("/dev/ttyqf", "r+");
  while ((ch = fgetc(my_tty)) != EOF) {
    putchar(ch);
  }
  putchar('\n');
  fclose(my_tty);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2e6c(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1195 <main+0x55>
movsbl -0x11(%rbp),%edi
call   1030 <putchar@plt>
jmp    1166 <main+0x26>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
lea    0xeb9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e7f(%rip),%r14
cmp    (%r14),%al
je     1185 <main+0x45>
xchg   %ax,%ax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r14),%al
jne    1170 <main+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/ttyqf\00"
@.str.1 = [3 x i8] c"r+\00"
@EOF = global i8 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
br label %6
6: ; preds = %13, %0
%7 = load i32*, i32** %2
%8 = call signext i8 @fgetc(i32* %7)
store i8 %8, i8* %3
%9 = sext i8 %8 to i32
%10 = load i8, i8* @EOF
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %9, %11
br i1 %12, label %13, label %16
13: ; preds = %6
%14 = load i8, i8* %3
%15 = call i32 @putchar(i8 signext %14)
br label %6
16: ; preds = %6
%17 = call i32 @putchar(i8 signext 10)
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/ttyqf\00"
@.str.1 = [3 x i8] c"r+\00"
@EOF = global i8 0
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call signext i8 @fgetc(i32* %1)
%3 = load i8, i8* @EOF
%4 = icmp eq i8 %2, %3
br i1 %4, label %11, label %5
5: ; preds = %0, %5
%6 = phi i8 [ %8, %5 ], [ %2, %0 ]
%7 = tail call i32 @putchar(i8 signext %6)
%8 = tail call signext i8 @fgetc(i32* %1)
%9 = load i8, i8* @EOF
%10 = icmp eq i8 %8, %9
br i1 %10, label %11, label %5
11: ; preds = %5, %0
%12 = tail call i32 @putchar(i8 signext 10)
%13 = tail call i32 @fclose(i32* %1)
ret i32 0
}