#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*/ printf(char *, ...);
int /*<<< orphan*/ right_shift(char *, int, int);
int main(void) {
  int len = 7;
  char str[] = "abcdefg";
  for (int i = -len; i < len + len; i++) {
    printf("shift %d\n", i);
    right_shift(str, len, i);
    printf("%s\n", str);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x7,-0x8(%rbp)
mov    0xec3(%rip),%rax
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    -0x8(%rbp),%ecx
cmp    %ecx,%eax
jge    119a <main+0x7a>
mov    -0x14(%rbp),%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <right_shift@plt>
lea    -0x10(%rbp),%rsi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1149 <main+0x29>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movabs $0x67666564636261,%rax
mov    %rax,0x8(%rsp)
mov    $0xfffffff9,%ebx
lea    0xeac(%rip),%r14
lea    0x8(%rsp),%r15
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    $0x7,%esi
mov    %ebx,%edx
call   1050 <right_shift@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
add    $0x1,%ebx
cmp    $0xe,%ebx
jne    1160 <main+0x30>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.str = [8 x i8] c"abcdefg\00"
@.str = [10 x i8] c"shift %d\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [8 x i8]
%4 = alloca i32
store i32 0, i32* %1
store i32 7, i32* %2
%5 = bitcast [8 x i8]* %3 to i8*
%6 = load i32, i32* %2
%7 = sub nsw i32 0, %6
store i32 %7, i32* %4
br label %8
8: ; preds = %23, %0
%9 = load i32, i32* %4
%10 = load i32, i32* %2
%11 = load i32, i32* %2
%12 = add nsw i32 %10, %11
%13 = icmp slt i32 %9, %12
br i1 %13, label %14, label %26
14: ; preds = %8
%15 = load i32, i32* %4
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%18 = load i32, i32* %2
%19 = load i32, i32* %4
%20 = call i32 @right_shift(i8* %17, i32 %18, i32 %19)
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %14
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %8
26: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"shift %d\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
store i64 29104508263162465, i64* %1
br label %4
3: ; preds = %4
ret i32 0
4: ; preds = %0, %4
%5 = phi i32 [ -7, %0 ], [ %9, %4 ]
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32 @right_shift(i8* %2, i32 7, i32 %5)
%8 = call i32 @puts(i8* %2)
%9 = add nsw i32 %5, 1
%10 = icmp eq i32 %9, 14
br i1 %10, label %3, label %4
}