#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 */
typedef struct TYPE_7__ TYPE_2__;
typedef struct TYPE_6__ TYPE_1__;

/* Type definitions */
struct TYPE_7__ {
  int fts_options;
  int /*<<< orphan*/ fts_path;
};
struct TYPE_6__ {
  size_t fts_namelen;
  int /*<<< orphan*/ *fts_pointer;
  scalar_t__ fts_number;
  int /*<<< orphan*/ fts_instr;
  scalar_t__ fts_flags;
  scalar_t__ fts_errno;
  int /*<<< orphan*/ fts_path;
  int /*<<< orphan*/ fts_name;
  int /*<<< orphan*/ *fts_statp;
};
typedef TYPE_1__ FTSENT;
typedef TYPE_2__ FTS;

/* Variables and functions */
int /*<<< orphan*/ FTS_NOINSTR;
int FTS_NOSTAT;
size_t UINT_MAX;
int /*<<< orphan*/ _DIAGASSERT(int /*<<< orphan*/);
int /*<<< orphan*/ free(TYPE_1__ *);
void *malloc(int);
int /*<<< orphan*/ memmove(int /*<<< orphan*/, char const *, size_t);
FTSENT *fts_alloc(FTS *sp, const char *name, size_t namelen) {
  FTSENT *p;
  _DIAGASSERT(sp != NULL);
  _DIAGASSERT(name != NULL);
  if ((p = malloc(sizeof(FTSENT) + namelen)) == NULL)
    return (NULL);
  if (!(sp->fts_options & (FTS_NOSTAT)))
    if ((p->fts_statp = malloc(sizeof(*(p->fts_statp)))) == NULL) {
      free(p);
      return (NULL);
    }
  if ((sp->fts_options & (FTS_NOSTAT)))
    p->fts_statp = NULL;
  memmove(p->fts_name, name, namelen + 1);
  p->fts_namelen = ((namelen) > UINT_MAX ? UINT_MAX : (unsigned int)(namelen));
  p->fts_path = sp->fts_path;
  p->fts_errno = 0;
  p->fts_flags = 0;
  p->fts_instr = FTS_NOINSTR;
  p->fts_number = 0;
  p->fts_pointer = NULL;
  return (p);
}


