#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 get_rounding_mode();
int /*<<< orphan*/ printf(char *, unsigned int const);
int /*<<< orphan*/ set_rounding_mode(unsigned int const);
int main(void) {
  int i;
  const unsigned rmodes[] = {0, 1, 2, 3};
  printf("initial rounding mode: %u\n", get_rounding_mode());
  for (i = 0; i < sizeof rmodes / sizeof rmodes[0]; ++i) {
    printf("setting rounding mode to %u\n", rmodes[i]);
    set_rounding_mode(rmodes[i]);
    printf("...checking: %u\n", get_rounding_mode());
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <get_rounding_mode@plt>
mov    %eax,%esi
lea    0xeab(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rax
cmp    $0x4,%rax
jae    11c3 <main+0x93>
movslq -0x8(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
movslq -0x8(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%edi
call   1050 <set_rounding_mode@plt>
mov    $0x0,%al
call   1040 <get_rounding_mode@plt>
mov    %eax,%esi
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1171 <main+0x41>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <get_rounding_mode@plt>
lea    0xebe(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
lea    0xecb(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <set_rounding_mode@plt>
xor    %eax,%eax
call   1040 <get_rounding_mode@plt>
lea    0xec9(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <set_rounding_mode@plt>
xor    %eax,%eax
call   1040 <get_rounding_mode@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1050 <set_rounding_mode@plt>
xor    %eax,%eax
call   1040 <get_rounding_mode@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
mov    $0x3,%edi
call   1050 <set_rounding_mode@plt>
xor    %eax,%eax
call   1040 <get_rounding_mode@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.rmodes = [4 x i32] [i32 0, i32 1, i32 2, i32 3]
@.str = [27 x i8] c"initial rounding mode: %u\0A\00"
@.str.1 = [29 x i8] c"setting rounding mode to %u\0A\00"
@.str.2 = [17 x i8] c"...checking: %u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4 x i32]
store i32 0, i32* %1
%4 = bitcast [4 x i32]* %3 to i8*
%5 = call i32 (...) @get_rounding_mode()
%6 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 0, i32* %2
br label %7
7: ; preds = %24, %0
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = icmp ult i64 %9, 4
br i1 %10, label %11, label %27
11: ; preds = %7
%12 = load i32, i32* %2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = call i32 @set_rounding_mode(i32 %20)
%22 = call i32 (...) @get_rounding_mode()
%23 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %11
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %7
27: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"initial rounding mode: %u\0A\00"
@.str.1 = [29 x i8] c"setting rounding mode to %u\0A\00"
@.str.2 = [17 x i8] c"...checking: %u\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @get_rounding_mode()
%2 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 0)
%4 = tail call i32 @set_rounding_mode(i32 0)
%5 = tail call i32 (...) @get_rounding_mode()
%6 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 1)
%8 = tail call i32 @set_rounding_mode(i32 1)
%9 = tail call i32 (...) @get_rounding_mode()
%10 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 2)
%12 = tail call i32 @set_rounding_mode(i32 2)
%13 = tail call i32 (...) @get_rounding_mode()
%14 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 3)
%16 = tail call i32 @set_rounding_mode(i32 3)
%17 = tail call i32 (...) @get_rounding_mode()
%18 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %17)
ret i32 0
}