#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*/ uint32_t;
typedef int /*<<< orphan*/ new_key;

/* Variables and functions */
int /*<<< orphan*/ get_keys(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ rand();
int /*<<< orphan*/ set_keys(int, int /*<<< orphan*/ *);
void rotate_key(int fd) {
  static int iter;
  static uint32_t new_key[4];
  uint32_t keys[8];
  uint32_t tmp_key[4];
  int i;
  if (iter < 10) {
    if (iter == 0) {
      for (i = 0; i < (sizeof(new_key) / sizeof((new_key)[0])); i++)
        new_key[i] = rand();
    }
    get_keys(fd, keys);
    memcpy(keys + 4, new_key, 16);
    set_keys(fd, keys);
  } else {
    get_keys(fd, keys);
    memcpy(tmp_key, keys + 4, 16);
    memcpy(keys + 4, keys, 16);
    memcpy(keys, tmp_key, 16);
    set_keys(fd, keys);
  }
  if (++iter >= (10 * 2))
    iter = 0;
}


x86 assembly (clang, -O0):
<rotate_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0xa,0x2efe(%rip)
jge    11da <rotate_key+0x9a>
cmpl   $0x0,0x2ef1(%rip)
jne    11a4 <rotate_key+0x64>
movl   $0x0,-0x44(%rbp)
movslq -0x44(%rbp),%rax
cmp    $0x4,%rax
jae    119f <rotate_key+0x5f>
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,%edx
movslq -0x44(%rbp),%rcx
lea    0x2ed2(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    116c <rotate_key+0x2c>
jmp    11a4 <rotate_key+0x64>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1050 <get_keys@plt>
lea    -0x30(%rbp),%rdi
add    $0x10,%rdi
lea    0x2ea1(%rip),%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1040 <set_keys@plt>
jmp    1230 <rotate_key+0xf0>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1050 <get_keys@plt>
lea    -0x40(%rbp),%rdi
lea    -0x30(%rbp),%rsi
add    $0x10,%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
lea    -0x30(%rbp),%rdi
add    $0x10,%rdi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1040 <set_keys@plt>
mov    0x2e1a(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e11(%rip)
cmp    $0x14,%eax
jl     1252 <rotate_key+0x112>
movl   $0x0,0x2dfe(%rip)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rotate_key>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edi,%ebx
mov    0x2efd(%rip),%eax
cmp    $0x9,%eax
jg     11a8 <rotate_key+0x68>
test   %eax,%eax
jne    1190 <rotate_key+0x50>
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,0x2ef7(%rip)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,0x2eee(%rip)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,0x2ee5(%rip)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,0x2edc(%rip)
mov    %rsp,%rsi
mov    %ebx,%edi
call   1050 <get_keys@plt>
lea    0x10(%rsp),%rdi
lea    0x2eba(%rip),%rsi
jmp    11e5 <rotate_key+0xa5>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <get_keys@plt>
lea    0x10(%rsp),%r15
lea    0x20(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
call   1040 <set_keys@plt>
mov    0x2e51(%rip),%eax
lea    0x1(%rax),%ecx
xor    %edx,%edx
cmp    $0x13,%eax
cmovl  %ecx,%edx
mov    %edx,0x2e40(%rip)
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@rotate_key.iter = internal global i32 0
@rotate_key.new_key = internal global [4 x i32] zeroinitializer
define void @rotate_key(i32 %0) {
%2 = alloca i32
%3 = alloca [8 x i32]
%4 = alloca [4 x i32]
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* @rotate_key.iter
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %35
8: ; preds = %1
%9 = load i32, i32* @rotate_key.iter
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %8
store i32 0, i32* %5
br label %12
12: ; preds = %21, %11
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = icmp ult i64 %14, 4
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = call i32 (...) @rand()
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [4 x i32], [4 x i32]* @rotate_key.new_key, i64 0, i64 %19
store i32 %17, i32* %20
br label %21
21: ; preds = %16
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %12
24: ; preds = %12
br label %25
25: ; preds = %24, %8
%26 = load i32, i32* %2
%27 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%28 = call i32 @get_keys(i32 %26, i32* %27)
%29 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%30 = getelementptr inbounds i32, i32* %29, i64 4
%31 = call i32 @memcpy(i32* %30, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @rotate_key.new_key, i64 0, i64 0), i32 16)
%32 = load i32, i32* %2
%33 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%34 = call i32 @set_keys(i32 %32, i32* %33)
br label %53
35: ; preds = %1
%36 = load i32, i32* %2
%37 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%38 = call i32 @get_keys(i32 %36, i32* %37)
%39 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%40 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%41 = getelementptr inbounds i32, i32* %40, i64 4
%42 = call i32 @memcpy(i32* %39, i32* %41, i32 16)
%43 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%44 = getelementptr inbounds i32, i32* %43, i64 4
%45 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%46 = call i32 @memcpy(i32* %44, i32* %45, i32 16)
%47 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%48 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%49 = call i32 @memcpy(i32* %47, i32* %48, i32 16)
%50 = load i32, i32* %2
%51 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%52 = call i32 @set_keys(i32 %50, i32* %51)
br label %53
53: ; preds = %35, %25
%54 = load i32, i32* @rotate_key.iter
%55 = add nsw i32 %54, 1
store i32 %55, i32* @rotate_key.iter
%56 = icmp sge i32 %55, 20
br i1 %56, label %57, label %58
57: ; preds = %53
store i32 0, i32* @rotate_key.iter
br label %58
58: ; preds = %57, %53
ret void
}

LLVM IR (-O2):
@rotate_key.iter = internal unnamed_addr global i32 0
@rotate_key.new_key = internal global [4 x i32] zeroinitializer
define void @rotate_key(i32 %0) {
%2 = alloca [8 x i32]
%3 = alloca [4 x i32]
%4 = bitcast [8 x i32]* %2 to i8*
%5 = bitcast [4 x i32]* %3 to i8*
%6 = load i32, i32* @rotate_key.iter
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %20
8: ; preds = %1
%9 = icmp eq i32 %6, 0
br i1 %9, label %10, label %15
10: ; preds = %8
%11 = tail call i32 (...) @rand()
store i32 %11, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @rotate_key.new_key, i64 0, i64 0)
%12 = tail call i32 (...) @rand()
store i32 %12, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @rotate_key.new_key, i64 0, i64 1)
%13 = tail call i32 (...) @rand()
store i32 %13, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @rotate_key.new_key, i64 0, i64 2)
%14 = tail call i32 (...) @rand()
store i32 %14, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @rotate_key.new_key, i64 0, i64 3)
br label %15
15: ; preds = %10, %8
%16 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 0
%17 = call i32 @get_keys(i32 %0, i32* %16)
%18 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 4
%19 = call i32 @memcpy(i32* %18, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @rotate_key.new_key, i64 0, i64 0), i32 16)
br label %28
20: ; preds = %1
%21 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 0
%22 = call i32 @get_keys(i32 %0, i32* %21)
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%24 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 4
%25 = call i32 @memcpy(i32* %23, i32* %24, i32 16)
%26 = call i32 @memcpy(i32* %24, i32* %21, i32 16)
%27 = call i32 @memcpy(i32* %21, i32* %23, i32 16)
br label %28
28: ; preds = %20, %15
%29 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 0
%30 = call i32 @set_keys(i32 %0, i32* %29)
%31 = load i32, i32* @rotate_key.iter
%32 = add nsw i32 %31, 1
%33 = icmp sgt i32 %31, 18
%34 = select i1 %33, i32 0, i32 %32
store i32 %34, i32* @rotate_key.iter
ret void
}