#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 */
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  FILE *fd = fopen("/dev/ttyACM0", "r");
  if (fd) {
    while (1)
      fprintf(stdout, "%c", fgetc(fd));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1198 <main+0x68>
jmp    116d <main+0x3d>
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fgetc@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%edx
lea    0xe81(%rip),%rsi
call   1040 <fprintf@plt>
jmp    116d <main+0x3d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xec2(%rip),%rdi
lea    0xec8(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1179 <main+0x49>
mov    %rax,%rbx
mov    0x2e87(%rip),%r15
lea    0xeaf(%rip),%r14
mov    (%r15),%ebp
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <fprintf@plt>
jmp    1160 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyACM0\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32 0
@.str.2 = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %9, label %5
5: ; preds = %2, %5
%6 = load i32, i32* @stdout
%7 = tail call i32 @fgetc(i32* %3)
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %7)
br label %5
9: ; preds = %2
ret i32 0
}