#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 */
struct timeval {
  int tv_usec;
  int tv_sec;
};
struct timespec {
  int tv_nsec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ s;

/* Variables and functions */
int /*<<< orphan*/ extendednameenemy(char *, int);
int /*<<< orphan*/ getint(int *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int magicconsume(int *, int *, int, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ shiftarray(int *);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ srand(int);
void bodyswitch(int *aces, int *inv, int *future, int *map, int *pos,
                int *start, int *control, int *nomag) {
  struct timespec a;
  a.tv_sec = 0;
  a.tv_nsec = 1000;
  nanosleep(&a, NULL);
  struct timeval t1;
  gettimeofday(&t1, NULL);
  srand(t1.tv_usec * t1.tv_sec);
  char s[30];
  memset(s, 0, sizeof(s));
  sprintf(s, "StealingSpirit");
  int v = magicconsume(aces, inv, 7, s);
  if (v < 0)
    return;
  v = -1;
  do {
    printf("What enemy you want to transmute?\n");
    getint(&v);
  } while ((v < 0) || (v > 11));
  if (*(map + v) > 0) {
    int c;
    if (*future >= 0) {
      c = *future;
      shiftarray(future);
    } else
      c = rand() % 54;
    extendednameenemy(s, c);
    printf("The enemy is transmuted into a %s!\n", s);
    *(map + v) = c;
    if (v == *pos) {
      *start = 1;
      *control = 0;
    }
  } else
    printf("Nothing here...\n");
  if (nomag)
    *nomag = 2;
}


x86 assembly (clang, -O0):
<bodyswitch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x3e8,-0x40(%rbp)
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <nanosleep@plt>
lea    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x48(%rbp),%edi
imul   -0x44(%rbp),%edi
call   1090 <srand@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1070 <memset@plt>
lea    -0x70(%rbp),%rdi
lea    0xdd5(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x70(%rbp),%rcx
mov    $0x7,%edx
call   1040 <magicconsume@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
jge    1258 <bodyswitch+0xa8>
jmp    1359 <bodyswitch+0x1a9>
movl   $0xffffffff,-0x74(%rbp)
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x74(%rbp),%rdi
call   1080 <getint@plt>
mov    $0x1,%al
cmpl   $0x0,-0x74(%rbp)
mov    %al,-0x79(%rbp)
jl     128f <bodyswitch+0xdf>
cmpl   $0xb,-0x74(%rbp)
setg   %al
mov    %al,-0x79(%rbp)
mov    -0x79(%rbp),%al
test   $0x1,%al
jne    125f <bodyswitch+0xaf>
mov    -0x20(%rbp),%rax
movslq -0x74(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jle    1336 <bodyswitch+0x186>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jl     12d0 <bodyswitch+0x120>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    -0x18(%rbp),%rdi
call   10b0 <shiftarray@plt>
jmp    12e2 <bodyswitch+0x132>
mov    $0x0,%al
call   10d0 <rand@plt>
mov    $0x36,%ecx
cltd
idiv   %ecx
mov    %edx,-0x78(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%esi
call   10a0 <extendednameenemy@plt>
lea    -0x70(%rbp),%rsi
lea    0xd39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x78(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x74(%rbp),%eax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%eax
jne    1331 <bodyswitch+0x181>
mov    -0x30(%rbp),%rax
movl   $0x1,(%rax)
mov    0x10(%rbp),%rax
movl   $0x0,(%rax)
jmp    1344 <bodyswitch+0x194>
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,0x18(%rbp)
je     1359 <bodyswitch+0x1a9>
mov    0x18(%rbp),%rax
movl   $0x2,(%rax)
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bodyswitch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r9,0x18(%rsp)
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %rdi,%rbp
movq   $0x0,0x28(%rsp)
movl   $0x3e8,0x20(%rsp)
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1060 <nanosleep@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    0x14(%rsp),%edi
imul   0x10(%rsp),%edi
call   10a0 <srand@plt>
lea    0x30(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1080 <memset@plt>
movabs $0x676e696c61657453,%rax
69 6e 67
mov    %rax,0x30(%rsp)
movabs $0x74697269705367,%rax
mov    %rax,0x37(%rsp)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x7,%edx
mov    %r14,%rcx
call   1050 <magicconsume@plt>
test   %eax,%eax
js     1337 <bodyswitch+0x187>
mov    0x98(%rsp),%r14
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xdc6(%rip),%rbx
lea    0xc(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1090 <getint@plt>
mov    0xc(%rsp),%eax
cmp    $0xb,%rax
ja     1280 <bodyswitch+0xd0>
cmpl   $0x0,(%r12,%rax,4)
jle    12b3 <bodyswitch+0x103>
mov    0x0(%r13),%ebx
test   %ebx,%ebx
js     12c1 <bodyswitch+0x111>
mov    %r13,%rdi
call   10c0 <shiftarray@plt>
jmp    12e4 <bodyswitch+0x134>
lea    0xd9b(%rip),%rdi
call   1030 <puts@plt>
jmp    132b <bodyswitch+0x17b>
xor    %eax,%eax
call   10d0 <rand@plt>
movslq %eax,%rbx
imul   $0x4bda12f7,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x24,%rax
add    %ecx,%eax
imul   $0x36,%eax,%eax
sub    %eax,%ebx
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
mov    %ebx,%esi
call   10b0 <extendednameenemy@plt>
lea    0xd15(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movslq 0xc(%rsp),%rax
mov    %ebx,(%r12,%rax,4)
cmp    (%r15),%eax
jne    132b <bodyswitch+0x17b>
mov    0x18(%rsp),%rax
movl   $0x1,(%rax)
mov    0x90(%rsp),%rax
movl   $0x0,(%rax)
test   %r14,%r14
je     1337 <bodyswitch+0x187>
movl   $0x2,(%r14)
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
%struct.timeval = type { i32, i32 }
@.str = [15 x i8] c"StealingSpirit\00"
@.str.1 = [35 x i8] c"What enemy you want to transmute?\0A\00"
@.str.2 = [36 x i8] c"The enemy is transmuted into a %s!\0A\00"
@.str.3 = [17 x i8] c"Nothing here...\0A\00"
define void @bodyswitch(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7) {
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca %struct.timespec
%18 = alloca %struct.timeval
%19 = alloca [30 x i8]
%20 = alloca i32
%21 = alloca i32
store i32* %0, i32** %9
store i32* %1, i32** %10
store i32* %2, i32** %11
store i32* %3, i32** %12
store i32* %4, i32** %13
store i32* %5, i32** %14
store i32* %6, i32** %15
store i32* %7, i32** %16
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %17, i32 0, i32 1
store i64 0, i64* %22
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %17, i32 0, i32 0
store i32 1000, i32* %23
%24 = call i32 @nanosleep(%struct.timespec* %17, i32* null)
%25 = call i32 @gettimeofday(%struct.timeval* %18, i32* null)
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 0
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 1
%29 = load i32, i32* %28
%30 = mul nsw i32 %27, %29
%31 = call i32 @srand(i32 %30)
%32 = getelementptr inbounds [30 x i8], [30 x i8]* %19, i64 0, i64 0
%33 = call i32 @memset(i8* %32, i32 0, i32 30)
%34 = getelementptr inbounds [30 x i8], [30 x i8]* %19, i64 0, i64 0
%35 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%36 = load i32*, i32** %9
%37 = load i32*, i32** %10
%38 = getelementptr inbounds [30 x i8], [30 x i8]* %19, i64 0, i64 0
%39 = call i32 @magicconsume(i32* %36, i32* %37, i32 7, i8* %38)
store i32 %39, i32* %20
%40 = load i32, i32* %20
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %8
br label %100
43: ; preds = %8
store i32 -1, i32* %20
br label %44
44: ; preds = %53, %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%46 = call i32 @getint(i32* %20)
br label %47
47: ; preds = %44
%48 = load i32, i32* %20
%49 = icmp slt i32 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %47
%51 = load i32, i32* %20
%52 = icmp sgt i32 %51, 11
br label %53
53: ; preds = %50, %47
%54 = phi i1 [ true, %47 ], [ %52, %50 ]
br i1 %54, label %44, label %55
55: ; preds = %53
%56 = load i32*, i32** %12
%57 = load i32, i32* %20
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %56, i64 %58
%60 = load i32, i32* %59
%61 = icmp sgt i32 %60, 0
br i1 %61, label %62, label %93
62: ; preds = %55
%63 = load i32*, i32** %11
%64 = load i32, i32* %63
%65 = icmp sge i32 %64, 0
br i1 %65, label %66, label %71
66: ; preds = %62
%67 = load i32*, i32** %11
%68 = load i32, i32* %67
store i32 %68, i32* %21
%69 = load i32*, i32** %11
%70 = call i32 @shiftarray(i32* %69)
br label %74
71: ; preds = %62
%72 = call i32 (...) @rand()
%73 = srem i32 %72, 54
store i32 %73, i32* %21
br label %74
74: ; preds = %71, %66
%75 = getelementptr inbounds [30 x i8], [30 x i8]* %19, i64 0, i64 0
%76 = load i32, i32* %21
%77 = call i32 @extendednameenemy(i8* %75, i32 %76)
%78 = getelementptr inbounds [30 x i8], [30 x i8]* %19, i64 0, i64 0
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %78)
%80 = load i32, i32* %21
%81 = load i32*, i32** %12
%82 = load i32, i32* %20
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i32, i32* %81, i64 %83
store i32 %80, i32* %84
%85 = load i32, i32* %20
%86 = load i32*, i32** %13
%87 = load i32, i32* %86
%88 = icmp eq i32 %85, %87
br i1 %88, label %89, label %92
89: ; preds = %74
%90 = load i32*, i32** %14
store i32 1, i32* %90
%91 = load i32*, i32** %15
store i32 0, i32* %91
br label %92
92: ; preds = %89, %74
br label %95
93: ; preds = %55
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %95
95: ; preds = %93, %92
%96 = load i32*, i32** %16
%97 = icmp ne i32* %96, null
br i1 %97, label %98, label %100
98: ; preds = %95
%99 = load i32*, i32** %16
store i32 2, i32* %99
br label %100
100: ; preds = %42, %98, %95
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
%struct.timeval = type { i32, i32 }
@.str = [15 x i8] c"StealingSpirit\00"
@.str.2 = [36 x i8] c"The enemy is transmuted into a %s!\0A\00"
@str = [34 x i8] c"What enemy you want to transmute?\00"
@str.4 = [16 x i8] c"Nothing here...\00"
define void @bodyswitch(i32* %0, i32* %1, i32* %2, i32* nocapture %3, i32* nocapture %4, i32* nocapture writeonly %5, i32* nocapture writeonly %6, i32* writeonly %7) {
%9 = alloca %struct.timespec
%10 = alloca %struct.timeval
%11 = alloca [30 x i8]
%12 = alloca i32
%13 = bitcast %struct.timespec* %9 to i8*
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i64 0, i32 1
store i64 0, i64* %14
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i64 0, i32 0
store i32 1000, i32* %15
%16 = call i32 @nanosleep(%struct.timespec* %9, i32* null)
%17 = bitcast %struct.timeval* %10 to i8*
%18 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i64 0, i32 0
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i64 0, i32 1
%22 = load i32, i32* %21
%23 = mul nsw i32 %22, %20
%24 = call i32 @srand(i32 %23)
%25 = getelementptr inbounds [30 x i8], [30 x i8]* %11, i64 0, i64 0
%26 = call i32 @memset(i8* %25, i32 0, i32 30)
%27 = bitcast i32* %12 to i8*
%28 = call i32 @magicconsume(i32* %0, i32* %1, i32 7, i8* %25)
%29 = icmp slt i32 %28, 0
br i1 %29, label %64, label %30
30: ; preds = %8
store i32 -1, i32* %12
br label %31
31: ; preds = %31, %30
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%33 = call i32 @getint(i32* %12)
%34 = load i32, i32* %12
%35 = icmp ugt i32 %34, 11
br i1 %35, label %31, label %36
36: ; preds = %31
%37 = zext i32 %34 to i64
%38 = getelementptr inbounds i32, i32* %3, i64 %37
%39 = load i32, i32* %38
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %59
41: ; preds = %36
%42 = load i32, i32* %2
%43 = icmp sgt i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 @shiftarray(i32* %2)
br label %49
46: ; preds = %41
%47 = call i32 (...) @rand()
%48 = srem i32 %47, 54
br label %49
49: ; preds = %46, %44
%50 = phi i32 [ %42, %44 ], [ %48, %46 ]
%51 = call i32 @extendednameenemy(i8* %25, i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%53 = load i32, i32* %12
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %3, i64 %54
store i32 %50, i32* %55
%56 = load i32, i32* %4
%57 = icmp eq i32 %53, %56
br i1 %57, label %58, label %61
58: ; preds = %49
store i32 1, i32* %5
store i32 0, i32* %6
br label %61
59: ; preds = %36
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.4, i64 0, i64 0))
br label %61
61: ; preds = %49, %58, %59
%62 = icmp eq i32* %7, null
br i1 %62, label %64, label %63
63: ; preds = %61
store i32 2, i32* %7
br label %64
64: ; preds = %61, %63, %8
ret void
}