#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 int shift_transform(unsigned int, int, char *);
unsigned generate(unsigned val, char left, char start_bit) {
  if (left)
    for (int i = 0; i < (int)(sizeof(unsigned) * 8); ++i)
      val = shift_transform(val, i, &start_bit);
  else
    for (int i = (sizeof(unsigned) * 8) - 1; i > -1; --i)
      val = shift_transform(val, i, &start_bit);
  return val;
}


x86 assembly (clang, -O0):
<generate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %edi,-0x4(%rbp)
mov    %cl,-0x5(%rbp)
mov    %al,-0x6(%rbp)
cmpb   $0x0,-0x5(%rbp)
je     1166 <generate+0x56>
movl   $0x0,-0xc(%rbp)
cmpl   $0x20,-0xc(%rbp)
jge    1161 <generate+0x51>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
lea    -0x6(%rbp),%rdx
call   1030 <shift_transform@plt>
mov    %eax,-0x4(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1137 <generate+0x27>
jmp    119c <generate+0x8c>
movl   $0x1f,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jle    1197 <generate+0x87>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
lea    -0x6(%rbp),%rdx
call   1030 <shift_transform@plt>
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    116d <generate+0x5d>
jmp    119c <generate+0x8c>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%eax
mov    %dl,0x7(%rsp)
test   %sil,%sil
je     1146 <generate+0x36>
xor    %ebx,%ebx
lea    0x7(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %eax,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <shift_transform@plt>
add    $0x1,%ebx
cmp    $0x20,%ebx
jne    1130 <generate+0x20>
jmp    1161 <generate+0x51>
mov    $0x1f,%ebx
lea    0x7(%rsp),%r14
mov    %eax,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <shift_transform@plt>
add    $0xffffffff,%ebx
jb     1150 <generate+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @generate(i32 %0, i8 signext %1, i8 signext %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8 %1, i8* %5
store i8 %2, i8* %6
%9 = load i8, i8* %5
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %3
store i32 0, i32* %7
br label %12
12: ; preds = %19, %11
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 32
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i32, i32* %4
%17 = load i32, i32* %7
%18 = call i32 @shift_transform(i32 %16, i32 %17, i8* %6)
store i32 %18, i32* %4
br label %19
19: ; preds = %15
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
store i32 %21, i32* %7
br label %12
22: ; preds = %12
br label %35
23: ; preds = %3
store i32 31, i32* %8
br label %24
24: ; preds = %31, %23
%25 = load i32, i32* %8
%26 = icmp sgt i32 %25, -1
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = load i32, i32* %4
%29 = load i32, i32* %8
%30 = call i32 @shift_transform(i32 %28, i32 %29, i8* %6)
store i32 %30, i32* %4
br label %31
31: ; preds = %27
%32 = load i32, i32* %8
%33 = add nsw i32 %32, -1
store i32 %33, i32* %8
br label %24
34: ; preds = %24
br label %35
35: ; preds = %34, %22
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
define i32 @generate(i32 %0, i8 signext %1, i8 signext %2) {
%4 = alloca i8
store i8 %2, i8* %4
%5 = icmp eq i8 %1, 0
br i1 %5, label %12, label %6
6: ; preds = %3, %6
%7 = phi i32 [ %10, %6 ], [ 0, %3 ]
%8 = phi i32 [ %9, %6 ], [ %0, %3 ]
%9 = call i32 @shift_transform(i32 %8, i32 %7, i8* %4)
%10 = add nuw nsw i32 %7, 1
%11 = icmp eq i32 %10, 32
br i1 %11, label %18, label %6
12: ; preds = %3, %12
%13 = phi i32 [ %16, %12 ], [ 31, %3 ]
%14 = phi i32 [ %15, %12 ], [ %0, %3 ]
%15 = call i32 @shift_transform(i32 %14, i32 %13, i8* %4)
%16 = add nsw i32 %13, -1
%17 = icmp eq i32 %13, 0
br i1 %17, label %18, label %12
18: ; preds = %6, %12
%19 = phi i32 [ %15, %12 ], [ %9, %6 ]
ret i32 %19
}