#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 */

/* Variables and functions */
int /*<<< orphan*/ do_fxrstor(unsigned char *);
int /*<<< orphan*/ do_fxsave(unsigned char *);
int /*<<< orphan*/ do_setup_then_fxsave(unsigned char *);
int /*<<< orphan*/ do_zeroise();
int /*<<< orphan*/ free(unsigned char *);
unsigned char *memalign(int, int);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ show(unsigned char *, int);
int main(int argc, char **argv) {
  unsigned char *buf1 = memalign(16, 512);
  unsigned char *buf2 = memalign(16, 512);
  unsigned char *buf3 = memalign(16, 512);
  int xx = argc > 1;
  printf("Re-run with any arg to suppress least-significant\n"
         "   16 bits of FP numbers\n");
  memset(buf1, 0x55, 512);
  memset(buf2, 0x55, 512);
  memset(buf3, 0x55, 512);
  do_setup_then_fxsave(buf1);
  printf("\nBEFORE\n");
  show(buf1, xx);
  do_zeroise();
  do_fxsave(buf2);
  printf("\nZEROED\n");
  show(buf2, xx);
  do_fxrstor(buf1);
  do_fxsave(buf3);
  printf("\nRESTORED\n");
  show(buf3, xx);
  free(buf1);
  free(buf2);
  free(buf3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x10,%edi
mov    $0x200,%esi
call   1090 <memalign@plt>
mov    %rax,-0x18(%rbp)
mov    $0x10,%edi
mov    $0x200,%esi
call   1090 <memalign@plt>
mov    %rax,-0x20(%rbp)
mov    $0x10,%edi
mov    $0x200,%esi
call   1090 <memalign@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x1,-0x8(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
lea    0xe0b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    $0x55,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    $0x55,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    $0x55,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
call   1080 <do_setup_then_fxsave@plt>
lea    0xe09(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1060 <show@plt>
mov    $0x0,%al
call   1070 <do_zeroise@plt>
mov    -0x20(%rbp),%rdi
call   10b0 <do_fxsave@plt>
lea    0xdea(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1060 <show@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <do_fxrstor@plt>
mov    -0x28(%rbp),%rdi
call   10b0 <do_fxsave@plt>
lea    0xdc9(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1060 <show@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r12d
mov    $0x10,%edi
mov    $0x200,%esi
call   1090 <memalign@plt>
mov    %rax,%rbx
mov    $0x10,%edi
mov    $0x200,%esi
call   1090 <memalign@plt>
mov    %rax,%r14
mov    $0x10,%edi
mov    $0x200,%esi
call   1090 <memalign@plt>
mov    %rax,%r15
xor    %ebp,%ebp
cmp    $0x2,%r12d
setge  %bpl
lea    0xe1e(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0x55,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    %r14,%rdi
mov    $0x55,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    %r15,%rdi
mov    $0x55,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
call   1080 <do_setup_then_fxsave@plt>
lea    0xe1f(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <show@plt>
xor    %eax,%eax
call   1070 <do_zeroise@plt>
mov    %r14,%rdi
call   10b0 <do_fxsave@plt>
lea    0xe02(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1060 <show@plt>
mov    %rbx,%rdi
call   10a0 <do_fxrstor@plt>
mov    %r15,%rdi
call   10b0 <do_fxsave@plt>
lea    0xde4(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
mov    %ebp,%esi
call   1060 <show@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [76 x i8] c"Re-run with any arg to suppress least-significant\0A 16 bits of FP numbers\0A\00"
@.str.1 = [9 x i8] c"\0ABEFORE\0A\00"
@.str.2 = [9 x i8] c"\0AZEROED\0A\00"
@.str.3 = [11 x i8] c"\0ARESTORED\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i8* @memalign(i32 16, i32 512)
store i8* %10, i8** %6
%11 = call i8* @memalign(i32 16, i32 512)
store i8* %11, i8** %7
%12 = call i8* @memalign(i32 16, i32 512)
store i8* %12, i8** %8
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 1
%15 = zext i1 %14 to i32
store i32 %15, i32* %9
%16 = call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %6
%18 = call i32 @memset(i8* %17, i32 85, i32 512)
%19 = load i8*, i8** %7
%20 = call i32 @memset(i8* %19, i32 85, i32 512)
%21 = load i8*, i8** %8
%22 = call i32 @memset(i8* %21, i32 85, i32 512)
%23 = load i8*, i8** %6
%24 = call i32 @do_setup_then_fxsave(i8* %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%26 = load i8*, i8** %6
%27 = load i32, i32* %9
%28 = call i32 @show(i8* %26, i32 %27)
%29 = call i32 (...) @do_zeroise()
%30 = load i8*, i8** %7
%31 = call i32 @do_fxsave(i8* %30)
%32 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%33 = load i8*, i8** %7
%34 = load i32, i32* %9
%35 = call i32 @show(i8* %33, i32 %34)
%36 = load i8*, i8** %6
%37 = call i32 @do_fxrstor(i8* %36)
%38 = load i8*, i8** %8
%39 = call i32 @do_fxsave(i8* %38)
%40 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%41 = load i8*, i8** %8
%42 = load i32, i32* %9
%43 = call i32 @show(i8* %41, i32 %42)
%44 = load i8*, i8** %6
%45 = call i32 @free(i8* %44)
%46 = load i8*, i8** %7
%47 = call i32 @free(i8* %46)
%48 = load i8*, i8** %8
%49 = call i32 @free(i8* %48)
ret i32 0
}

LLVM IR (-O2):
@str = [75 x i8] c"Re-run with any arg to suppress least-significant\0A 16 bits of FP numbers\00"
@str.4 = [8 x i8] c"\0ABEFORE\00"
@str.5 = [8 x i8] c"\0AZEROED\00"
@str.6 = [10 x i8] c"\0ARESTORED\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call align 16 dereferenceable_or_null(512) i8* @memalign(i32 16, i32 512)
%4 = tail call align 16 dereferenceable_or_null(512) i8* @memalign(i32 16, i32 512)
%5 = tail call align 16 dereferenceable_or_null(512) i8* @memalign(i32 16, i32 512)
%6 = icmp sgt i32 %0, 1
%7 = zext i1 %6 to i32
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @memset(i8* %3, i32 85, i32 512)
%10 = tail call i32 @memset(i8* %4, i32 85, i32 512)
%11 = tail call i32 @memset(i8* %5, i32 85, i32 512)
%12 = tail call i32 @do_setup_then_fxsave(i8* %3)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.4, i64 0, i64 0))
%14 = tail call i32 @show(i8* %3, i32 %7)
%15 = tail call i32 (...) @do_zeroise()
%16 = tail call i32 @do_fxsave(i8* %4)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.5, i64 0, i64 0))
%18 = tail call i32 @show(i8* %4, i32 %7)
%19 = tail call i32 @do_fxrstor(i8* %3)
%20 = tail call i32 @do_fxsave(i8* %5)
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.6, i64 0, i64 0))
%22 = tail call i32 @show(i8* %5, i32 %7)
%23 = tail call i32 @free(i8* %3)
%24 = tail call i32 @free(i8* %4)
%25 = tail call i32 @free(i8* %5)
ret i32 0
}