#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 *array2StringInt(int *, int);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ free(char *);
char *nthRank(char *, int *, int);
int /*<<< orphan*/ printf(char *, char *, char *, ...);
scalar_t__ strcmp(char *, char *);
void dotest(char *st, int *we, int n, int szarray, char *sexpr) {
  char *sact = nthRank(st, we, n);
  char *sarr = array2StringInt(we, szarray);
  printf("st: %s / we: %s / nth: %d Expected: %s\n", st, sarr, n, sexpr);
  if (strcmp(sact, sexpr) != 0)
    printf("Error. Expected %s but got %s\n", sexpr, sact);
  assert(strcmp(sact, sexpr) == 0);
  free(sarr);
  sarr = NULL;
}


x86 assembly (clang, -O0):
<dotest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <nthRank@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1040 <array2StringInt@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%r8
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     11e8 <dotest+0x88>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dotest>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r12
mov    %ecx,%r14d
mov    %edx,%r13d
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1050 <nthRank@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <array2StringInt@plt>
mov    %rax,%r14
lea    0xe69(%rip),%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
mov    %r13d,%ecx
mov    %r12,%r8
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11ce <dotest+0x6e>
lea    0xe67(%rip),%rdi
mov    %r12,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [40 x i8] c"st: %s / we: %s / nth: %d Expected: %s\0A\00"
@.str.1 = [31 x i8] c"Error. Expected %s but got %s\0A\00"
define void @dotest(i8* %0, i32* %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%13 = load i8*, i8** %6
%14 = load i32*, i32** %7
%15 = load i32, i32* %8
%16 = call i8* @nthRank(i8* %13, i32* %14, i32 %15)
store i8* %16, i8** %11
%17 = load i32*, i32** %7
%18 = load i32, i32* %9
%19 = call i8* @array2StringInt(i32* %17, i32 %18)
store i8* %19, i8** %12
%20 = load i8*, i8** %6
%21 = load i8*, i8** %12
%22 = load i32, i32* %8
%23 = load i8*, i8** %10
%24 = call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %21, i32 %22, i8* %23)
%25 = load i8*, i8** %11
%26 = load i8*, i8** %10
%27 = call i64 @strcmp(i8* %25, i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %5
%30 = load i8*, i8** %10
%31 = load i8*, i8** %11
%32 = call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %31)
br label %33
33: ; preds = %29, %5
%34 = load i8*, i8** %11
%35 = load i8*, i8** %10
%36 = call i64 @strcmp(i8* %34, i8* %35)
%37 = icmp eq i64 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = load i8*, i8** %12
%41 = call i32 @free(i8* %40)
store i8* null, i8** %12
ret void
}

LLVM IR (-O2):
@.str = [40 x i8] c"st: %s / we: %s / nth: %d Expected: %s\0A\00"
@.str.1 = [31 x i8] c"Error. Expected %s but got %s\0A\00"
define void @dotest(i8* %0, i32* %1, i32 %2, i32 %3, i8* %4) {
%6 = tail call i8* @nthRank(i8* %0, i32* %1, i32 %2)
%7 = tail call i8* @array2StringInt(i32* %1, i32 %3)
%8 = tail call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %7, i32 %2, i8* %4)
%9 = tail call i64 @strcmp(i8* %6, i8* %4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %5
%12 = tail call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %6)
br label %13
13: ; preds = %11, %5
%14 = tail call i64 @strcmp(i8* %6, i8* %4)
%15 = icmp eq i64 %14, 0
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = tail call i32 @free(i8* %7)
ret void
}