#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int rtems_shell_cat_file(FILE *out, const char *name) {
  FILE *fd;
  int c;
  if (out) {
    fd = fopen(name, "r");
    if (!fd) {
      return -1;
    }
    while ((c = fgetc(fd)) != EOF)
      fputc(c, out);
    fclose(fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<rtems_shell_cat_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c0 <rtems_shell_cat_file+0x80>
mov    -0x18(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1186 <rtems_shell_cat_file+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <rtems_shell_cat_file+0x87>
jmp    118b <rtems_shell_cat_file+0x4b>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e4a(%rip),%rcx
cmp    (%rcx),%eax
je     11b7 <rtems_shell_cat_file+0x77>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <fputc@plt>
jmp    118b <rtems_shell_cat_file+0x4b>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtems_shell_cat_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %rdi,%rdi
je     11a7 <rtems_shell_cat_file+0x67>
mov    %rdi,%rbx
lea    0xea7(%rip),%rax
mov    %rsi,%rdi
mov    %rax,%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a1 <rtems_shell_cat_file+0x61>
mov    %rax,%rbp
mov    %rax,%rdi
call   1040 <fgetc@plt>
mov    0x2e6d(%rip),%r15
cmp    (%r15),%eax
je     1197 <rtems_shell_cat_file+0x57>
mov    %eax,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    %rbp,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%eax
jne    1180 <rtems_shell_cat_file+0x40>
mov    %rbp,%rdi
call   1030 <fclose@plt>
jmp    11a7 <rtems_shell_cat_file+0x67>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @rtems_shell_cat_file(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %29
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp ne i32* %13, null
br i1 %14, label %16, label %15
15: ; preds = %10
store i32 -1, i32* %3
br label %30
16: ; preds = %10
br label %17
17: ; preds = %22, %16
%18 = load i32*, i32** %6
%19 = call i32 @fgetc(i32* %18)
store i32 %19, i32* %7
%20 = load i32, i32* @EOF
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* %7
%24 = load i32*, i32** %4
%25 = call i32 @fputc(i32 %23, i32* %24)
br label %17
26: ; preds = %17
%27 = load i32*, i32** %6
%28 = call i32 @fclose(i32* %27)
br label %29
29: ; preds = %26, %2
store i32 0, i32* %3
br label %30
30: ; preds = %29, %15
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @rtems_shell_cat_file(i32* %0, i8* nocapture %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %19, label %4
4: ; preds = %2
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %19, label %7
7: ; preds = %4
%8 = tail call i32 @fgetc(i32* %5)
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %17, label %11
11: ; preds = %7, %11
%12 = phi i32 [ %14, %11 ], [ %8, %7 ]
%13 = tail call i32 @fputc(i32 %12, i32* %0)
%14 = tail call i32 @fgetc(i32* %5)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %11
17: ; preds = %11, %7
%18 = tail call i32 @fclose(i32* %5)
br label %19
19: ; preds = %2, %17, %4
%20 = phi i32 [ -1, %4 ], [ 0, %17 ], [ 0, %2 ]
ret i32 %20
}