#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ *fopen(char const *, char *);
int lstat(char const *, struct stat *);
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strcmp(char const *, char *);
int /*<<< orphan*/ weprintf(char *, ...);
FILE *parsefile(const char *fname) {
  struct stat st;
  int ret;
  if (!strcmp(fname, "/dev/stdout") || !strcmp(fname, "-"))
    return stdout;
  ret = lstat(fname, &st);
  if (ret < 0 && errno == ENOENT)
    goto tropen;
  if (ret < 0) {
    weprintf("lstat %s:", fname);
    return NULL;
  }
  if (!S_ISREG(st.st_mode)) {
    weprintf(
        "for safety uudecode operates only on regular files and /dev/stdout\n");
    return NULL;
  }
tropen:
  return fopen(fname, "w");
}


x86 assembly (clang, -O0):
<parsefile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
je     118e <parsefile+0x3e>
mov    -0x10(%rbp),%rdi
lea    0xe8c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11a1 <parsefile+0x51>
mov    0x2e43(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    1248 <parsefile+0xf8>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <lstat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11da <parsefile+0x8a>
mov    0x2e1e(%rip),%rax
mov    (%rax),%rax
mov    0x2dfc(%rip),%rcx
cmp    (%rcx),%rax
jne    11da <parsefile+0x8a>
jmp    1234 <parsefile+0xe4>
cmpl   $0x0,-0x1c(%rbp)
jge    1203 <parsefile+0xb3>
mov    -0x10(%rbp),%rsi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1060 <weprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1248 <parsefile+0xf8>
mov    -0x18(%rbp),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%eax
jne    122f <parsefile+0xdf>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1060 <weprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1248 <parsefile+0xf8>
jmp    1234 <parsefile+0xe4>
mov    -0x10(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsefile>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xea2(%rip),%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11a8 <parsefile+0x58>
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11a8 <parsefile+0x58>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <lstat@plt>
test   %eax,%eax
js     11bd <parsefile+0x6d>
mov    (%rsp),%edi
call   1050 <S_ISREG@plt>
test   %eax,%eax
jne    11d3 <parsefile+0x83>
lea    0xe7c(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <weprintf@plt>
jmp    11b2 <parsefile+0x62>
mov    0x2e29(%rip),%rax
mov    (%rax),%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e1c(%rip),%rax
mov    (%rax),%rax
mov    0x2dfa(%rip),%rcx
cmp    (%rcx),%rax
jne    11e9 <parsefile+0x99>
lea    0xe82(%rip),%rsi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <fopen@plt>
lea    0xe1e(%rip),%rdi
xor    %r14d,%r14d
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <weprintf@plt>
jmp    11b2 <parsefile+0x62>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [12 x i8] c"/dev/stdout\00"
@.str.1 = [2 x i8] c"-\00"
@stdout = global i32* null
@errno = global i64 0
@ENOENT = global i64 0
@.str.2 = [10 x i8] c"lstat %s:\00"
@.str.3 = [68 x i8] c"for safety uudecode operates only on regular files and /dev/stdout\0A\00"
@.str.4 = [2 x i8] c"w\00"
define i32* @parsefile(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strcmp(i8* %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @strcmp(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9, %1
%14 = load i32*, i32** @stdout
store i32* %14, i32** %2
br label %42
15: ; preds = %9
%16 = load i8*, i8** %3
%17 = call i32 @lstat(i8* %16, %struct.stat* %4)
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i64, i64* @errno
%22 = load i64, i64* @ENOENT
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %20
br label %39
25: ; preds = %20, %15
%26 = load i32, i32* %5
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i8*, i8** %3
%30 = call i32 (i8*, ...) @weprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %29)
store i32* null, i32** %2
br label %42
31: ; preds = %25
%32 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 @S_ISREG(i32 %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %31
%37 = call i32 (i8*, ...) @weprintf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0))
store i32* null, i32** %2
br label %42
38: ; preds = %31
br label %39
39: ; preds = %38, %24
%40 = load i8*, i8** %3
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %41, i32** %2
br label %42
42: ; preds = %39, %36, %28, %13
%43 = load i32*, i32** %2
ret i32* %43
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [12 x i8] c"/dev/stdout\00"
@.str.1 = [2 x i8] c"-\00"
@stdout = global i32* null
@errno = global i64 0
@ENOENT = global i64 0
@.str.2 = [10 x i8] c"lstat %s:\00"
@.str.3 = [68 x i8] c"for safety uudecode operates only on regular files and /dev/stdout\0A\00"
@.str.4 = [2 x i8] c"w\00"
define i32* @parsefile(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6, %1
%10 = load i32*, i32** @stdout
br label %29
11: ; preds = %6
%12 = call i32 @lstat(i8* %0, %struct.stat* %2)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i64, i64* @errno
%16 = load i64, i64* @ENOENT
%17 = icmp eq i64 %15, %16
br i1 %17, label %27, label %18
18: ; preds = %14
%19 = tail call i32 (i8*, ...) @weprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %29
20: ; preds = %11
%21 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%22 = load i32, i32* %21
%23 = tail call i32 @S_ISREG(i32 %22)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = tail call i32 (i8*, ...) @weprintf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0))
br label %29
27: ; preds = %20, %14
%28 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %27, %25, %18, %9
%30 = phi i32* [ %28, %27 ], [ null, %18 ], [ null, %25 ], [ %10, %9 ]
ret i32* %30
}