#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ hex_dump(void *, size_t);
int /*<<< orphan*/ memset(void *, int, int);
int /*<<< orphan*/ populate_FP_state();
scalar_t__ posix_memalign(void **, int, size_t);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ xsaveopt_64(int, int, void *);
int main() {
  uint32_t edx = 0x0;
  uint32_t eax = 0x7;
  size_t xsave_area_size = 832;
  void *xsave_area;
  if (posix_memalign(&xsave_area, 64, xsave_area_size))
    return 1;
  memset(xsave_area, 0x00, 832);
  printf("\nDumping the contents of the xsave_area prior to saving (should "
         "have every byte set to 0x11):\n");
  hex_dump(xsave_area, xsave_area_size);
  printf("\nPopulating fp registers and calling xsaveopt with edx:eax=0x%x:%x, "
         "xsave_area addr=0x%p\n",
         edx, eax, xsave_area);
  populate_FP_state();
  xsaveopt_64(edx, eax, xsave_area);
  printf("\nDumping the contents of the xsave_area:\n");
  hex_dump(xsave_area, xsave_area_size);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x7,-0xc(%rbp)
movq   $0x340,-0x18(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rdi
mov    $0x40,%esi
call   1070 <posix_memalign@plt>
cmp    $0x0,%rax
je     11ad <main+0x4d>
movl   $0x1,-0x4(%rbp)
jmp    1221 <main+0xc1>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x340,%edx
call   1050 <memset@plt>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <hex_dump@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <populate_FP_state@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1060 <xsaveopt_64@plt>
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <hex_dump@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
mov    $0x340,%edx
mov    $0x40,%esi
call   1080 <posix_memalign@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    120e <main+0x9e>
mov    0x8(%rsp),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x340,%edx
call   1060 <memset@plt>
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rdi
mov    $0x340,%esi
call   1090 <hex_dump@plt>
mov    0x8(%rsp),%rcx
lea    0xe33(%rip),%rdi
xor    %esi,%esi
mov    $0x7,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <populate_FP_state@plt>
mov    0x8(%rsp),%rdx
xor    %edi,%edi
mov    $0x7,%esi
call   1070 <xsaveopt_64@plt>
lea    0xebe(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rdi
mov    $0x340,%esi
call   1090 <hex_dump@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [95 x i8] c"\0ADumping the contents of the xsave_area prior to saving (should have every byte set to 0x11):\0A\00"
@.str.1 = [90 x i8] c"\0APopulating fp registers and calling xsaveopt with edx:eax=0x%x:%x, xsave_area addr=0x%p\0A\00"
@.str.2 = [42 x i8] c"\0ADumping the contents of the xsave_area:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %2
store i32 7, i32* %3
store i64 832, i64* %4
%6 = load i64, i64* %4
%7 = call i64 @posix_memalign(i8** %5, i32 64, i64 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 1, i32* %1
br label %30
10: ; preds = %0
%11 = load i8*, i8** %5
%12 = call i32 @memset(i8* %11, i32 0, i32 832)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([95 x i8], [95 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** %5
%15 = load i64, i64* %4
%16 = call i32 @hex_dump(i8* %14, i64 %15)
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = load i8*, i8** %5
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18, i8* %19)
%21 = call i32 (...) @populate_FP_state()
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = load i8*, i8** %5
%25 = call i32 @xsaveopt_64(i32 %22, i32 %23, i8* %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%27 = load i8*, i8** %5
%28 = load i64, i64* %4
%29 = call i32 @hex_dump(i8* %27, i64 %28)
br label %30
30: ; preds = %10, %9
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str.1 = [90 x i8] c"\0APopulating fp registers and calling xsaveopt with edx:eax=0x%x:%x, xsave_area addr=0x%p\0A\00"
@str = [94 x i8] c"\0ADumping the contents of the xsave_area prior to saving (should have every byte set to 0x11):\00"
@str.3 = [41 x i8] c"\0ADumping the contents of the xsave_area:\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = call i64 @posix_memalign(i8** %1, i32 64, i64 832)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %19
5: ; preds = %0
%6 = load i8*, i8** %1
%7 = call i32 @memset(i8* %6, i32 0, i32 832)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([94 x i8], [94 x i8]* @str, i64 0, i64 0))
%9 = load i8*, i8** %1
%10 = call i32 @hex_dump(i8* %9, i64 832)
%11 = load i8*, i8** %1
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([90 x i8], [90 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 7, i8* %11)
%13 = call i32 (...) @populate_FP_state()
%14 = load i8*, i8** %1
%15 = call i32 @xsaveopt_64(i32 0, i32 7, i8* %14)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.3, i64 0, i64 0))
%17 = load i8*, i8** %1
%18 = call i32 @hex_dump(i8* %17, i64 832)
br label %19
19: ; preds = %0, %5
%20 = phi i32 [ 0, %5 ], [ 1, %0 ]
ret i32 %20
}