#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 */

/* Variables and functions */
int ENOENT;
int /*<<< orphan*/ MAXPATHLEN;
int /*<<< orphan*/ O_RDONLY;
int _DtHelpCeUncompressFile(char *, char *);
int errno;
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(scalar_t__);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ tmpnam(char *);
int /*<<< orphan*/ unlink(char *);
int FileOpenRtnFd(char *name, int *ret_fd) {
  char *inFile = 0;
  char tmpName[MAXPATHLEN + 1];
  int result = 1;
  *ret_fd = open(name, O_RDONLY);
  if (*ret_fd == -1) {
    (void)tmpnam(tmpName);
    inFile = (char *)malloc(strlen(name) + 3);
    if (inFile != 0) {
      strcpy(inFile, name);
      strcat(inFile, ".Z");
      result = _DtHelpCeUncompressFile(inFile, tmpName);
      free(inFile);
      if (result != 0) {
        errno = ENOENT;
        return -1;
      }
      *ret_fd = open(tmpName, O_RDONLY);
      if (*ret_fd == -1)
        result = -1;
      else
        unlink(tmpName);
    } else {
      errno = -7;
      return -1;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<FileOpenRtnFd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    12fd <FileOpenRtnFd+0x16d>
mov    -0x40(%rbp),%rdi
call   10b0 <tmpnam@plt>
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rdi
add    $0x3,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12d8 <FileOpenRtnFd+0x148>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xdb6(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%rdi
call   1060 <_DtHelpCeUncompressFile@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x34(%rbp)
je     1297 <FileOpenRtnFd+0x107>
mov    0x2d47(%rip),%rax
mov    (%rax),%ecx
mov    0x2d4e(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    130a <FileOpenRtnFd+0x17a>
mov    -0x40(%rbp),%rdi
mov    0x2d46(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    12ca <FileOpenRtnFd+0x13a>
movl   $0xffffffff,-0x34(%rbp)
jmp    12d3 <FileOpenRtnFd+0x143>
mov    -0x40(%rbp),%rdi
call   1040 <unlink@plt>
jmp    12f8 <FileOpenRtnFd+0x168>
mov    0x2cf1(%rip),%rax
movl   $0xfffffff9,(%rax)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    130a <FileOpenRtnFd+0x17a>
jmp    12fd <FileOpenRtnFd+0x16d>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileOpenRtnFd>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e20(%rip),%r13
mov    0x0(%r13),%esi
call   1090 <open@plt>
mov    %eax,%ecx
mov    %eax,(%r14)
mov    $0x1,%eax
cmp    $0xffffffff,%ecx
jne    125c <FileOpenRtnFd+0xcc>
mov    %rbx,%rdi
call   10b0 <tmpnam@plt>
mov    %r15,%rdi
call   1070 <strlen@plt>
lea    0x3(%rax),%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     124a <FileOpenRtnFd+0xba>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <strcpy@plt>
lea    0xded(%rip),%rsi
mov    %r12,%rdi
call   10a0 <strcat@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <_DtHelpCeUncompressFile@plt>
mov    %eax,%r15d
mov    %r12,%rdi
call   1030 <free@plt>
test   %r15d,%r15d
je     126b <FileOpenRtnFd+0xdb>
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
mov    0x2d8a(%rip),%rcx
mov    %eax,(%rcx)
jmp    1257 <FileOpenRtnFd+0xc7>
mov    0x2d7f(%rip),%rax
movl   $0xfffffff9,(%rax)
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
mov    %eax,(%r14)
cmp    $0xffffffff,%eax
je     1257 <FileOpenRtnFd+0xc7>
mov    %rbx,%rdi
call   1040 <unlink@plt>
xor    %eax,%eax
jmp    125c <FileOpenRtnFd+0xcc>

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
@O_RDONLY = global i32 0
@.str = [3 x i8] c".Z\00"
@ENOENT = global i32 0
@errno = global i32 0
define i32 @FileOpenRtnFd(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i8* null, i8** %6
%11 = load i32, i32* @MAXPATHLEN
%12 = add nsw i32 %11, 1
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %7
%15 = alloca i8, i64 %13
store i64 %13, i64* %8
store i32 1, i32* %9
%16 = load i8*, i8** %4
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %16, i32 %17)
%19 = load i32*, i32** %5
store i32 %18, i32* %19
%20 = load i32*, i32** %5
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %59
23: ; preds = %2
%24 = call i32 @tmpnam(i8* %15)
%25 = load i8*, i8** %4
%26 = call i64 @strlen(i8* %25)
%27 = add nsw i64 %26, 3
%28 = call i64 @malloc(i64 %27)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %6
%30 = load i8*, i8** %6
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %57
32: ; preds = %23
%33 = load i8*, i8** %6
%34 = load i8*, i8** %4
%35 = call i32 @strcpy(i8* %33, i8* %34)
%36 = load i8*, i8** %6
%37 = call i32 @strcat(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%38 = load i8*, i8** %6
%39 = call i32 @_DtHelpCeUncompressFile(i8* %38, i8* %15)
store i32 %39, i32* %9
%40 = load i8*, i8** %6
%41 = call i32 @free(i8* %40)
%42 = load i32, i32* %9
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %32
%45 = load i32, i32* @ENOENT
store i32 %45, i32* @errno
store i32 -1, i32* %3
store i32 1, i32* %10
br label %61
46: ; preds = %32
%47 = load i32, i32* @O_RDONLY
%48 = call i32 @open(i8* %15, i32 %47)
%49 = load i32*, i32** %5
store i32 %48, i32* %49
%50 = load i32*, i32** %5
%51 = load i32, i32* %50
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %54
53: ; preds = %46
store i32 -1, i32* %9
br label %56
54: ; preds = %46
%55 = call i32 @unlink(i8* %15)
br label %56
56: ; preds = %54, %53
br label %58
57: ; preds = %23
store i32 -7, i32* @errno
store i32 -1, i32* %3
store i32 1, i32* %10
br label %61
58: ; preds = %56
br label %59
59: ; preds = %58, %2
%60 = load i32, i32* %9
store i32 %60, i32* %3
store i32 1, i32* %10
br label %61
61: ; preds = %59, %57, %44
%62 = load i8*, i8** %7
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@O_RDONLY = global i32 0
@.str = [3 x i8] c".Z\00"
@ENOENT = global i32 0
@errno = global i32 0
define i32 @FileOpenRtnFd(i8* %0, i32* nocapture writeonly %1) {
%3 = load i32, i32* @MAXPATHLEN
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %0, i32 %7)
store i32 %8, i32* %1
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %32
10: ; preds = %2
%11 = call i32 @tmpnam(i8* %6)
%12 = call i64 @strlen(i8* dereferenceable(1) %0)
%13 = add nsw i64 %12, 3
%14 = call i64 @malloc(i64 %13)
%15 = inttoptr i64 %14 to i8*
%16 = icmp eq i64 %14, 0
br i1 %16, label %31, label %17
17: ; preds = %10
%18 = call i32 @strcpy(i8* %15, i8* %0)
%19 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @_DtHelpCeUncompressFile(i8* %15, i8* %6)
%21 = call i32 @free(i8* %15)
%22 = icmp eq i32 %20, 0
br i1 %22, label %25, label %23
23: ; preds = %17
%24 = load i32, i32* @ENOENT
store i32 %24, i32* @errno
br label %32
25: ; preds = %17
%26 = load i32, i32* @O_RDONLY
%27 = call i32 @open(i8* %6, i32 %26)
store i32 %27, i32* %1
%28 = icmp eq i32 %27, -1
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = call i32 @unlink(i8* %6)
br label %32
31: ; preds = %10
store i32 -7, i32* @errno
br label %32
32: ; preds = %2, %29, %25, %31, %23
%33 = phi i32 [ -1, %23 ], [ -1, %31 ], [ 0, %29 ], [ 1, %2 ], [ -1, %25 ]
ret i32 %33
}