#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 xattr_list {
  int dummy;
};
struct squashfs_super_block {
  int dummy;
};

/* Variables and functions */
int generate_xattrs(unsigned int, struct xattr_list *);
struct xattr_list *get_xattr(int, unsigned int *, int /*<<< orphan*/);
int /*<<< orphan*/ progressbar_error(char *);
int read_xattrs_from_disk(int, struct squashfs_super_block *);
int get_xattrs(int fd, struct squashfs_super_block *sBlk) {
  int ids, res, i, id;
  unsigned int count;
  ;
  res = read_xattrs_from_disk(fd, sBlk);
  if (res == ((long long)-1) || res == 0)
    goto done;
  ids = res;
  for (i = 0; i < ids; i++) {
    struct xattr_list *xattr_list = get_xattr(i, &count, 0);
    if (xattr_list == NULL) {
      res = 0;
      goto done;
    }
    id = generate_xattrs(count, xattr_list);
    if (id != i) {
      do {
        progressbar_error("BUG, different xattr_id in get_xattrs\n");
      } while (0);
      res = 0;
      goto done;
    }
  }
done:
  return res;
}


x86 assembly (clang, -O0):
<get_xattrs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <read_xattrs_from_disk@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    $0xffffffffffffffff,%rax
je     1176 <get_xattrs+0x36>
cmpl   $0x0,-0x18(%rbp)
jne    117b <get_xattrs+0x3b>
jmp    120d <get_xattrs+0xcd>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1208 <get_xattrs+0xc8>
mov    -0x1c(%rbp),%edi
lea    -0x24(%rbp),%rsi
xor    %edx,%edx
call   1030 <get_xattr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11bd <get_xattrs+0x7d>
movl   $0x0,-0x18(%rbp)
jmp    120d <get_xattrs+0xcd>
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1040 <generate_xattrs@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11f5 <get_xattrs+0xb5>
jmp    11dd <get_xattrs+0x9d>
lea    0xe1c(%rip),%rdi
call   1060 <progressbar_error@plt>
movl   $0x0,-0x18(%rbp)
jmp    120d <get_xattrs+0xcd>
jmp    11fa <get_xattrs+0xba>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1188 <get_xattrs+0x48>
jmp    120d <get_xattrs+0xcd>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_xattrs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
call   1050 <read_xattrs_from_disk@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1188 <get_xattrs+0x48>
xor    %r14d,%r14d
lea    0x4(%rsp),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r15,%rsi
xor    %edx,%edx
call   1030 <get_xattr@plt>
test   %rax,%rax
je     1199 <get_xattrs+0x59>
mov    0x4(%rsp),%edi
mov    %rax,%rsi
call   1040 <generate_xattrs@plt>
cmp    %eax,%ebx
jne    118d <get_xattrs+0x4d>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1160 <get_xattrs+0x20>
mov    %ebp,%r14d
jmp    1199 <get_xattrs+0x59>
lea    0xe6c(%rip),%rdi
call   1060 <progressbar_error@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.squashfs_super_block = type { i32 }
%struct.xattr_list = type { i32 }
@.str = [39 x i8] c"BUG, different xattr_id in get_xattrs\0A\00"
define i32 @get_xattrs(i32 %0, %struct.squashfs_super_block* %1) {
%3 = alloca i32
%4 = alloca %struct.squashfs_super_block*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.xattr_list*
store i32 %0, i32* %3
store %struct.squashfs_super_block* %1, %struct.squashfs_super_block** %4
%11 = load i32, i32* %3
%12 = load %struct.squashfs_super_block*, %struct.squashfs_super_block** %4
%13 = call i32 @read_xattrs_from_disk(i32 %11, %struct.squashfs_super_block* %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = icmp eq i64 %15, -1
br i1 %16, label %20, label %17
17: ; preds = %2
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17, %2
br label %49
21: ; preds = %17
%22 = load i32, i32* %6
store i32 %22, i32* %5
store i32 0, i32* %7
br label %23
23: ; preds = %45, %21
%24 = load i32, i32* %7
%25 = load i32, i32* %5
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %48
27: ; preds = %23
%28 = load i32, i32* %7
%29 = call %struct.xattr_list* @get_xattr(i32 %28, i32* %9, i32 0)
store %struct.xattr_list* %29, %struct.xattr_list** %10
%30 = load %struct.xattr_list*, %struct.xattr_list** %10
%31 = icmp eq %struct.xattr_list* %30, null
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 0, i32* %6
br label %49
33: ; preds = %27
%34 = load i32, i32* %9
%35 = load %struct.xattr_list*, %struct.xattr_list** %10
%36 = call i32 @generate_xattrs(i32 %34, %struct.xattr_list* %35)
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = load i32, i32* %7
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %44
40: ; preds = %33
br label %41
41: ; preds = %40
%42 = call i32 @progressbar_error(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %43
43: ; preds = %41
store i32 0, i32* %6
br label %49
44: ; preds = %33
br label %45
45: ; preds = %44
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %23
48: ; preds = %23
br label %49
49: ; preds = %48, %43, %32, %20
%50 = load i32, i32* %6
ret i32 %50
}

LLVM IR (-O2):
%struct.squashfs_super_block = type { i32 }
%struct.xattr_list = type { i32 }
@.str = [39 x i8] c"BUG, different xattr_id in get_xattrs\0A\00"
define i32 @get_xattrs(i32 %0, %struct.squashfs_super_block* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @read_xattrs_from_disk(i32 %0, %struct.squashfs_super_block* %1)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %9, label %20
7: ; preds = %13
%8 = icmp eq i32 %17, %5
br i1 %8, label %20, label %9
9: ; preds = %2, %7
%10 = phi i32 [ %17, %7 ], [ 0, %2 ]
%11 = call %struct.xattr_list* @get_xattr(i32 %10, i32* %3, i32 0)
%12 = icmp eq %struct.xattr_list* %11, null
br i1 %12, label %20, label %13
13: ; preds = %9
%14 = load i32, i32* %3
%15 = call i32 @generate_xattrs(i32 %14, %struct.xattr_list* %11)
%16 = icmp eq i32 %15, %10
%17 = add nuw nsw i32 %10, 1
br i1 %16, label %7, label %18
18: ; preds = %13
%19 = call i32 @progressbar_error(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %7, %9, %18, %2
%21 = phi i32 [ %5, %2 ], [ 0, %18 ], [ %5, %7 ], [ 0, %9 ]
ret i32 %21
}