#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int main() {
  FILE *fp;
  char str[100 + 1];
  if ((fp = fopen("/home/gerry/ssh3", "rt")) == NULL) {
    printf("Cannot open file, press any key to exit!\n");
    getchar();
    exit(1);
  }
  while (fgets(str, 100, fp) != NULL) {
    printf("%s", str);
  }
  fclose(fp);
  sleep(10000);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11c2 <main+0x52>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11c7 <main+0x57>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11fa <main+0x8a>
lea    -0x80(%rbp),%rsi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11c7 <main+0x57>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x2710,%edi
call   1090 <sleep@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
lea    0xe70(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1210 <main+0x90>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11f2 <main+0x72>
lea    0xe54(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11d0 <main+0x50>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    $0x2710,%edi
call   10a0 <sleep@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe00(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"/home/gerry/ssh3\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [42 x i8] c"Cannot open file, press any key to exit!\0A\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [101 x i8]
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 (...) @getchar()
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
br label %11
11: ; preds = %16, %10
%12 = getelementptr inbounds [101 x i8], [101 x i8]* %3, i64 0, i64 0
%13 = load i32*, i32** %2
%14 = call i32* @fgets(i8* %12, i32 100, i32* %13)
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = getelementptr inbounds [101 x i8], [101 x i8]* %3, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %17)
br label %11
19: ; preds = %11
%20 = load i32*, i32** %2
%21 = call i32 @fclose(i32* %20)
%22 = call i32 @sleep(i32 10000)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"/home/gerry/ssh3\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.3 = [3 x i8] c"%s\00"
@str = [41 x i8] c"Cannot open file, press any key to exit!\00"
define i32 @main() {
%1 = alloca [101 x i8]
%2 = getelementptr inbounds [101 x i8], [101 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32* @fgets(i8* %2, i32 100, i32* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %16, label %12
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 (...) @getchar()
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %5, %12
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%14 = call i32* @fgets(i8* %2, i32 100, i32* %3)
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %12
16: ; preds = %12, %5
%17 = call i32 @fclose(i32* %3)
%18 = call i32 @sleep(i32 10000)
ret i32 0
}