x86 assembly (clang, -O0):
<fts_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <_DIAGASSERT@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <_DIAGASSERT@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11a2 <fts_alloc+0x62>
movq   $0x0,-0x8(%rbp)
jmp    12bf <fts_alloc+0x17f>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    0x2e21(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    11f1 <fts_alloc+0xb1>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    -0x28(%rbp),%rcx
mov    %rax,0x38(%rcx)
cmp    $0x0,%rax
jne    11ec <fts_alloc+0xac>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12bf <fts_alloc+0x17f>
jmp    11f1 <fts_alloc+0xb1>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    0x2dd2(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1215 <fts_alloc+0xd5>
mov    -0x28(%rbp),%rax
movq   $0x0,0x38(%rax)
mov    -0x28(%rbp),%rax
mov    0x34(%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
add    $0x1,%rdx
call   1060 <memmove@plt>
mov    -0x20(%rbp),%rax
mov    0x2db0(%rip),%rcx
cmp    (%rcx),%rax
jbe    1254 <fts_alloc+0x114>
mov    0x2da0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    125e <fts_alloc+0x11e>
mov    -0x20(%rbp),%rax
mov    %eax,%eax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x30(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,0x28(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,0x20(%rax)
mov    0x2d42(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fts_alloc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1040 <_DIAGASSERT@plt>
xor    %edi,%edi
test   %r12,%r12
setne  %dil
call   1040 <_DIAGASSERT@plt>
lea    0x40(%r15),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1196 <fts_alloc+0x56>
mov    %rax,%rbx
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
test   %eax,(%r14)
je     119a <fts_alloc+0x5a>
movq   $0x0,0x38(%rbx)
jmp    11ad <fts_alloc+0x6d>
xor    %ebx,%ebx
jmp    11ee <fts_alloc+0xae>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,0x38(%rbx)
test   %rax,%rax
je     11fd <fts_alloc+0xbd>
lea    0x1(%r15),%rdx
mov    %r12,%rsi
call   1060 <memmove@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%rax
cmp    %r15,%rax
mov    %r15d,%ecx
cmovb  %rax,%rcx
mov    %rcx,(%rbx)
mov    0x4(%r14),%eax
mov    %eax,0x30(%rbx)
xorps  %xmm0,%xmm0
movups %xmm0,0x20(%rbx)
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rbx)
movups %xmm0,0x8(%rbx)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
jmp    11ee <fts_alloc+0xae>

LLVM IR (-O0):
%struct.TYPE_6__ = type { i64, i32*, i64, i32, i64, i64, i32, i32, i32* }
%struct.TYPE_7__ = type { i32, i32 }
@FTS_NOSTAT = global i32 0
@UINT_MAX = global i64 0
@FTS_NOINSTR = global i32 0
define %struct.TYPE_6__* @fts_alloc(%struct.TYPE_7__* %0, i8* %1, i64 %2) {
%4 = alloca %struct.TYPE_6__*
%5 = alloca %struct.TYPE_7__*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.TYPE_6__*
store %struct.TYPE_7__* %0, %struct.TYPE_7__** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = load %struct.TYPE_7__*, %struct.TYPE_7__** %5
%10 = icmp ne %struct.TYPE_7__* %9, null
%11 = zext i1 %10 to i32
%12 = call i32 @_DIAGASSERT(i32 %11)
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @_DIAGASSERT(i32 %15)
%17 = load i64, i64* %7
%18 = add i64 64, %17
%19 = trunc i64 %18 to i32
%20 = call i8* @malloc(i32 %19)
%21 = bitcast i8* %20 to %struct.TYPE_6__*
store %struct.TYPE_6__* %21, %struct.TYPE_6__** %8
%22 = icmp eq %struct.TYPE_6__* %21, null
br i1 %22, label %23, label %24
23: ; preds = %3
store %struct.TYPE_6__* null, %struct.TYPE_6__** %4
br label %89
24: ; preds = %3
%25 = load %struct.TYPE_7__*, %struct.TYPE_7__** %5
%26 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = load i32, i32* @FTS_NOSTAT
%29 = and i32 %27, %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %41, label %31
31: ; preds = %24
%32 = call i8* @malloc(i32 4)
%33 = bitcast i8* %32 to i32*
%34 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%35 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %34, i32 0, i32 8
store i32* %33, i32** %35
%36 = icmp eq i32* %33, null
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%39 = call i32 @free(%struct.TYPE_6__* %38)
store %struct.TYPE_6__* null, %struct.TYPE_6__** %4
br label %89
40: ; preds = %31
br label %41
41: ; preds = %40, %24
%42 = load %struct.TYPE_7__*, %struct.TYPE_7__** %5
%43 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = load i32, i32* @FTS_NOSTAT
%46 = and i32 %44, %45
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %41
%49 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%50 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %49, i32 0, i32 8
store i32* null, i32** %50
br label %51
51: ; preds = %48, %41
%52 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%53 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %52, i32 0, i32 7
%54 = load i32, i32* %53
%55 = load i8*, i8** %6
%56 = load i64, i64* %7
%57 = add i64 %56, 1
%58 = call i32 @memmove(i32 %54, i8* %55, i64 %57)
%59 = load i64, i64* %7
%60 = load i64, i64* @UINT_MAX
%61 = icmp ugt i64 %59, %60
br i1 %61, label %62, label %64
62: ; preds = %51
%63 = load i64, i64* @UINT_MAX
br label %68
64: ; preds = %51
%65 = load i64, i64* %7
%66 = trunc i64 %65 to i32
%67 = zext i32 %66 to i64
br label %68
68: ; preds = %64, %62
%69 = phi i64 [ %63, %62 ], [ %67, %64 ]
%70 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%71 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %70, i32 0, i32 0
store i64 %69, i64* %71
%72 = load %struct.TYPE_7__*, %struct.TYPE_7__** %5
%73 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %72, i32 0, i32 1
%74 = load i32, i32* %73
%75 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%76 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %75, i32 0, i32 6
store i32 %74, i32* %76
%77 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%78 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %77, i32 0, i32 5
store i64 0, i64* %78
%79 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%80 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %79, i32 0, i32 4
store i64 0, i64* %80
%81 = load i32, i32* @FTS_NOINSTR
%82 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%83 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %82, i32 0, i32 3
store i32 %81, i32* %83
%84 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%85 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %84, i32 0, i32 2
store i64 0, i64* %85
%86 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
%87 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %86, i32 0, i32 1
store i32* null, i32** %87
%88 = load %struct.TYPE_6__*, %struct.TYPE_6__** %8
store %struct.TYPE_6__* %88, %struct.TYPE_6__** %4
br label %89
89: ; preds = %68, %37, %23
%90 = load %struct.TYPE_6__*, %struct.TYPE_6__** %4
ret %struct.TYPE_6__* %90
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i64, i32*, i64, i32, i64, i64, i32, i32, i32* }
%struct.TYPE_7__ = type { i32, i32 }
@FTS_NOSTAT = global i32 0
@UINT_MAX = global i64 0
@FTS_NOINSTR = global i32 0
define noalias %struct.TYPE_6__* @fts_alloc(%struct.TYPE_7__* %0, i8* %1, i64 %2) {
%4 = icmp ne %struct.TYPE_7__* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @_DIAGASSERT(i32 %5)
%7 = icmp ne i8* %1, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @_DIAGASSERT(i32 %8)
%10 = trunc i64 %2 to i32
%11 = add i32 %10, 64
%12 = tail call i8* @malloc(i32 %11)
%13 = bitcast i8* %12 to %struct.TYPE_6__*
%14 = icmp eq i8* %12, null
br i1 %14, label %47, label %15
15: ; preds = %3
%16 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %0, i64 0, i32 0
%17 = load i32, i32* %16
%18 = load i32, i32* @FTS_NOSTAT
%19 = and i32 %18, %17
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %15
%22 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
%23 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %13, i64 0, i32 8
%24 = bitcast i32** %23 to i8**
store i8* %22, i8** %24
%25 = icmp eq i8* %22, null
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = tail call i32 @free(%struct.TYPE_6__* %13)
br label %47
28: ; preds = %15
%29 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %13, i64 0, i32 8
store i32* null, i32** %29
br label %30
30: ; preds = %21, %28
%31 = add i64 %2, 1
%32 = tail call i32 @memmove(i32 undef, i8* %1, i64 %31)
%33 = load i64, i64* @UINT_MAX
%34 = icmp ult i64 %33, %2
%35 = and i64 %2, 4294967295
%36 = select i1 %34, i64 %33, i64 %35
%37 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %13, i64 0, i32 0
store i64 %36, i64* %37
%38 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %0, i64 0, i32 1
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %13, i64 0, i32 6
store i32 %39, i32* %40
%41 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %13, i64 0, i32 4
%42 = bitcast i64* %41 to i8*
%43 = load i32, i32* @FTS_NOINSTR
%44 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %13, i64 0, i32 3
store i32 %43, i32* %44
%45 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %13, i64 0, i32 1
%46 = bitcast i32** %45 to i8*
br label %47
47: ; preds = %3, %30, %26
%48 = phi %struct.TYPE_6__* [ %13, %30 ], [ null, %26 ], [ null, %3 ]
ret %struct.TYPE_6__* %48
}