#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*/ F_OK;
int /*<<< orphan*/ MAXPATHLEN;
int _DtHelpCeUncompressFile(char *, char *);
int access(char *, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ tmpnam(char *);
int _DtHelpCeGetUncompressedFileName(char *name, char **ret_name) {
  char *inFile = 0;
  char tmpName[MAXPATHLEN + 1];
  int result = 1;
  *ret_name = name;
  if (access(name, F_OK) == -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_name = strdup(tmpName);
      if (*ret_name == 0) {
        errno = -7;
        return -1;
      }
    } else {
      errno = -7;
      return -1;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<_DtHelpCeGetUncompressedFileName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2e39(%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),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
cmp    $0xffffffff,%eax
jne    1301 <_DtHelpCeGetUncompressedFileName+0x171>
mov    -0x40(%rbp),%rdi
call   10a0 <tmpnam@plt>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rdi
add    $0x3,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12dc <_DtHelpCeGetUncompressedFileName+0x14c>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xdb7(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%rdi
call   1050 <_DtHelpCeUncompressFile@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x34(%rbp)
je     1296 <_DtHelpCeGetUncompressedFileName+0x106>
mov    0x2d50(%rip),%rax
mov    (%rax),%ecx
mov    0x2d57(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    130e <_DtHelpCeGetUncompressedFileName+0x17e>
mov    -0x40(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    12d7 <_DtHelpCeGetUncompressedFileName+0x147>
mov    0x2d1a(%rip),%rax
movl   $0xfffffff9,(%rax)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    130e <_DtHelpCeGetUncompressedFileName+0x17e>
jmp    12fc <_DtHelpCeGetUncompressedFileName+0x16c>
mov    0x2cf5(%rip),%rax
movl   $0xfffffff9,(%rax)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    130e <_DtHelpCeGetUncompressedFileName+0x17e>
jmp    1301 <_DtHelpCeGetUncompressedFileName+0x171>
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):
<_DtHelpCeGetUncompressedFileName>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rdi,(%rsi)
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0xffffffff,%ecx
jne    126e <_DtHelpCeGetUncompressedFileName+0xde>
mov    %rbx,%rdi
call   10a0 <tmpnam@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    0x3(%rax),%rdi
call   1070 <malloc@plt>
mov    $0xfffffff9,%r13d
test   %rax,%rax
je     125f <_DtHelpCeGetUncompressedFileName+0xcf>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
lea    0xde5(%rip),%rsi
mov    %r12,%rdi
call   1090 <strcat@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <_DtHelpCeUncompressFile@plt>
mov    %eax,%r15d
mov    %r12,%rdi
call   1030 <free@plt>
test   %r15d,%r15d
je     124a <_DtHelpCeGetUncompressedFileName+0xba>
mov    0x2d83(%rip),%rax
mov    (%rax),%r13d
jmp    125f <_DtHelpCeGetUncompressedFileName+0xcf>
mov    %rbx,%rdi
call   10b0 <strdup@plt>
mov    %rax,%rcx
mov    %rax,(%r14)
xor    %eax,%eax
test   %rcx,%rcx
jne    126e <_DtHelpCeGetUncompressedFileName+0xde>
mov    0x2d72(%rip),%rax
mov    %r13d,(%rax)
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@F_OK = global i32 0
@.str = [3 x i8] c".Z\00"
@ENOENT = global i32 0
@errno = global i32 0
define i32 @_DtHelpCeGetUncompressedFileName(i8* %0, i8** 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
store i8* %0, i8** %1
%7 = load i32, i32* @F_OK
%8 = tail call i32 @access(i8* %0, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %30
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 %28, 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
br label %28
25: ; preds = %17
%26 = call i8* @strdup(i8* %6)
store i8* %26, i8** %1
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %10, %25, %23
%29 = phi i32 [ %24, %23 ], [ -7, %25 ], [ -7, %10 ]
store i32 %29, i32* @errno
br label %30
30: ; preds = %28, %2, %25
%31 = phi i32 [ 0, %25 ], [ 1, %2 ], [ -1, %28 ]
ret i32 %31
}