#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned long);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(unsigned char *, char *, unsigned char);
void w_encrypt_data(FILE *fp, unsigned char data[4][4], unsigned int k) {
  int i, j;
  unsigned char tmp;
  unsigned char buff[32];
  unsigned long int addr = 0x04000000 + k * 0x10;
  fprintf(fp, "@%08x\n", addr);
  for (i = 0; i < 4; i++)
    for (j = 0; j < 4; j++) {
      tmp = data[3 - j][i];
      sprintf(buff, "%02x\n", tmp);
      fwrite(buff, 1, 3, fp);
    }
}


x86 assembly (clang, -O0):
<w_encrypt_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
add    $0x4000000,%eax
mov    %eax,%eax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x48(%rbp),%rdx
lea    0xe9d(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    11f6 <w_encrypt_data+0xc6>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    11e3 <w_encrypt_data+0xb3>
mov    -0x10(%rbp),%rax
mov    $0x3,%ecx
sub    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe52(%rip),%rsi
movzbl -0x1d(%rbp),%edx
call   1040 <sprintf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3,%edx
call   1050 <fwrite@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1180 <w_encrypt_data+0x50>
jmp    11e8 <w_encrypt_data+0xb8>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116f <w_encrypt_data+0x3f>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<w_encrypt_data>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
shl    $0x4,%edx
add    $0x4000000,%edx
lea    0xead(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xfffffffffffffffc,%rbx
lea    0xea1(%rip),%r15
mov    %rsp,%r13
nopl   0x0(%rax)
movzbl 0x10(%r14,%rbx,1),%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1040 <sprintf@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x3,%edx
mov    %r12,%rcx
call   1050 <fwrite@plt>
movzbl 0xc(%r14,%rbx,1),%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1040 <sprintf@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x3,%edx
mov    %r12,%rcx
call   1050 <fwrite@plt>
movzbl 0x8(%r14,%rbx,1),%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1040 <sprintf@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x3,%edx
mov    %r12,%rcx
call   1050 <fwrite@plt>
movzbl 0x4(%r14,%rbx,1),%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1040 <sprintf@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x3,%edx
mov    %r12,%rcx
call   1050 <fwrite@plt>
inc    %rbx
jne    1170 <w_encrypt_data+0x40>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"@%08x\0A\00"
@.str.1 = [6 x i8] c"%02x\0A\00"
define void @w_encrypt_data(i32* %0, [4 x i8]* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca [4 x i8]*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca [32 x i8]
%11 = alloca i64
store i32* %0, i32** %4
store [4 x i8]* %1, [4 x i8]** %5
store i32 %2, i32* %6
%12 = load i32, i32* %6
%13 = mul i32 %12, 16
%14 = add i32 67108864, %13
%15 = zext i32 %14 to i64
store i64 %15, i64* %11
%16 = load i32*, i32** %4
%17 = load i64, i64* %11
%18 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %17)
store i32 0, i32* %7
br label %19
19: ; preds = %46, %3
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 4
br i1 %21, label %22, label %49
22: ; preds = %19
store i32 0, i32* %8
br label %23
23: ; preds = %42, %22
%24 = load i32, i32* %8
%25 = icmp slt i32 %24, 4
br i1 %25, label %26, label %45
26: ; preds = %23
%27 = load [4 x i8]*, [4 x i8]** %5
%28 = load i32, i32* %8
%29 = sub nsw i32 3, %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %27, i64 %30
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [4 x i8], [4 x i8]* %31, i64 0, i64 %33
%35 = load i8, i8* %34
store i8 %35, i8* %9
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%37 = load i8, i8* %9
%38 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %37)
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%40 = load i32*, i32** %4
%41 = call i32 @fwrite(i8* %39, i32 1, i32 3, i32* %40)
br label %42
42: ; preds = %26
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %23
45: ; preds = %23
br label %46
46: ; preds = %45
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %19
49: ; preds = %19
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"@%08x\0A\00"
@.str.1 = [6 x i8] c"%02x\0A\00"
define void @w_encrypt_data(i32* nocapture %0, [4 x i8]* nocapture %1, i32 %2) {
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%6 = shl i32 %2, 4
%7 = add i32 %6, 67108864
%8 = zext i32 %7 to i64
%9 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %8)
br label %10
10: ; preds = %3, %10
%11 = phi i64 [ 0, %3 ], [ %28, %10 ]
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 3, i64 %11
%13 = load i8, i8* %12
%14 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %13)
%15 = call i32 @fwrite(i8* %5, i32 1, i32 3, i32* %0)
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 2, i64 %11
%17 = load i8, i8* %16
%18 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %17)
%19 = call i32 @fwrite(i8* %5, i32 1, i32 3, i32* %0)
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 1, i64 %11
%21 = load i8, i8* %20
%22 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %21)
%23 = call i32 @fwrite(i8* %5, i32 1, i32 3, i32* %0)
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 %11
%25 = load i8, i8* %24
%26 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %25)
%27 = call i32 @fwrite(i8* %5, i32 1, i32 3, i32* %0)
%28 = add nuw nsw i64 %11, 1
%29 = icmp eq i64 %28, 4
br i1 %29, label %30, label %10
30: ; preds = %10
ret void
}