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

/* Variables and functions */
int S_IFMT;
int S_IFREG;
int /*<<< orphan*/ adddir(char *, char *);
int /*<<< orphan*/ addtab(char *, struct stat *);
int /*<<< orphan*/ perror(char *);
scalar_t__ stat(char *, struct stat *);
void add(char *name) {
  struct stat st;
  if (stat(name, &st) < 0) {
    perror(name);
    return;
  }
  if ((st.st_mode & S_IFMT) == S_IFREG)
    addtab(name, &st);
  else
    adddir((char *)0, name);
}


x86 assembly (clang, -O0):
<add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
jge    1171 <add+0x31>
mov    -0x8(%rbp),%rdi
call   1050 <perror@plt>
jmp    11ab <add+0x6b>
mov    -0x10(%rbp),%eax
mov    0x2e5d(%rip),%rcx
and    (%rcx),%eax
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%eax
jne    119e <add+0x5e>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <addtab@plt>
jmp    11ab <add+0x6b>
mov    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <adddir@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
test   %rax,%rax
js     118e <add+0x4e>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
and    0x8(%rsp),%eax
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%eax
jne    117e <add+0x3e>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <addtab@plt>
jmp    1188 <add+0x48>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <adddir@plt>
add    $0x10,%rsp
pop    %rbx
ret
mov    %rbx,%rdi
call   1050 <perror@plt>
jmp    1188 <add+0x48>

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IFMT = global i32 0
@S_IFREG = global i32 0
define void @add(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @stat(i8* %4, %struct.stat* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = call i32 @perror(i8* %8)
br label %23
10: ; preds = %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%12 = load i32, i32* %11
%13 = load i32, i32* @S_IFMT
%14 = and i32 %12, %13
%15 = load i32, i32* @S_IFREG
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = load i8*, i8** %2
%19 = call i32 @addtab(i8* %18, %struct.stat* %3)
br label %23
20: ; preds = %10
%21 = load i8*, i8** %2
%22 = call i32 @adddir(i8* null, i8* %21)
br label %23
23: ; preds = %7, %20, %17
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IFMT = global i32 0
@S_IFREG = global i32 0
define void @add(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @stat(i8* %0, %struct.stat* %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @perror(i8* %0)
br label %19
8: ; preds = %1
%9 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%10 = load i32, i32* %9
%11 = load i32, i32* @S_IFMT
%12 = and i32 %11, %10
%13 = load i32, i32* @S_IFREG
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = call i32 @addtab(i8* %0, %struct.stat* %2)
br label %19
17: ; preds = %8
%18 = call i32 @adddir(i8* null, i8* %0)
br label %19
19: ; preds = %15, %17, %6
ret void
}