#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
FILE *get_input_fd(int argc, char **argv) {
  if (argc == 1) {
    return stdin;
  }
  FILE *fd = fopen(argv[1], "r");
  if (!fd) {
    fprintf(stderr, "Nelze otevrit vstupni soubor: %s\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  return fd;
}


x86 assembly (clang, -O0):
<get_input_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    115c <get_input_fd+0x2c>
mov    0x2e98(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11b2 <get_input_fd+0x82>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe95(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11aa <get_input_fd+0x7a>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe6b(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_input_fd>:
push   %rbx
cmp    $0x1,%edi
jne    1142 <get_input_fd+0x12>
mov    0x2eab(%rip),%rax
mov    (%rax),%rax
pop    %rbx
ret
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xeb0(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     115c <get_input_fd+0x2c>
pop    %rbx
ret
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe92(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Nelze otevrit vstupni soubor: %s\0A\00"
@EXIT_FAILURE = global i32 0
define i32* @get_input_fd(i32 %0, i8** %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = load i32*, i32** @stdin
store i32* %10, i32** %3
br label %28
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %6
%16 = load i32*, i32** %6
%17 = icmp ne i32* %16, null
br i1 %17, label %26, label %18
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %11
%27 = load i32*, i32** %6
store i32* %27, i32** %3
br label %28
28: ; preds = %26, %9
%29 = load i32*, i32** %3
ret i32* %29
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Nelze otevrit vstupni soubor: %s\0A\00"
@EXIT_FAILURE = global i32 0
define i32* @get_input_fd(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = load i32*, i32** @stdin
br label %17
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %17
11: ; preds = %6
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %7
%14 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %6, %4
%18 = phi i32* [ %5, %4 ], [ %9, %6 ]
ret i32* %18
}