#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 */
typedef scalar_t__ ssize_t;

/* Variables and functions */
scalar_t__ EXIT_FAILURE;
int /*<<< orphan*/ errExit(char *);
int /*<<< orphan*/ free(void *);
scalar_t__ listAttrs(char *, void *, int);
void *malloc(int);
ssize_t listattr_numattr() {
  void *data = malloc(128);
  if (data == NULL) {
    errExit("test: malloc listAttrs buffer");
  }
  for (size_t i = 0; i < 128; i++) {
    ((char *)data)[i] = '\0';
  }
  ssize_t numAttrs = listAttrs("testFile", data, 128);
  free(data);
  data = NULL;
  if (numAttrs < 0) {
    return EXIT_FAILURE;
  }
  return numAttrs;
}


x86 assembly (clang, -O0):
<listattr_numattr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x80,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116d <listattr_numattr+0x2d>
lea    0xe98(%rip),%rdi
call   1040 <errExit@plt>
movq   $0x0,-0x18(%rbp)
cmpq   $0x80,-0x18(%rbp)
jae    11a0 <listattr_numattr+0x60>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1175 <listattr_numattr+0x35>
mov    -0x10(%rbp),%rsi
lea    0xe73(%rip),%rdi
mov    $0x80,%edx
call   1050 <listAttrs@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11e8 <listattr_numattr+0xa8>
mov    0x2e04(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11f0 <listattr_numattr+0xb0>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listattr_numattr>:
push   %r14
push   %rbx
push   %rax
mov    $0x80,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1162 <listattr_numattr+0x22>
lea    0xea3(%rip),%rdi
call   1040 <errExit@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0x70(%rbx)
movups %xmm0,0x60(%rbx)
movups %xmm0,0x50(%rbx)
movups %xmm0,0x40(%rbx)
movups %xmm0,0x30(%rbx)
movups %xmm0,0x20(%rbx)
movups %xmm0,0x10(%rbx)
movups %xmm0,(%rbx)
lea    0xe93(%rip),%rdi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1050 <listAttrs@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r14,%r14
jns    11b2 <listattr_numattr+0x72>
mov    0x2e31(%rip),%rax
mov    (%rax),%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [30 x i8] c"test: malloc listAttrs buffer\00"
@.str.1 = [9 x i8] c"testFile\00"
@EXIT_FAILURE = global i64 0
define i64 @listattr_numattr() {
%1 = alloca i64
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = call i8* @malloc(i32 128)
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @errExit(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
store i64 0, i64* %3
br label %11
11: ; preds = %18, %10
%12 = load i64, i64* %3
%13 = icmp ult i64 %12, 128
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i8*, i8** %2
%16 = load i64, i64* %3
%17 = getelementptr inbounds i8, i8* %15, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %14
%19 = load i64, i64* %3
%20 = add i64 %19, 1
store i64 %20, i64* %3
br label %11
21: ; preds = %11
%22 = load i8*, i8** %2
%23 = call i64 @listAttrs(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %22, i32 128)
store i64 %23, i64* %4
%24 = load i8*, i8** %2
%25 = call i32 @free(i8* %24)
store i8* null, i8** %2
%26 = load i64, i64* %4
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = load i64, i64* @EXIT_FAILURE
store i64 %29, i64* %1
br label %32
30: ; preds = %21
%31 = load i64, i64* %4
store i64 %31, i64* %1
br label %32
32: ; preds = %30, %28
%33 = load i64, i64* %1
ret i64 %33
}

LLVM IR (-O2):
@.str = [30 x i8] c"test: malloc listAttrs buffer\00"
@.str.1 = [9 x i8] c"testFile\00"
@EXIT_FAILURE = global i64 0
define i64 @listattr_numattr() {
%1 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @errExit(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %3, %0
%6 = tail call i64 @listAttrs(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 128)
%7 = tail call i32 @free(i8* %1)
%8 = icmp slt i64 %6, 0
%9 = load i64, i64* @EXIT_FAILURE
%10 = select i1 %8, i64 %9, i64 %6
ret i64 %10
}