#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 /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char **argv) {
  FILE *fp = NULL;
  char f_name[100];
  switch (argc) {
  case (1):
    fgets(f_name, 100, stdin);
    break;
  case (2):
    strncpy(f_name, argv[1], 100);
    break;
  default:
    printf("\nErro de syntax %s", argv[0]);
    exit(0);
  }
  fputs(f_name, stdout);
  fp = fopen(f_name, "r");
  if (fp == NULL)
    printf("\nNão abriu.\n");
  else
    printf("\nAbriu\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x84(%rbp)
sub    $0x1,%eax
je     11ac <main+0x4c>
jmp    1198 <main+0x38>
mov    -0x84(%rbp),%eax
sub    $0x2,%eax
je     11c8 <main+0x68>
jmp    11e3 <main+0x83>
lea    -0x80(%rbp),%rdi
mov    0x2e31(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1060 <fgets@plt>
jmp    11ff <main+0x9f>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x64,%edx
call   1030 <strncpy@plt>
jmp    11ff <main+0x9f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    -0x80(%rbp),%rdi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
lea    -0x80(%rbp),%rdi
lea    0xdf7(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1243 <main+0xe3>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1251 <main+0xf1>
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
cmp    $0x2,%edi
je     1197 <main+0x27>
cmp    $0x1,%edi
jne    11ed <main+0x7d>
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x64,%esi
call   1070 <fgets@plt>
jmp    11a8 <main+0x38>
mov    0x8(%rsi),%rsi
mov    %rsp,%rdi
mov    $0x64,%edx
call   1030 <strncpy@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <fputs@plt>
lea    0xe50(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
lea    0xe47(%rip),%rax
lea    0xe39(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
ret
mov    (%rsi),%rsi
lea    0xe09(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [19 x i8] c"\0AErro de syntax %s\00"
@stdout = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"\0AN\C3\A3o abriu.\0A\00"
@.str.3 = [8 x i8] c"\0AAbriu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
%8 = load i32, i32* %4
switch i32 %8, label %19 [
i32 1, label %9
i32 2, label %13
]
9: ; preds = %2
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%11 = load i32, i32* @stdin
%12 = call i32 @fgets(i8* %10, i32 100, i32 %11)
br label %25
13: ; preds = %2
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @strncpy(i8* %14, i8* %17, i32 100)
br label %25
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %13, %9
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%27 = load i32, i32* @stdout
%28 = call i32 @fputs(i8* %26, i32 %27)
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %30, i32** %6
%31 = load i32*, i32** %6
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %35
33: ; preds = %25
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %37
35: ; preds = %25
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %35, %33
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [19 x i8] c"\0AErro de syntax %s\00"
@stdout = global i32 0
@.str.1 = [2 x i8] c"r\00"
@str = [7 x i8] c"\0AAbriu\00"
@str.4 = [13 x i8] c"\0AN\C3\A3o abriu.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
switch i32 %0, label %12 [
i32 1, label %5
i32 2, label %8
]
5: ; preds = %2
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %4, i32 100, i32 %6)
br label %16
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @strncpy(i8* %4, i8* %10, i32 100)
br label %16
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %8, %5
%17 = load i32, i32* @stdout
%18 = call i32 @fputs(i8* %4, i32 %17)
%19 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i32* %19, null
%21 = select i1 %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0)
%22 = call i32 @puts(i8* dereferenceable(1) %21)
ret i32 0
}