#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;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ check(char const *, struct stat, char const *const *, int);
int /*<<< orphan*/ do_dir(char const *, char const *const *);
int errno;
int /*<<< orphan*/ error(int, int, char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int lstat(char const *, struct stat *);
int /*<<< orphan*/ print(char const *);
void do_file(const char *file_name, const char *const *parms) {
  int parm_pos = 0;
  struct stat fd_in;
  if (lstat(file_name, &fd_in) == -1) {
    error(1, 1, "%d", errno);
    exit(EXIT_FAILURE);
  }
  check(file_name, fd_in, parms, parm_pos);
  if (parms[parm_pos] == NULL) {
    print(file_name);
  }
  if (S_ISDIR(fd_in.st_mode)) {
    do_dir(file_name, parms);
  }
}


x86 assembly (clang, -O0):
<do_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <lstat@plt>
cmp    $0xffffffff,%eax
jne    11c7 <do_file+0x57>
mov    0x2e3c(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
lea    0xe4e(%rip),%rdx
mov    %esi,%edi
call   1070 <error@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%esi
call   1080 <check@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11f6 <do_file+0x86>
mov    -0x8(%rbp),%rdi
call   1040 <print@plt>
mov    -0x18(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1215 <do_file+0xa5>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <do_dir@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1050 <lstat@plt>
cmp    $0xffffffff,%eax
je     11d6 <do_file+0x66>
mov    0x8(%rsp),%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1080 <check@plt>
cmpq   $0x0,(%r14)
jne    11ae <do_file+0x3e>
mov    %rbx,%rdi
call   1040 <print@plt>
mov    %ebp,%edi
call   1030 <S_ISDIR@plt>
test   %rax,%rax
je     11cd <do_file+0x5d>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <do_dir@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e03(%rip),%rax
mov    (%rax),%ecx
lea    0xe1a(%rip),%rdx
mov    $0x1,%edi
mov    $0x1,%esi
call   1070 <error@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [3 x i8] c"%d\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @do_file(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca %struct.stat
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32 0, i32* %5
%7 = load i8*, i8** %3
%8 = call i32 @lstat(i8* %7, %struct.stat* %6)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @errno
%12 = call i32 @error(i32 1, i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = load i8**, i8*** %4
%18 = load i32, i32* %5
%19 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @check(i8* %16, i32 %20, i8** %17, i32 %18)
%22 = load i8**, i8*** %4
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %15
%29 = load i8*, i8** %3
%30 = call i32 @print(i8* %29)
br label %31
31: ; preds = %28, %15
%32 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i64 @S_ISDIR(i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = load i8*, i8** %3
%38 = load i8**, i8*** %4
%39 = call i32 @do_dir(i8* %37, i8** %38)
br label %40
40: ; preds = %36, %31
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [3 x i8] c"%d\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @do_file(i8* %0, i8** %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i32 @lstat(i8* %0, %struct.stat* %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* @errno
%9 = tail call i32 @error(i32 1, i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%14 = load i32, i32* %13
%15 = tail call i32 @check(i8* %0, i32 %14, i8** %1, i32 0)
%16 = load i8*, i8** %1
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = tail call i32 @print(i8* %0)
br label %20
20: ; preds = %18, %12
%21 = tail call i64 @S_ISDIR(i32 %14)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i32 @do_dir(i8* %0, i8** %1)
br label %25
25: ; preds = %23, %20
ret void
}