#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 int /*<<< orphan*/ uint64_t;
typedef int uint32_t;
struct stat {
  int st_uid;
  int st_gid;
  int st_mode;
  int st_atime;
  int st_mtime;
  int /*<<< orphan*/ st_size;
};
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ memset(struct stat *, int /*<<< orphan*/, int);
int read_uint32(int *);
int /*<<< orphan*/ read_uint64(int /*<<< orphan*/ *);
ssize_t read_attr(uint32_t *attr_flags, struct stat *st) {
  ssize_t r;
  uint64_t attr_size;
  uint32_t attr_uid, attr_gid;
  uint32_t attr_permissions;
  uint32_t attr_atime, attr_mtime;
  if ((r = read_uint32(attr_flags)) == -1)
    return r;
  memset(st, 0, sizeof(*st));
  if (*attr_flags & 0x00000001) {
    read_uint64(&attr_size);
    st->st_size = attr_size;
  }
  if (*attr_flags & 0x00000002) {
    read_uint32(&attr_uid);
    st->st_uid = attr_uid;
  }
  if (*attr_flags & 0x00000002) {
    read_uint32(&attr_gid);
    st->st_gid = attr_gid;
  }
  if (*attr_flags & 0x00000004) {
    read_uint32(&attr_permissions);
    st->st_mode = attr_permissions;
  }
  if (*attr_flags & 0x00000008) {
    read_uint32(&attr_atime);
    st->st_atime = attr_atime;
  }
  if (*attr_flags & 0x00000008) {
    read_uint32(&attr_mtime);
    st->st_mtime = attr_mtime;
  }
  return r;
}


