#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 */
unsigned char *calloc(int, int);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
void inv_shift_row(unsigned char *instring) {
  unsigned char *buf;
  buf = calloc(16, sizeof(unsigned char));
  for (int i = 0; i < 4; i++) {
    buf[(4 * i)] = instring[(4 * i)];
    buf[(4 * i) + 1] = instring[((4 * i) + 1 + 12) % 16];
    buf[(4 * i) + 2] = instring[((4 * i) + 2 + 8) % 16];
    buf[(4 * i) + 3] = instring[((4 * i) + 3 + 4) % 16];
  }
  memcpy(instring, buf, 16);
  free(buf);
}


x86 assembly (clang, -O0):
<inv_shift_row>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x10,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    1239 <inv_shift_row+0x109>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x2,%eax
add    $0x1,%eax
add    $0xc,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    -0x30(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x2,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x2,%eax
add    $0x2,%eax
add    $0x8,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    -0x28(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x2,%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x2,%eax
add    $0x3,%eax
add    $0x4,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x2,%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1156 <inv_shift_row+0x26>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inv_shift_row>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x10,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
movdqu (%r14),%xmm0
pxor   %xmm1,%xmm1
movdqa %xmm0,%xmm2
punpcklbw %xmm1,%xmm2
movdqa 0xe9e(%rip),%xmm3
movdqa %xmm3,%xmm4
pandn  %xmm2,%xmm4
punpckhbw %xmm1,%xmm0
movdqa %xmm3,%xmm1
pandn  %xmm0,%xmm1
pand   %xmm3,%xmm0
por    %xmm4,%xmm0
pshuflw $0xd8,%xmm0,%xmm0
pshufhw $0xd8,%xmm0,%xmm0
pshufd $0x6c,%xmm0,%xmm0
pshuflw $0xd8,%xmm0,%xmm0
pshufhw $0xd8,%xmm0,%xmm0
pand   %xmm3,%xmm2
por    %xmm1,%xmm2
pshuflw $0xd8,%xmm2,%xmm1
pshufhw $0xd8,%xmm1,%xmm1
pshufd $0x6c,%xmm1,%xmm1
pshuflw $0xd8,%xmm1,%xmm1
pshufhw $0xd8,%xmm1,%xmm1
packuswb %xmm0,%xmm1
movdqu %xmm1,(%rax)
mov    %r14,%rdi
mov    %rax,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

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

LLVM IR (-O2):
define void @inv_shift_row(i8* %0) {
%2 = tail call dereferenceable_or_null(16) i8* @calloc(i32 16, i32 1)
%3 = bitcast i8* %0 to <16 x i8>*
%4 = load <16 x i8>, <16 x i8>* %3
%5 = shufflevector <16 x i8> %4, <16 x i8> poison, <16 x i32> <i32 0, i32 13, i32 10, i32 7, i32 4, i32 1, i32 14, i32 11, i32 8, i32 5, i32 2, i32 15, i32 12, i32 9, i32 6, i32 3>
%6 = bitcast i8* %2 to <16 x i8>*
store <16 x i8> %5, <16 x i8>* %6
%7 = tail call i32 @memcpy(i8* %0, i8* %2, i32 16)
%8 = tail call i32 @free(i8* %2)
ret void
}