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

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getc(int);
int /*<<< orphan*/ gets(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(int);
main() {
  int c, i;
  char buf[50];
  do {
    printf("File: ");
    gets(buf);
    i = open(buf, 0);
  } while (i <= 0);
  while ((c = getc(i)) > 0)
    putchar(c);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
call   1050 <gets@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    116f <main+0xf>
jmp    11a1 <main+0x41>
mov    -0xc(%rbp),%edi
call   1080 <getc@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11c2 <main+0x62>
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
jmp    11a1 <main+0x41>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xe90(%rip),%r14
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1050 <gets@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <open@plt>
test   %eax,%eax
jle    1180 <main+0x20>
mov    %eax,%ebx
mov    %ebx,%edi
call   1080 <getc@plt>
test   %eax,%eax
jle    11b4 <main+0x54>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    11a0 <main+0x40>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"File: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [50 x i8]
store i32 0, i32* %1
br label %5
5: ; preds = %11, %0
%6 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%8 = call i32 @gets(i8* %7)
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%10 = call i32 @open(i8* %9, i32 0)
store i32 %10, i32* %3
br label %11
11: ; preds = %5
%12 = load i32, i32* %3
%13 = icmp sle i32 %12, 0
br i1 %13, label %5, label %14
14: ; preds = %11
br label %15
15: ; preds = %19, %14
%16 = load i32, i32* %3
%17 = call i32 @getc(i32 %16)
store i32 %17, i32* %2
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* %2
%21 = call i32 @putchar(i32 %20)
br label %15
22: ; preds = %15
%23 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"File: \00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %3, %0
%4 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @gets(i8* %2)
%6 = call i32 @open(i8* %2, i32 0)
%7 = icmp slt i32 %6, 1
br i1 %7, label %3, label %8
8: ; preds = %3
%9 = call i32 @getc(i32 %6)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %8, %11
%12 = phi i32 [ %14, %11 ], [ %9, %8 ]
%13 = call i32 @putchar(i32 %12)
%14 = call i32 @getc(i32 %6)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %11, label %16
16: ; preds = %11, %8
%17 = call i32 @exit(i32 0)
unreachable
}