#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 atoi(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ reverse(char *, int, int);
int strlen(char *);
int main(int argc, char **argv) {
  if (argc < 3)
    return (0);
  int k = atoi(argv[2]);
  int l = strlen(argv[1]);
  if (k %= l) {
    reverse(argv[1], 0, k - 1);
    reverse(argv[1], k, l - 1);
    reverse(argv[1], 0, l - 1);
  }
  printf("%s\n", argv[1]);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    116c <main+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    11fc <main+0xbc>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
cmp    $0x0,%edx
je     11e1 <main+0xa1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <reverse@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
call   1030 <reverse@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <reverse@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe10(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
cmp    $0x3,%edi
jl     11b0 <main+0x70>
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
mov    0x8(%rbx),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14d,%eax
cltd
idiv   %ebp
test   %edx,%edx
je     119c <main+0x5c>
mov    %edx,%r14d
mov    0x8(%rbx),%rdi
add    $0xffffffff,%edx
xor    %esi,%esi
call   1030 <reverse@plt>
mov    0x8(%rbx),%rdi
add    $0xffffffff,%ebp
mov    %r14d,%esi
mov    %ebp,%edx
call   1030 <reverse@plt>
mov    0x8(%rbx),%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1030 <reverse@plt>
mov    0x8(%rbx),%rsi
lea    0xe59(%rip),%rdi
call   1050 <printf@plt>
pop    %rbx
pop    %r14
pop    %rbp
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %3
br label %49
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 2
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %6
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = load i32, i32* %6
%22 = srem i32 %21, %20
store i32 %22, i32* %6
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %44
24: ; preds = %11
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i32, i32* %6
%29 = sub nsw i32 %28, 1
%30 = call i32 @reverse(i8* %27, i32 0, i32 %29)
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = sub nsw i32 %35, 1
%37 = call i32 @reverse(i8* %33, i32 %34, i32 %36)
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = load i32, i32* %7
%42 = sub nsw i32 %41, 1
%43 = call i32 @reverse(i8* %40, i32 0, i32 %42)
br label %44
44: ; preds = %24, %11
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %47)
store i32 0, i32* %3
br label %49
49: ; preds = %44, %10
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %25, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 2
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strlen(i8* %9)
%11 = srem i32 %7, %10
%12 = icmp eq i32 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %4
%14 = load i8*, i8** %8
%15 = add nsw i32 %11, -1
%16 = tail call i32 @reverse(i8* %14, i32 0, i32 %15)
%17 = load i8*, i8** %8
%18 = add nsw i32 %10, -1
%19 = tail call i32 @reverse(i8* %17, i32 %11, i32 %18)
%20 = load i8*, i8** %8
%21 = tail call i32 @reverse(i8* %20, i32 0, i32 %18)
br label %22
22: ; preds = %13, %4
%23 = load i8*, i8** %8
%24 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %2, %22
ret i32 0
}