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

/* Variables and functions */
int u8t32le(int /*<<< orphan*/ *);
void chacha20_init_state(uint32_t s[16], uint8_t key[32], uint32_t counter,
                         uint8_t nonce[12]) {
  int i;
  s[0] = 0x61707865;
  s[1] = 0x3320646e;
  s[2] = 0x79622d32;
  s[3] = 0x6b206574;
  for (i = 0; i < 8; i++) {
    s[4 + i] = u8t32le(key + i * 4);
  }
  s[12] = counter;
  for (i = 0; i < 3; i++) {
    s[13 + i] = u8t32le(nonce + i * 4);
  }
}


x86 assembly (clang, -O0):
<chacha20_init_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x61707865,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x3320646e,0x4(%rax)
mov    -0x8(%rbp),%rax
movl   $0x79622d32,0x8(%rax)
mov    -0x8(%rbp),%rax
movl   $0x6b206574,0xc(%rax)
movl   $0x0,-0x24(%rbp)
cmpl   $0x8,-0x24(%rbp)
jge    119b <chacha20_init_state+0x8b>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%eax
shl    $0x2,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
call   1030 <u8t32le@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x4,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1159 <chacha20_init_state+0x49>
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x30(%rax)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    11ee <chacha20_init_state+0xde>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%eax
shl    $0x2,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
call   1030 <u8t32le@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0xd,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ac <chacha20_init_state+0x9c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chacha20_init_state>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %rdi,%rbx
movaps 0xed6(%rip),%xmm0
movups %xmm0,(%rdi)
mov    %rsi,%rdi
call   1030 <u8t32le@plt>
mov    %eax,0x10(%rbx)
lea    0x10(%rbp),%rdi
call   1030 <u8t32le@plt>
mov    %eax,0x14(%rbx)
lea    0x20(%rbp),%rdi
call   1030 <u8t32le@plt>
mov    %eax,0x18(%rbx)
lea    0x30(%rbp),%rdi
call   1030 <u8t32le@plt>
mov    %eax,0x1c(%rbx)
lea    0x40(%rbp),%rdi
call   1030 <u8t32le@plt>
mov    %eax,0x20(%rbx)
lea    0x50(%rbp),%rdi
call   1030 <u8t32le@plt>
mov    %eax,0x24(%rbx)
lea    0x60(%rbp),%rdi
call   1030 <u8t32le@plt>
mov    %eax,0x28(%rbx)
add    $0x70,%rbp
mov    %rbp,%rdi
call   1030 <u8t32le@plt>
mov    %eax,0x2c(%rbx)
mov    %r15d,0x30(%rbx)
mov    %r14,%rdi
call   1030 <u8t32le@plt>
mov    %eax,0x34(%rbx)
lea    0x10(%r14),%rdi
call   1030 <u8t32le@plt>
mov    %eax,0x38(%rbx)
add    $0x20,%r14
mov    %r14,%rdi
call   1030 <u8t32le@plt>
mov    %eax,0x3c(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @chacha20_init_state(i32* %0, i32* %1, i32 %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%10 = load i32*, i32** %5
%11 = getelementptr inbounds i32, i32* %10, i64 0
store i32 1634760805, i32* %11
%12 = load i32*, i32** %5
%13 = getelementptr inbounds i32, i32* %12, i64 1
store i32 857760878, i32* %13
%14 = load i32*, i32** %5
%15 = getelementptr inbounds i32, i32* %14, i64 2
store i32 2036477234, i32* %15
%16 = load i32*, i32** %5
%17 = getelementptr inbounds i32, i32* %16, i64 3
store i32 1797285236, i32* %17
store i32 0, i32* %9
br label %18
18: ; preds = %33, %4
%19 = load i32, i32* %9
%20 = icmp slt i32 %19, 8
br i1 %20, label %21, label %36
21: ; preds = %18
%22 = load i32*, i32** %6
%23 = load i32, i32* %9
%24 = mul nsw i32 %23, 4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %22, i64 %25
%27 = call i32 @u8t32le(i32* %26)
%28 = load i32*, i32** %5
%29 = load i32, i32* %9
%30 = add nsw i32 4, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %28, i64 %31
store i32 %27, i32* %32
br label %33
33: ; preds = %21
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %18
36: ; preds = %18
%37 = load i32, i32* %7
%38 = load i32*, i32** %5
%39 = getelementptr inbounds i32, i32* %38, i64 12
store i32 %37, i32* %39
store i32 0, i32* %9
br label %40
40: ; preds = %55, %36
%41 = load i32, i32* %9
%42 = icmp slt i32 %41, 3
br i1 %42, label %43, label %58
43: ; preds = %40
%44 = load i32*, i32** %8
%45 = load i32, i32* %9
%46 = mul nsw i32 %45, 4
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %44, i64 %47
%49 = call i32 @u8t32le(i32* %48)
%50 = load i32*, i32** %5
%51 = load i32, i32* %9
%52 = add nsw i32 13, %51
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %50, i64 %53
store i32 %49, i32* %54
br label %55
55: ; preds = %43
%56 = load i32, i32* %9
%57 = add nsw i32 %56, 1
store i32 %57, i32* %9
br label %40
58: ; preds = %40
ret void
}

LLVM IR (-O2):
define void @chacha20_init_state(i32* nocapture writeonly %0, i32* %1, i32 %2, i32* %3) {
%5 = bitcast i32* %0 to <4 x i32>*
store <4 x i32> <i32 1634760805, i32 857760878, i32 2036477234, i32 1797285236>, <4 x i32>* %5
%6 = tail call i32 @u8t32le(i32* %1)
%7 = getelementptr inbounds i32, i32* %0, i64 4
store i32 %6, i32* %7
%8 = getelementptr inbounds i32, i32* %1, i64 4
%9 = tail call i32 @u8t32le(i32* %8)
%10 = getelementptr inbounds i32, i32* %0, i64 5
store i32 %9, i32* %10
%11 = getelementptr inbounds i32, i32* %1, i64 8
%12 = tail call i32 @u8t32le(i32* %11)
%13 = getelementptr inbounds i32, i32* %0, i64 6
store i32 %12, i32* %13
%14 = getelementptr inbounds i32, i32* %1, i64 12
%15 = tail call i32 @u8t32le(i32* %14)
%16 = getelementptr inbounds i32, i32* %0, i64 7
store i32 %15, i32* %16
%17 = getelementptr inbounds i32, i32* %1, i64 16
%18 = tail call i32 @u8t32le(i32* %17)
%19 = getelementptr inbounds i32, i32* %0, i64 8
store i32 %18, i32* %19
%20 = getelementptr inbounds i32, i32* %1, i64 20
%21 = tail call i32 @u8t32le(i32* %20)
%22 = getelementptr inbounds i32, i32* %0, i64 9
store i32 %21, i32* %22
%23 = getelementptr inbounds i32, i32* %1, i64 24
%24 = tail call i32 @u8t32le(i32* %23)
%25 = getelementptr inbounds i32, i32* %0, i64 10
store i32 %24, i32* %25
%26 = getelementptr inbounds i32, i32* %1, i64 28
%27 = tail call i32 @u8t32le(i32* %26)
%28 = getelementptr inbounds i32, i32* %0, i64 11
store i32 %27, i32* %28
%29 = getelementptr inbounds i32, i32* %0, i64 12
store i32 %2, i32* %29
%30 = tail call i32 @u8t32le(i32* %3)
%31 = getelementptr inbounds i32, i32* %0, i64 13
store i32 %30, i32* %31
%32 = getelementptr inbounds i32, i32* %3, i64 4
%33 = tail call i32 @u8t32le(i32* %32)
%34 = getelementptr inbounds i32, i32* %0, i64 14
store i32 %33, i32* %34
%35 = getelementptr inbounds i32, i32* %3, i64 8
%36 = tail call i32 @u8t32le(i32* %35)
%37 = getelementptr inbounds i32, i32* %0, i64 15
store i32 %36, i32* %37
ret void
}