#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 */
scalar_t__ errno;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
char *strerror(scalar_t__);
int main(int argc, char **argv) {
  FILE *in;
  char fname[20];
  errno = 0;
  printf("Input a file you wanna open: ");
  scanf("%s", fname);
  in = fopen(fname, "r");
  if (errno) {
    printf("%s\n", strerror(errno));
    perror(fname);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e73(%rip),%rax
movq   $0x0,(%rax)
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xe91(%rip),%rdi
call   1040 <scanf@plt>
lea    -0x30(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e33(%rip),%rax
cmpq   $0x0,(%rax)
je     11e0 <main+0x90>
mov    0x2e22(%rip),%rax
mov    (%rax),%rdi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e72(%rip),%r14
movq   $0x0,(%r14)
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe94(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1050 <scanf@plt>
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    (%r14),%rdi
test   %rdi,%rdi
jne    11b6 <main+0x56>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
call   1080 <strerror@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1070 <perror@plt>
jmp    11ac <main+0x4c>

LLVM IR (-O0):
@errno = global i64 0
@.str = [30 x i8] c"Input a file you wanna open: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [20 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* @errno
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i64, i64* @errno
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i64, i64* @errno
%17 = call i8* @strerror(i64 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%20 = call i32 @perror(i8* %19)
br label %21
21: ; preds = %15, %2
ret i32 0
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [30 x i8] c"Input a file you wanna open: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
store i64 0, i64* @errno
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%7 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = load i64, i64* @errno
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = call i8* @strerror(i64 %8)
%12 = call i32 @puts(i8* dereferenceable(1) %11)
%13 = call i32 @perror(i8* %4)
br label %14
14: ; preds = %10, %2
ret i32 0
}