#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 yc_poly_emulator(char *, char *, unsigned int);
int foo(unsigned int ecx) {
  unsigned i;
  char code[ecx];
  char decryptor_offset[0x32] = {
      0xEB, 0xFE, 0x2,  0x32, 0xEB, 0xFE, 0x2,  0x32, 0xEB, 0xFE,
      0x2,  0x32, 0xEB, 0xFE, 0x2,  0x32, 0xEB, 0xFE, 0x2,  0x32,
      0xEB, 0xFE, 0x2,  0x32, 0xEB, 0xFE, 0x2,  0x32, 0xEB, 0xFE,
      0x2,  0x32, 0xEB, 0xFE, 0x2,  0x32, 0xEB, 0xFE, 0x2,  0x32,
      0xEB, 0xFE, 0x2,  0x32, 0xEB, 0xFE, 0x2,  0x32, 0x3,  0x4};
  volatile int dummy = 0;
  for (i = 0; i < ecx; i++)
    code[i] = dummy;
  return yc_poly_emulator(decryptor_offset, code, ecx);
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xea4(%rip),%rsi
mov    $0x32,%edx
call   1030 <memcpy@plt>
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    119d <foo+0x7d>
mov    -0x60(%rbp),%rax
mov    -0x54(%rbp),%ecx
mov    %cl,%dl
mov    -0x8(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1174 <foo+0x54>
mov    -0x60(%rbp),%rsi
lea    -0x50(%rbp),%rdi
mov    -0x4(%rbp),%edx
call   1040 <yc_poly_emulator@plt>
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,%r8d
mov    %edi,%ecx
mov    %rsp,%rsi
lea    0xf(%rcx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rsi
mov    %rsi,%rsp
movaps 0xeeb(%rip),%xmm0
movaps %xmm0,-0x20(%rbp)
movaps 0xed0(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
movaps 0xeb5(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
movw   $0x403,-0x10(%rbp)
movl   $0x0,-0x4(%rbp)
test   %edi,%edi
je     11bf <foo+0xaf>
lea    -0x1(%rcx),%rdi
mov    %ecx,%eax
and    $0x3,%eax
cmp    $0x3,%rdi
jae    1173 <foo+0x63>
xor    %edi,%edi
jmp    11a4 <foo+0x94>
and    $0xfffffffc,%ecx
xor    %edi,%edi
nopl   0x0(%rax,%rax,1)
mov    -0x4(%rbp),%edx
mov    %dl,(%rsi,%rdi,1)
mov    -0x4(%rbp),%edx
mov    %dl,0x1(%rsi,%rdi,1)
mov    -0x4(%rbp),%edx
mov    %dl,0x2(%rsi,%rdi,1)
mov    -0x4(%rbp),%edx
mov    %dl,0x3(%rsi,%rdi,1)
add    $0x4,%rdi
cmp    %rdi,%rcx
jne    1180 <foo+0x70>
test   %rax,%rax
je     11bf <foo+0xaf>
add    %rsi,%rdi
xor    %ecx,%ecx
xchg   %ax,%ax
mov    -0x4(%rbp),%edx
mov    %dl,(%rdi,%rcx,1)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    11b0 <foo+0xa0>
lea    -0x40(%rbp),%rdi
mov    %r8d,%edx
call   1030 <yc_poly_emulator@plt>
mov    %rbp,%rsp
pop    %rbp
ret

LLVM IR (-O0):
@__const.foo.decryptor_offset = [50 x i8] c"\EB\FE\022\EB\FE\022\EB\FE\022\EB\FE\022\EB\FE\022\EB\FE\022\EB\FE\022\EB\FE\022\EB\FE\022\EB\FE\022\EB\FE\022\EB\FE\022\03\04"
define i32 @foo(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [50 x i8]
%7 = alloca i32
store i32 %0, i32* %2
%8 = load i32, i32* %2
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %4
%11 = alloca i8, i64 %9
store i64 %9, i64* %5
%12 = bitcast [50 x i8]* %6 to i8*
store volatile i32 0, i32* %7
store i32 0, i32* %3
br label %13
13: ; preds = %23, %1
%14 = load i32, i32* %3
%15 = load i32, i32* %2
%16 = icmp ult i32 %14, %15
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = load volatile i32, i32* %7
%19 = trunc i32 %18 to i8
%20 = load i32, i32* %3
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %11, i64 %21
store i8 %19, i8* %22
br label %23
23: ; preds = %17
%24 = load i32, i32* %3
%25 = add i32 %24, 1
store i32 %25, i32* %3
br label %13
26: ; preds = %13
%27 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%28 = load i32, i32* %2
%29 = call i32 @yc_poly_emulator(i8* %27, i8* %11, i32 %28)
%30 = load i8*, i8** %4
ret i32 %29
}

LLVM IR (-O2):
@__const.foo.decryptor_offset = [50 x i8] c"\EB\FE\022\EB\FE\022\EB\FE\022\EB\FE\022\EB\FE\022\EB\FE\022\EB\FE\022\EB\FE\022\EB\FE\022\EB\FE\022\EB\FE\022\EB\FE\022\03\04"
define i32 @foo(i32 %0) {
%2 = alloca [50 x i8]
%3 = alloca i32
%4 = zext i32 %0 to i64
%5 = alloca i8, i64 %4
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%7 = bitcast i32* %3 to i8*
store volatile i32 0, i32* %3
%8 = icmp eq i32 %0, 0
br i1 %8, label %48, label %9
9: ; preds = %1
%10 = add nsw i64 %4, -1
%11 = and i64 %4, 3
%12 = icmp ult i64 %10, 3
br i1 %12, label %36, label %13
13: ; preds = %9
%14 = and i64 %4, 4294967292
br label %15
15: ; preds = %15, %13
%16 = phi i64 [ 0, %13 ], [ %33, %15 ]
%17 = phi i64 [ 0, %13 ], [ %34, %15 ]
%18 = load volatile i32, i32* %3
%19 = trunc i32 %18 to i8
%20 = getelementptr inbounds i8, i8* %5, i64 %16
store i8 %19, i8* %20
%21 = or i64 %16, 1
%22 = load volatile i32, i32* %3
%23 = trunc i32 %22 to i8
%24 = getelementptr inbounds i8, i8* %5, i64 %21
store i8 %23, i8* %24
%25 = or i64 %16, 2
%26 = load volatile i32, i32* %3
%27 = trunc i32 %26 to i8
%28 = getelementptr inbounds i8, i8* %5, i64 %25
store i8 %27, i8* %28
%29 = or i64 %16, 3
%30 = load volatile i32, i32* %3
%31 = trunc i32 %30 to i8
%32 = getelementptr inbounds i8, i8* %5, i64 %29
store i8 %31, i8* %32
%33 = add nuw nsw i64 %16, 4
%34 = add i64 %17, 4
%35 = icmp eq i64 %34, %14
br i1 %35, label %36, label %15
36: ; preds = %15, %9
%37 = phi i64 [ 0, %9 ], [ %33, %15 ]
%38 = icmp eq i64 %11, 0
br i1 %38, label %48, label %39
39: ; preds = %36, %39
%40 = phi i64 [ %45, %39 ], [ %37, %36 ]
%41 = phi i64 [ %46, %39 ], [ 0, %36 ]
%42 = load volatile i32, i32* %3
%43 = trunc i32 %42 to i8
%44 = getelementptr inbounds i8, i8* %5, i64 %40
store i8 %43, i8* %44
%45 = add nuw nsw i64 %40, 1
%46 = add i64 %41, 1
%47 = icmp eq i64 %46, %11
br i1 %47, label %48, label %39
48: ; preds = %36, %39, %1
%49 = call i32 @yc_poly_emulator(i8* %6, i8* %5, i32 %0)
ret i32 %49
}