#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*/ errno;
int /*<<< orphan*/ fatalx(char *, ...);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
void openit(char *name, FILE **fff, char *type) {
  char *ss;
  if (name == NULL)
    fatalx("\n(openit) null name\n");
  *fff = fopen(name, type);
  if (*fff == NULL) {
    ss = strerror(errno);
    printf("bad open %s\n", name);
    fatalx("can't open file %s of type %s\n error info: %s\n", name, type, ss);
  }
}


x86 assembly (clang, -O0):
<openit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    116d <openit+0x2d>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <fatalx@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <fopen@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11ce <openit+0x8e>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <fatalx@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openit>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1161 <openit+0x21>
lea    0xea6(%rip),%rdi
xor    %eax,%eax
call   1030 <fatalx@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fopen@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     117a <openit+0x3a>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%r15
lea    0xe83(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xe81(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fatalx@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"\0A(openit) null name\0A\00"
@errno = global i32 0
@.str.1 = [13 x i8] c"bad open %s\0A\00"
@.str.2 = [47 x i8] c"can't open file %s of type %s\0A error info: %s\0A\00"
define void @openit(i8* %0, i32** %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32**
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i32** %1, i32*** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = call i32 (i8*, ...) @fatalx(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %3
%13 = load i8*, i8** %4
%14 = load i8*, i8** %6
%15 = call i32* @fopen(i8* %13, i8* %14)
%16 = load i32**, i32*** %5
store i32* %15, i32** %16
%17 = load i32**, i32*** %5
%18 = load i32*, i32** %17
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %29
20: ; preds = %12
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
store i8* %22, i8** %7
%23 = load i8*, i8** %4
%24 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %4
%26 = load i8*, i8** %6
%27 = load i8*, i8** %7
%28 = call i32 (i8*, ...) @fatalx(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %25, i8* %26, i8* %27)
br label %29
29: ; preds = %20, %12
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"\0A(openit) null name\0A\00"
@errno = global i32 0
@.str.1 = [13 x i8] c"bad open %s\0A\00"
@.str.2 = [47 x i8] c"can't open file %s of type %s\0A error info: %s\0A\00"
define void @openit(i8* %0, i32** nocapture writeonly %1, i8* %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 (i8*, ...) @fatalx(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %3
%8 = tail call i32* @fopen(i8* %0, i8* %2)
store i32* %8, i32** %1
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%14 = tail call i32 (i8*, ...) @fatalx(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %2, i8* %12)
br label %15
15: ; preds = %10, %7
ret void
}