x86 assembly (clang, -O0):
<read_attr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <read_uint32@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1160 <read_attr+0x30>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1253 <read_attr+0x123>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1195 <read_attr+0x65>
lea    -0x20(%rbp),%rdi
call   1050 <read_uint64@plt>
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x14(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     11b9 <read_attr+0x89>
lea    -0x24(%rbp),%rdi
call   1030 <read_uint32@plt>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     11de <read_attr+0xae>
lea    -0x28(%rbp),%rdi
call   1030 <read_uint32@plt>
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1203 <read_attr+0xd3>
lea    -0x2c(%rbp),%rdi
call   1030 <read_uint32@plt>
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     1228 <read_attr+0xf8>
lea    -0x30(%rbp),%rdi
call   1030 <read_uint32@plt>
mov    -0x30(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     124d <read_attr+0x11d>
lea    -0x34(%rbp),%rdi
call   1030 <read_uint32@plt>
mov    -0x34(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_attr>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1030 <read_uint32@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
je     11ec <read_attr+0xbc>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x0(%rbp),%eax
test   $0x1,%al
je     1179 <read_attr+0x49>
lea    0x1c(%rsp),%rdi
call   1050 <read_uint64@plt>
mov    0x1c(%rsp),%eax
mov    %eax,0x14(%rbx)
mov    0x0(%rbp),%eax
test   $0x2,%al
je     11a8 <read_attr+0x78>
lea    0x18(%rsp),%rdi
call   1030 <read_uint32@plt>
mov    0x18(%rsp),%eax
mov    %eax,(%rbx)
mov    0x0(%rbp),%eax
test   $0x2,%al
je     11a8 <read_attr+0x78>
lea    0x14(%rsp),%rdi
call   1030 <read_uint32@plt>
mov    0x14(%rsp),%eax
mov    %eax,0x4(%rbx)
mov    0x0(%rbp),%eax
test   $0x4,%al
je     11c0 <read_attr+0x90>
lea    0x10(%rsp),%rdi
call   1030 <read_uint32@plt>
mov    0x10(%rsp),%eax
mov    %eax,0x8(%rbx)
mov    0x0(%rbp),%eax
test   $0x8,%al
je     11ec <read_attr+0xbc>
lea    0xc(%rsp),%rdi
call   1030 <read_uint32@plt>
mov    0xc(%rsp),%eax
mov    %eax,0xc(%rbx)
testb  $0x8,0x0(%rbp)
je     11ec <read_attr+0xbc>
lea    0x8(%rsp),%rdi
call   1030 <read_uint32@plt>
mov    0x8(%rsp),%eax
mov    %eax,0x10(%rbx)
mov    %r14d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32, i32, i32, i32 }
define i32 @read_attr(i32* %0, %struct.stat* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %struct.stat*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %4
store %struct.stat* %1, %struct.stat** %5
%13 = load i32*, i32** %4
%14 = call i32 @read_uint32(i32* %13)
store i32 %14, i32* %6
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = load i32, i32* %6
store i32 %17, i32* %3
br label %82
18: ; preds = %2
%19 = load %struct.stat*, %struct.stat** %5
%20 = call i32 @memset(%struct.stat* %19, i32 0, i32 24)
%21 = load i32*, i32** %4
%22 = load i32, i32* %21
%23 = and i32 %22, 1
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = call i32 @read_uint64(i32* %7)
%27 = load i32, i32* %7
%28 = load %struct.stat*, %struct.stat** %5
%29 = getelementptr inbounds %struct.stat, %struct.stat* %28, i32 0, i32 5
store i32 %27, i32* %29
br label %30
30: ; preds = %25, %18
%31 = load i32*, i32** %4
%32 = load i32, i32* %31
%33 = and i32 %32, 2
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = call i32 @read_uint32(i32* %8)
%37 = load i32, i32* %8
%38 = load %struct.stat*, %struct.stat** %5
%39 = getelementptr inbounds %struct.stat, %struct.stat* %38, i32 0, i32 0
store i32 %37, i32* %39
br label %40
40: ; preds = %35, %30
%41 = load i32*, i32** %4
%42 = load i32, i32* %41
%43 = and i32 %42, 2
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %40
%46 = call i32 @read_uint32(i32* %9)
%47 = load i32, i32* %9
%48 = load %struct.stat*, %struct.stat** %5
%49 = getelementptr inbounds %struct.stat, %struct.stat* %48, i32 0, i32 1
store i32 %47, i32* %49
br label %50
50: ; preds = %45, %40
%51 = load i32*, i32** %4
%52 = load i32, i32* %51
%53 = and i32 %52, 4
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %60
55: ; preds = %50
%56 = call i32 @read_uint32(i32* %10)
%57 = load i32, i32* %10
%58 = load %struct.stat*, %struct.stat** %5
%59 = getelementptr inbounds %struct.stat, %struct.stat* %58, i32 0, i32 2
store i32 %57, i32* %59
br label %60
60: ; preds = %55, %50
%61 = load i32*, i32** %4
%62 = load i32, i32* %61
%63 = and i32 %62, 8
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %60
%66 = call i32 @read_uint32(i32* %11)
%67 = load i32, i32* %11
%68 = load %struct.stat*, %struct.stat** %5
%69 = getelementptr inbounds %struct.stat, %struct.stat* %68, i32 0, i32 3
store i32 %67, i32* %69
br label %70
70: ; preds = %65, %60
%71 = load i32*, i32** %4
%72 = load i32, i32* %71
%73 = and i32 %72, 8
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %80
75: ; preds = %70
%76 = call i32 @read_uint32(i32* %12)
%77 = load i32, i32* %12
%78 = load %struct.stat*, %struct.stat** %5
%79 = getelementptr inbounds %struct.stat, %struct.stat* %78, i32 0, i32 4
store i32 %77, i32* %79
br label %80
80: ; preds = %75, %70
%81 = load i32, i32* %6
store i32 %81, i32* %3
br label %82
82: ; preds = %80, %16
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32, i32, i32, i32 }
define i32 @read_attr(i32* %0, %struct.stat* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = bitcast i32* %7 to i8*
%14 = bitcast i32* %8 to i8*
%15 = tail call i32 @read_uint32(i32* %0)
%16 = icmp eq i32 %15, -1
br i1 %16, label %67, label %17
17: ; preds = %2
%18 = tail call i32 @memset(%struct.stat* %1, i32 0, i32 24)
%19 = load i32, i32* %0
%20 = and i32 %19, 1
%21 = icmp eq i32 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %17
%23 = call i32 @read_uint64(i32* %3)
%24 = load i32, i32* %3
%25 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 5
store i32 %24, i32* %25
%26 = load i32, i32* %0
br label %27
27: ; preds = %22, %17
%28 = phi i32 [ %26, %22 ], [ %19, %17 ]
%29 = and i32 %28, 2
%30 = icmp eq i32 %29, 0
br i1 %30, label %43, label %31
31: ; preds = %27
%32 = call i32 @read_uint32(i32* %4)
%33 = load i32, i32* %4
%34 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
store i32 %33, i32* %34
%35 = load i32, i32* %0
%36 = and i32 %35, 2
%37 = icmp eq i32 %36, 0
br i1 %37, label %43, label %38
38: ; preds = %31
%39 = call i32 @read_uint32(i32* %5)
%40 = load i32, i32* %5
%41 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
store i32 %40, i32* %41
%42 = load i32, i32* %0
br label %43
43: ; preds = %27, %38, %31
%44 = phi i32 [ %42, %38 ], [ %35, %31 ], [ %28, %27 ]
%45 = and i32 %44, 4
%46 = icmp eq i32 %45, 0
br i1 %46, label %52, label %47
47: ; preds = %43
%48 = call i32 @read_uint32(i32* %6)
%49 = load i32, i32* %6
%50 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 2
store i32 %49, i32* %50
%51 = load i32, i32* %0
br label %52
52: ; preds = %47, %43
%53 = phi i32 [ %51, %47 ], [ %44, %43 ]
%54 = and i32 %53, 8
%55 = icmp eq i32 %54, 0
br i1 %55, label %67, label %56
56: ; preds = %52
%57 = call i32 @read_uint32(i32* %7)
%58 = load i32, i32* %7
%59 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 3
store i32 %58, i32* %59
%60 = load i32, i32* %0
%61 = and i32 %60, 8
%62 = icmp eq i32 %61, 0
br i1 %62, label %67, label %63
63: ; preds = %56
%64 = call i32 @read_uint32(i32* %8)
%65 = load i32, i32* %8
%66 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 4
store i32 %65, i32* %66
br label %67
67: ; preds = %52, %56, %63, %2
ret i32 %15
}