#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 */
int /*<<< orphan*/ add_to_first(unsigned char *, unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ mul_by_x(unsigned char *);
void mul_by_delta(unsigned char blk[16], unsigned char delta[16]) {
  int i, j;
  int power;
  unsigned char res[16] = {0};
  unsigned char tmp[16];
  memcpy(tmp, blk, 16);
  for (i = 15; i >= 0; i--) {
    power = 1;
    for (j = 0; j < 8; j++) {
      if (delta[i] >= power) {
        add_to_first(res, tmp);
      }
      power = power * 2;
      mul_by_x(tmp);
    }
  }
  memcpy(blk, res, 16);
}


x86 assembly (clang, -O0):
<mul_by_delta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
movl   $0xf,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11f0 <mul_by_delta+0xb0>
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x8,-0x18(%rbp)
jge    11dd <mul_by_delta+0x9d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    -0x1c(%rbp),%eax
jl     11bd <mul_by_delta+0x7d>
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <add_to_first@plt>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
lea    -0x40(%rbp),%rdi
call   1060 <mul_by_x@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1191 <mul_by_delta+0x51>
jmp    11e2 <mul_by_delta+0xa2>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1179 <mul_by_delta+0x39>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mul_by_delta>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r13
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
mov    $0xf,%ebx
mov    %rsp,%r12
jmp    1196 <mul_by_delta+0x66>
nopl   0x0(%rax)
mov    %r15,%rdi
call   1050 <mul_by_x@plt>
cmpb   $0x0,0x0(%r13,%rbx,1)
js     1260 <mul_by_delta+0x130>
mov    %r15,%rdi
call   1050 <mul_by_x@plt>
add    $0xffffffffffffffff,%rbx
jae    1270 <mul_by_delta+0x140>
cmpb   $0x0,0x0(%r13,%rbx,1)
je     11a9 <mul_by_delta+0x79>
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <add_to_first@plt>
mov    %r15,%rdi
call   1050 <mul_by_x@plt>
cmpb   $0x2,0x0(%r13,%rbx,1)
jb     11c4 <mul_by_delta+0x94>
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <add_to_first@plt>
mov    %r15,%rdi
call   1050 <mul_by_x@plt>
cmpb   $0x4,0x0(%r13,%rbx,1)
jb     11df <mul_by_delta+0xaf>
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <add_to_first@plt>
mov    %r15,%rdi
call   1050 <mul_by_x@plt>
cmpb   $0x8,0x0(%r13,%rbx,1)
jb     11fa <mul_by_delta+0xca>
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <add_to_first@plt>
mov    %r15,%rdi
call   1050 <mul_by_x@plt>
cmpb   $0x10,0x0(%r13,%rbx,1)
jb     1215 <mul_by_delta+0xe5>
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <add_to_first@plt>
mov    %r15,%rdi
call   1050 <mul_by_x@plt>
cmpb   $0x20,0x0(%r13,%rbx,1)
jb     1230 <mul_by_delta+0x100>
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <add_to_first@plt>
mov    %r15,%rdi
call   1050 <mul_by_x@plt>
cmpb   $0x40,0x0(%r13,%rbx,1)
jb     1170 <mul_by_delta+0x40>
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <add_to_first@plt>
jmp    1170 <mul_by_delta+0x40>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <add_to_first@plt>
jmp    1184 <mul_by_delta+0x54>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0x10,%edx
call   1030 <memcpy@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @mul_by_delta(i8* %0, i8* nocapture %1) {
%3 = alloca [16 x i8]
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%7 = call i32 @memcpy(i8* %6, i8* %0, i32 16)
br label %8
8: ; preds = %2, %57
%9 = phi i64 [ 15, %2 ], [ %59, %57 ]
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = call i32 @add_to_first(i8* %5, i8* %6)
br label %15
15: ; preds = %13, %8
%16 = call i32 @mul_by_x(i8* %6)
%17 = load i8, i8* %10
%18 = icmp ult i8 %17, 2
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = call i32 @add_to_first(i8* %5, i8* %6)
br label %21
21: ; preds = %19, %15
%22 = call i32 @mul_by_x(i8* %6)
%23 = load i8, i8* %10
%24 = icmp ult i8 %23, 4
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = call i32 @add_to_first(i8* %5, i8* %6)
br label %27
27: ; preds = %25, %21
%28 = call i32 @mul_by_x(i8* %6)
%29 = load i8, i8* %10
%30 = icmp ult i8 %29, 8
br i1 %30, label %33, label %31
31: ; preds = %27
%32 = call i32 @add_to_first(i8* %5, i8* %6)
br label %33
33: ; preds = %31, %27
%34 = call i32 @mul_by_x(i8* %6)
%35 = load i8, i8* %10
%36 = icmp ult i8 %35, 16
br i1 %36, label %39, label %37
37: ; preds = %33
%38 = call i32 @add_to_first(i8* %5, i8* %6)
br label %39
39: ; preds = %37, %33
%40 = call i32 @mul_by_x(i8* %6)
%41 = load i8, i8* %10
%42 = icmp ult i8 %41, 32
br i1 %42, label %45, label %43
43: ; preds = %39
%44 = call i32 @add_to_first(i8* %5, i8* %6)
br label %45
45: ; preds = %43, %39
%46 = call i32 @mul_by_x(i8* %6)
%47 = load i8, i8* %10
%48 = icmp ult i8 %47, 64
br i1 %48, label %51, label %49
49: ; preds = %45
%50 = call i32 @add_to_first(i8* %5, i8* %6)
br label %51
51: ; preds = %49, %45
%52 = call i32 @mul_by_x(i8* %6)
%53 = load i8, i8* %10
%54 = icmp sgt i8 %53, -1
br i1 %54, label %57, label %55
55: ; preds = %51
%56 = call i32 @add_to_first(i8* %5, i8* %6)
br label %57
57: ; preds = %55, %51
%58 = call i32 @mul_by_x(i8* %6)
%59 = add nsw i64 %9, -1
%60 = icmp eq i64 %9, 0
br i1 %60, label %61, label %8
61: ; preds = %57
%62 = call i32 @memcpy(i8* %0, i8* %5, i32 16)
ret void
}