#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 */
char *_strdup(char const *);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
int rot_k(char *, int const);
int strcmp(char *, char const *);
void TESTROTK(const char *str, const int k, const char *expected,
              const int rc) {
  char *buf = NULL;
  int result = 0;
  int stringCompare = -1;
  int finalResult = 0;
  assert(expected != NULL);
  printf("\n    Test: \"%s\" rotated by %d : \n",
         (str == NULL ? "NULL" : (*str == 0 ? "EMPTY" : str)), k);
  printf("  Expect: \"%s\" returning %d : \n", expected, rc);
  if (str) {
    buf = _strdup(str);
  }
  result = rot_k(buf, k);
  printf("Received: \"%s\" and %d : ", buf, result);
  if (buf) {
    stringCompare = strcmp(buf, expected);
  }
  if ((rc == -1) && (result == -1)) {
    finalResult = 1;
    printf("[OK]");
  } else if ((rc != -1) && (rc == result) && (stringCompare == 0)) {
    finalResult = 1;
    printf("[OK]");
  } else {
    finalResult = 0;
    printf("[FAILED]");
  }
  printf("\n\n");
  {
    if (buf) {
      free(buf);
      buf = NULL;
    }
  };
  assert(finalResult == 1);
}


x86 assembly (clang, -O0):
<TESTROTK>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0xffffffff,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpq   $0x0,-0x8(%rbp)
jne    11c0 <TESTROTK+0x60>
lea    0xe6b(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    11f0 <TESTROTK+0x90>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11e0 <TESTROTK+0x80>
lea    0xe50(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    11e8 <TESTROTK+0x88>
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x8(%rbp)
je     1232 <TESTROTK+0xd2>
mov    -0x8(%rbp),%rdi
call   1080 <_strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <rot_k@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
je     1271 <TESTROTK+0x111>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcmp@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    129f <TESTROTK+0x13f>
cmpl   $0xffffffff,-0x2c(%rbp)
jne    129f <TESTROTK+0x13f>
movl   $0x1,-0x34(%rbp)
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12f3 <TESTROTK+0x193>
cmpl   $0xffffffff,-0x1c(%rbp)
je     12d9 <TESTROTK+0x179>
mov    -0x1c(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jne    12d9 <TESTROTK+0x179>
cmpl   $0x0,-0x30(%rbp)
jne    12d9 <TESTROTK+0x179>
movl   $0x1,-0x34(%rbp)
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ee <TESTROTK+0x18e>
movl   $0x0,-0x34(%rbp)
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12f3 <TESTROTK+0x193>
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
je     131d <TESTROTK+0x1bd>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
cmpl   $0x1,-0x34(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TESTROTK>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%r12
mov    %esi,%r15d
mov    %rdi,%rbx
xor    %edi,%edi
test   %rdx,%rdx
setne  %dil
call   1080 <assert@plt>
test   %rbx,%rbx
je     11d7 <TESTROTK+0x67>
cmpb   $0x0,(%rbx)
lea    0xe86(%rip),%rsi
cmovne %rbx,%rsi
lea    0xe54(%rip),%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe70(%rip),%rdi
mov    %r12,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1090 <_strdup@plt>
mov    %rax,%rbx
jmp    1205 <TESTROTK+0x95>
lea    0xe22(%rip),%rdi
lea    0xe3d(%rip),%rsi
xor    %ebx,%ebx
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe35(%rip),%rdi
mov    %r12,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1060 <rot_k@plt>
mov    %eax,%ebp
lea    0xe34(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
test   %rbx,%rbx
je     1237 <TESTROTK+0xc7>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <strcmp@plt>
jmp    123c <TESTROTK+0xcc>
mov    $0xffffffff,%eax
mov    %ebp,%ecx
and    %r14d,%ecx
mov    $0x1,%r15d
lea    0xe18(%rip),%rdi
cmp    $0xffffffff,%ecx
je     126c <TESTROTK+0xfc>
cmp    $0xffffffff,%r14d
je     1262 <TESTROTK+0xf2>
cmp    %r14d,%ebp
jne    1262 <TESTROTK+0xf2>
test   %eax,%eax
je     126c <TESTROTK+0xfc>
xor    %r15d,%r15d
lea    0xdff(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdd1(%rip),%rdi
call   1040 <puts@plt>
test   %rbx,%rbx
je     128c <TESTROTK+0x11c>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15d,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <assert@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"\0A Test: \22%s\22 rotated by %d : \0A\00"
@.str.1 = [5 x i8] c"NULL\00"
@.str.2 = [6 x i8] c"EMPTY\00"
@.str.3 = [32 x i8] c" Expect: \22%s\22 returning %d : \0A\00"
@.str.4 = [25 x i8] c"Received: \22%s\22 and %d : \00"
@.str.5 = [5 x i8] c"[OK]\00"
@.str.6 = [9 x i8] c"[FAILED]\00"
@.str.7 = [3 x i8] c"\0A\0A\00"
define void @TESTROTK(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i8* null, i8** %9
store i32 0, i32* %10
store i32 -1, i32* %11
store i32 0, i32* %12
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i8*, i8** %5
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %4
br label %30
20: ; preds = %4
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
br label %28
26: ; preds = %20
%27 = load i8*, i8** %5
br label %28
28: ; preds = %26, %25
%29 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %25 ], [ %27, %26 ]
br label %30
30: ; preds = %28, %19
%31 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %19 ], [ %29, %28 ]
%32 = load i32, i32* %6
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %31, i32 %32)
%34 = load i8*, i8** %7
%35 = load i32, i32* %8
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %34, i32 %35)
%37 = load i8*, i8** %5
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %42
39: ; preds = %30
%40 = load i8*, i8** %5
%41 = call i8* @_strdup(i8* %40)
store i8* %41, i8** %9
br label %42
42: ; preds = %39, %30
%43 = load i8*, i8** %9
%44 = load i32, i32* %6
%45 = call i32 @rot_k(i8* %43, i32 %44)
store i32 %45, i32* %10
%46 = load i8*, i8** %9
%47 = load i32, i32* %10
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %46, i32 %47)
%49 = load i8*, i8** %9
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %55
51: ; preds = %42
%52 = load i8*, i8** %9
%53 = load i8*, i8** %7
%54 = call i32 @strcmp(i8* %52, i8* %53)
store i32 %54, i32* %11
br label %55
55: ; preds = %51, %42
%56 = load i32, i32* %8
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %63
58: ; preds = %55
%59 = load i32, i32* %10
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %63
61: ; preds = %58
store i32 1, i32* %12
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %78
63: ; preds = %58, %55
%64 = load i32, i32* %8
%65 = icmp ne i32 %64, -1
br i1 %65, label %66, label %75
66: ; preds = %63
%67 = load i32, i32* %8
%68 = load i32, i32* %10
%69 = icmp eq i32 %67, %68
br i1 %69, label %70, label %75
70: ; preds = %66
%71 = load i32, i32* %11
%72 = icmp eq i32 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %70
store i32 1, i32* %12
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %77
75: ; preds = %70, %66, %63
store i32 0, i32* %12
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %77
77: ; preds = %75, %73
br label %78
78: ; preds = %77, %61
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%80 = load i8*, i8** %9
%81 = icmp ne i8* %80, null
br i1 %81, label %82, label %85
82: ; preds = %78
%83 = load i8*, i8** %9
%84 = call i32 @free(i8* %83)
store i8* null, i8** %9
br label %85
85: ; preds = %82, %78
%86 = load i32, i32* %12
%87 = icmp eq i32 %86, 1
%88 = zext i1 %87 to i32
%89 = call i32 @assert(i32 %88)
ret void
}

LLVM IR (-O2):
@.str = [34 x i8] c"\0A Test: \22%s\22 rotated by %d : \0A\00"
@.str.1 = [5 x i8] c"NULL\00"
@.str.2 = [6 x i8] c"EMPTY\00"
@.str.3 = [32 x i8] c" Expect: \22%s\22 returning %d : \0A\00"
@.str.4 = [25 x i8] c"Received: \22%s\22 and %d : \00"
@.str.5 = [5 x i8] c"[OK]\00"
@.str.6 = [9 x i8] c"[FAILED]\00"
@str = [2 x i8] c"\0A\00"
define void @TESTROTK(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp ne i8* %2, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp eq i8* %0, null
br i1 %8, label %16, label %9
9: ; preds = %4
%10 = load i8, i8* %0
%11 = icmp eq i8 %10, 0
%12 = select i1 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %1)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %2, i32 %3)
%15 = tail call i8* @_strdup(i8* %0)
br label %19
16: ; preds = %4
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %2, i32 %3)
br label %19
19: ; preds = %16, %9
%20 = phi i8* [ %15, %9 ], [ null, %16 ]
%21 = tail call i32 @rot_k(i8* %20, i32 %1)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %20, i32 %21)
%23 = icmp eq i8* %20, null
br i1 %23, label %26, label %24
24: ; preds = %19
%25 = tail call i32 @strcmp(i8* %20, i8* dereferenceable(1) %2)
br label %26
26: ; preds = %24, %19
%27 = phi i32 [ %25, %24 ], [ -1, %19 ]
%28 = and i32 %21, %3
%29 = icmp eq i32 %28, -1
br i1 %29, label %37, label %30
30: ; preds = %26
%31 = icmp eq i32 %3, -1
br i1 %31, label %36, label %32
32: ; preds = %30
%33 = icmp eq i32 %21, %3
%34 = icmp eq i32 %27, 0
%35 = select i1 %33, i1 %34, i1 false
br i1 %35, label %37, label %36
36: ; preds = %32, %30
br label %37
37: ; preds = %32, %26, %36
%38 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), %36 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), %26 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), %32 ]
%39 = phi i32 [ 0, %36 ], [ 1, %26 ], [ 1, %32 ]
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %38)
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br i1 %23, label %44, label %42
42: ; preds = %37
%43 = tail call i32 @free(i8* %20)
br label %44
44: ; preds = %42, %37
%45 = tail call i32 @assert(i32 %39)
ret void
}