#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 byte2lendian(unsigned char *);
int /*<<< orphan*/ lendian2byte(int, unsigned char *);
int enc2(int *a1) {
  int i, eax = 3, ecx = 0, edx = 0;
  int v0 = (*a1);
  unsigned char v4[4];
  unsigned char arg0[4] = {0, 0, 0, 0};
  unsigned char al, cl, dl;
  lendian2byte(v0, v4);
  for (i = 1; i <= 32; i++) {
    al = v4[eax];
    cl = arg0[ecx];
    arg0[ecx] = (cl << 1) | (al & 1);
    v4[eax] = al >> 1;
    eax = 3 - i / 8;
    ecx = i % 4;
  }
  *a1 = byte2lendian(arg0);
  return *a1;
}


x86 assembly (clang, -O0):
<enc2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x3,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x24(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1030 <lendian2byte@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0x20,-0xc(%rbp)
jg     11fb <enc2+0xcb>
movslq -0x10(%rbp),%rax
mov    -0x20(%rbp,%rax,1),%al
mov    %al,-0x25(%rbp)
movslq -0x14(%rbp),%rax
mov    -0x24(%rbp,%rax,1),%al
mov    %al,-0x26(%rbp)
movzbl -0x26(%rbp),%eax
shl    $0x1,%eax
movzbl -0x25(%rbp),%ecx
and    $0x1,%ecx
or     %ecx,%eax
mov    %al,%cl
movslq -0x14(%rbp),%rax
mov    %cl,-0x24(%rbp,%rax,1)
movzbl -0x25(%rbp),%eax
sar    $0x1,%eax
mov    %al,%cl
movslq -0x10(%rbp),%rax
mov    %cl,-0x20(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    $0x3,%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117d <enc2+0x4d>
lea    -0x24(%rbp),%rdi
call   1040 <byte2lendian@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enc2>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%edi
movl   $0x0,(%rsp)
lea    0x4(%rsp),%rsi
call   1030 <lendian2byte@plt>
xor    %ecx,%ecx
mov    $0x3,%edx
mov    $0x1,%eax
cs nopw 0x0(%rax,%rax,1)
movslq %edx,%rsi
movzbl 0x4(%rsp,%rsi,1),%edx
mov    %ecx,%edi
movzbl (%rsp,%rdi,1),%ecx
add    %cl,%cl
mov    %edx,%ebx
and    $0x1,%bl
or     %cl,%bl
mov    %bl,(%rsp,%rdi,1)
shr    %dl
mov    %dl,0x4(%rsp,%rsi,1)
mov    %eax,%ecx
shr    $0x3,%ecx
mov    $0x3,%edx
sub    %ecx,%edx
mov    %eax,%ecx
and    $0x3,%ecx
add    $0x1,%eax
cmp    $0x21,%eax
jne    1150 <enc2+0x30>
mov    %rsp,%rdi
call   1040 <byte2lendian@plt>
mov    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @enc2(i32* nocapture %0) {
%2 = alloca [4 x i8]
%3 = alloca i32
%4 = bitcast i32* %3 to [4 x i8]*
%5 = load i32, i32* %0
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%7 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%8 = call i32 @lendian2byte(i32 %5, i8* %6)
br label %9
9: ; preds = %1, %9
%10 = phi i32 [ 1, %1 ], [ %26, %9 ]
%11 = phi i32 [ 3, %1 ], [ %24, %9 ]
%12 = phi i32 [ 0, %1 ], [ %25, %9 ]
%13 = sext i32 %11 to i64
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = zext i32 %12 to i64
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = shl i8 %18, 1
%20 = and i8 %15, 1
%21 = or i8 %19, %20
store i8 %21, i8* %17
%22 = lshr i8 %15, 1
store i8 %22, i8* %14
%23 = lshr i32 %10, 3
%24 = sub nsw i32 3, %23
%25 = and i32 %10, 3
%26 = add nuw nsw i32 %10, 1
%27 = icmp eq i32 %26, 33
br i1 %27, label %28, label %9
28: ; preds = %9
%29 = call i32 @byte2lendian(i8* %7)
store i32 %29, i32* %0
ret i32 %29
}