#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 */
void set_ctr(int mode, void *iv) {
  uint32_t *_iv = (uint32_t *)iv;
  *((volatile uint32_t *)0x10009000) =
      (*((volatile uint32_t *)0x10009000) & ~(0x00800000 | 0x02000000)) |
      (mode << 23);
  if (mode & 4) {
    *(((volatile uint32_t *)0x10009020) + 0) = _iv[3];
    *(((volatile uint32_t *)0x10009020) + 1) = _iv[2];
    *(((volatile uint32_t *)0x10009020) + 2) = _iv[1];
    *(((volatile uint32_t *)0x10009020) + 3) = _iv[0];
  } else {
    *(((volatile uint32_t *)0x10009020) + 0) = _iv[0];
    *(((volatile uint32_t *)0x10009020) + 1) = _iv[1];
    *(((volatile uint32_t *)0x10009020) + 2) = _iv[2];
    *(((volatile uint32_t *)0x10009020) + 3) = _iv[3];
  }
}


x86 assembly (clang, -O0):
<set_ctr>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x10009000,%eax
mov    (%rax),%ecx
and    $0xfd7fffff,%ecx
mov    -0x4(%rbp),%eax
shl    $0x17,%eax
or     %eax,%ecx
mov    $0x10009000,%eax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     117d <set_ctr+0x7d>
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%ecx
mov    $0x10009020,%eax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%ecx
mov    $0x10009020,%eax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
mov    $0x10009020,%eax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    $0x10009020,%eax
mov    %ecx,0xc(%rax)
jmp    11b7 <set_ctr+0xb7>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    $0x10009020,%eax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
mov    $0x10009020,%eax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%ecx
mov    $0x10009020,%eax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%ecx
mov    $0x10009020,%eax
mov    %ecx,0xc(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_ctr>:
mov    $0xfd7fffff,%eax
and    0x10009000,%eax
mov    %edi,%ecx
shl    $0x17,%ecx
or     %eax,%ecx
mov    %ecx,0x10009000
test   $0x4,%dil
jne    1143 <set_ctr+0x43>
mov    (%rsi),%eax
mov    %eax,0x10009020
mov    0x4(%rsi),%eax
mov    %eax,0x10009024
mov    0x8(%rsi),%eax
mov    %eax,0x10009028
add    $0xc,%rsi
jmp    1161 <set_ctr+0x61>
mov    0xc(%rsi),%eax
mov    %eax,0x10009020
mov    0x8(%rsi),%eax
mov    %eax,0x10009024
mov    0x4(%rsi),%eax
mov    %eax,0x10009028
mov    (%rsi),%eax
mov    %eax,0x1000902c
ret

LLVM IR (-O0):
define void @set_ctr(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = bitcast i8* %6 to i32*
store i32* %7, i32** %5
%8 = load volatile i32, i32* inttoptr (i64 268472320 to i32*)
%9 = and i32 %8, -41943041
%10 = load i32, i32* %3
%11 = shl i32 %10, 23
%12 = or i32 %9, %11
store volatile i32 %12, i32* inttoptr (i64 268472320 to i32*)
%13 = load i32, i32* %3
%14 = and i32 %13, 4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %2
%17 = load i32*, i32** %5
%18 = getelementptr inbounds i32, i32* %17, i64 3
%19 = load i32, i32* %18
store volatile i32 %19, i32* inttoptr (i64 268472352 to i32*)
%20 = load i32*, i32** %5
%21 = getelementptr inbounds i32, i32* %20, i64 2
%22 = load i32, i32* %21
store volatile i32 %22, i32* getelementptr inbounds (i32, i32* inttoptr (i64 268472352 to i32*), i64 1)
%23 = load i32*, i32** %5
%24 = getelementptr inbounds i32, i32* %23, i64 1
%25 = load i32, i32* %24
store volatile i32 %25, i32* getelementptr inbounds (i32, i32* inttoptr (i64 268472352 to i32*), i64 2)
%26 = load i32*, i32** %5
%27 = getelementptr inbounds i32, i32* %26, i64 0
%28 = load i32, i32* %27
store volatile i32 %28, i32* getelementptr inbounds (i32, i32* inttoptr (i64 268472352 to i32*), i64 3)
br label %42
29: ; preds = %2
%30 = load i32*, i32** %5
%31 = getelementptr inbounds i32, i32* %30, i64 0
%32 = load i32, i32* %31
store volatile i32 %32, i32* inttoptr (i64 268472352 to i32*)
%33 = load i32*, i32** %5
%34 = getelementptr inbounds i32, i32* %33, i64 1
%35 = load i32, i32* %34
store volatile i32 %35, i32* getelementptr inbounds (i32, i32* inttoptr (i64 268472352 to i32*), i64 1)
%36 = load i32*, i32** %5
%37 = getelementptr inbounds i32, i32* %36, i64 2
%38 = load i32, i32* %37
store volatile i32 %38, i32* getelementptr inbounds (i32, i32* inttoptr (i64 268472352 to i32*), i64 2)
%39 = load i32*, i32** %5
%40 = getelementptr inbounds i32, i32* %39, i64 3
%41 = load i32, i32* %40
store volatile i32 %41, i32* getelementptr inbounds (i32, i32* inttoptr (i64 268472352 to i32*), i64 3)
br label %42
42: ; preds = %29, %16
ret void
}

LLVM IR (-O2):
define void @set_ctr(i32 %0, i8* nocapture %1) {
%3 = bitcast i8* %1 to i32*
%4 = load volatile i32, i32* inttoptr (i64 268472320 to i32*)
%5 = and i32 %4, -41943041
%6 = shl i32 %0, 23
%7 = or i32 %5, %6
store volatile i32 %7, i32* inttoptr (i64 268472320 to i32*)
%8 = and i32 %0, 4
%9 = icmp eq i32 %8, 0
br i1 %9, label %20, label %10
10: ; preds = %2
%11 = getelementptr inbounds i8, i8* %1, i64 12
%12 = bitcast i8* %11 to i32*
%13 = load i32, i32* %12
store volatile i32 %13, i32* inttoptr (i64 268472352 to i32*)
%14 = getelementptr inbounds i8, i8* %1, i64 8
%15 = bitcast i8* %14 to i32*
%16 = load i32, i32* %15
store volatile i32 %16, i32* inttoptr (i64 268472356 to i32*)
%17 = getelementptr inbounds i8, i8* %1, i64 4
%18 = bitcast i8* %17 to i32*
%19 = load i32, i32* %18
store volatile i32 %19, i32* inttoptr (i64 268472360 to i32*)
br label %30
20: ; preds = %2
%21 = load i32, i32* %3
store volatile i32 %21, i32* inttoptr (i64 268472352 to i32*)
%22 = getelementptr inbounds i8, i8* %1, i64 4
%23 = bitcast i8* %22 to i32*
%24 = load i32, i32* %23
store volatile i32 %24, i32* inttoptr (i64 268472356 to i32*)
%25 = getelementptr inbounds i8, i8* %1, i64 8
%26 = bitcast i8* %25 to i32*
%27 = load i32, i32* %26
store volatile i32 %27, i32* inttoptr (i64 268472360 to i32*)
%28 = getelementptr inbounds i8, i8* %1, i64 12
%29 = bitcast i8* %28 to i32*
br label %30
30: ; preds = %20, %10
%31 = phi i32* [ %29, %20 ], [ %3, %10 ]
%32 = load i32, i32* %31
store volatile i32 %32, i32* inttoptr (i64 268472364 to i32*)
ret void
}