#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 uint8_t;

/* Variables and functions */
void shift_rows(uint8_t *state) {
  uint8_t i, k, s, tmp;
  for (i = 1; i < 4; i++) {
    s = 0;
    while (s < i) {
      tmp = state[4 * i + 0];
      for (k = 1; k < 4; k++) {
        state[4 * i + k - 1] = state[4 * i + k];
      }
      state[4 * i + 4 - 1] = tmp;
      s++;
    }
  }
}


x86 assembly (clang, -O0):
<shift_rows>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x4,-0xc(%rbp)
jge    11c4 <shift_rows+0xc4>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b1 <shift_rows+0xb1>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x2,%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    118a <shift_rows+0x8a>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x2,%ecx
add    -0x10(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x2,%ecx
add    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1149 <shift_rows+0x49>
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x2,%ecx
add    $0x4,%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1120 <shift_rows+0x20>
jmp    11b6 <shift_rows+0xb6>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    110f <shift_rows+0xf>
pop    %rbp
ret

x86 assembly (clang, -O2):
<shift_rows>:
movdqu 0x10(%rdi),%xmm0
movdqu 0x20(%rdi),%xmm1
movdqu 0x30(%rdi),%xmm2
pshufd $0x39,%xmm0,%xmm0
movdqu %xmm0,0x10(%rdi)
pshufd $0x4e,%xmm1,%xmm0
movdqu %xmm0,0x20(%rdi)
pshufd $0x93,%xmm2,%xmm0
movdqu %xmm0,0x30(%rdi)
ret

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

LLVM IR (-O2):
define void @shift_rows(i32* nocapture %0) {
%2 = getelementptr inbounds i32, i32* %0, i64 4
%3 = bitcast i32* %2 to <4 x i32>*
%4 = load <4 x i32>, <4 x i32>* %3
%5 = shufflevector <4 x i32> %4, <4 x i32> poison, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
%6 = bitcast i32* %2 to <4 x i32>*
store <4 x i32> %5, <4 x i32>* %6
%7 = getelementptr inbounds i32, i32* %0, i64 8
%8 = bitcast i32* %7 to <4 x i32>*
%9 = load <4 x i32>, <4 x i32>* %8
%10 = shufflevector <4 x i32> %9, <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 0, i32 1>
%11 = bitcast i32* %7 to <4 x i32>*
store <4 x i32> %10, <4 x i32>* %11
%12 = getelementptr inbounds i32, i32* %0, i64 12
%13 = bitcast i32* %12 to <4 x i32>*
%14 = load <4 x i32>, <4 x i32>* %13
%15 = shufflevector <4 x i32> %14, <4 x i32> poison, <4 x i32> <i32 3, i32 0, i32 1, i32 2>
%16 = bitcast i32* %12 to <4 x i32>*
store <4 x i32> %15, <4 x i32>* %16
ret void
}