#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*/ Get_Coordinates(int, int *, int *);
scalar_t__ calloc(int, int);
int rand();
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *Place_Campaign_Humans(int start_place, int *destinations) {
  char *buffer;
  char coordinates[256];
  int objective = 0;
  int last_location = start_place;
  int place_x = 0, place_y = 0;
  int human_x, human_y;
  buffer = (char *)calloc(4096, sizeof(char));
  if (!buffer)
    return NULL;
  strcpy(buffer, "# Place humans\n");
  while (objective < 5) {
    if (destinations[objective] == 6) {
      if (last_location == 5)
        strcat(buffer,
               "create_human default need_rescue alert aware in_water\n");
      else
        strcat(buffer, "create_human default need_rescue alert aware\n");
      strcat(buffer, "translation ");
      Get_Coordinates(last_location, &place_x, &place_y);
      human_x = (rand() % 1000) - (1000 / 2);
      human_x = place_x + human_x;
      human_y = (rand() & 1000) - (1000 / 2);
      human_y = place_y + human_y;
      sprintf(coordinates, "%d %d 0.0", human_x, human_y);
      strcat(buffer, coordinates);
      strcat(buffer, "\nset_human_mesg_enter Thank you for the lift.\n");
      if (last_location == 4) {
        strcat(buffer, "create_fire 10.0 15.0\n");
        strcat(buffer, "translation ");
        sprintf(coordinates, "%d %d 0.0\n", human_x + 200, human_y - 100);
        strcat(buffer, coordinates);
      }
    } else if ((destinations[objective] > 0) && (destinations[objective] < 6))
      last_location = destinations[objective];
    objective++;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<Place_Campaign_Humans>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x124(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x128(%rbp)
movl   $0x0,-0x12c(%rbp)
movl   $0x0,-0x130(%rbp)
mov    $0x1000,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c4 <Place_Campaign_Humans+0x64>
movq   $0x0,-0x8(%rbp)
jmp    13af <Place_Campaign_Humans+0x24f>
mov    -0x20(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1030 <strcpy@plt>
cmpl   $0x5,-0x124(%rbp)
jge    13a7 <Place_Campaign_Humans+0x247>
mov    -0x18(%rbp),%rax
movslq -0x124(%rbp),%rcx
cmpl   $0x6,(%rax,%rcx,4)
jne    1350 <Place_Campaign_Humans+0x1f0>
cmpl   $0x5,-0x128(%rbp)
jne    1218 <Place_Campaign_Humans+0xb8>
mov    -0x20(%rbp),%rdi
lea    0xe02(%rip),%rsi
call   1050 <strcat@plt>
jmp    1228 <Place_Campaign_Humans+0xc8>
mov    -0x20(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x128(%rbp),%edi
lea    -0x12c(%rbp),%rsi
lea    -0x130(%rbp),%rdx
call   1060 <Get_Coordinates@plt>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
sub    $0x1f4,%edx
mov    %edx,-0x134(%rbp)
mov    -0x12c(%rbp),%eax
add    -0x134(%rbp),%eax
mov    %eax,-0x134(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
and    $0x3e8,%eax
sub    $0x1f4,%eax
mov    %eax,-0x138(%rbp)
mov    -0x130(%rbp),%eax
add    -0x138(%rbp),%eax
mov    %eax,-0x138(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x134(%rbp),%edx
mov    -0x138(%rbp),%ecx
lea    0xdc1(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xdab(%rip),%rsi
call   1050 <strcat@plt>
cmpl   $0x4,-0x128(%rbp)
jne    134b <Place_Campaign_Humans+0x1eb>
mov    -0x20(%rbp),%rdi
lea    0xdbd(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xd67(%rip),%rsi
call   1050 <strcat@plt>
lea    -0x120(%rbp),%rdi
mov    -0x134(%rbp),%edx
add    $0xc8,%edx
mov    -0x138(%rbp),%ecx
sub    $0x64,%ecx
lea    0xd9c(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1050 <strcat@plt>
jmp    1393 <Place_Campaign_Humans+0x233>
mov    -0x18(%rbp),%rax
movslq -0x124(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jle    138e <Place_Campaign_Humans+0x22e>
mov    -0x18(%rbp),%rax
movslq -0x124(%rbp),%rcx
cmpl   $0x6,(%rax,%rcx,4)
jge    138e <Place_Campaign_Humans+0x22e>
mov    -0x18(%rbp),%rax
movslq -0x124(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x128(%rbp)
jmp    1393 <Place_Campaign_Humans+0x233>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    11d4 <Place_Campaign_Humans+0x74>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Place_Campaign_Humans>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r12
mov    %edi,%ebp
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
mov    $0x1000,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     1309 <Place_Campaign_Humans+0x1a9>
mov    %rax,%r14
lea    0xe59(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
xor    %r13d,%r13d
mov    %r12,0x8(%rsp)
jmp    11d7 <Place_Campaign_Humans+0x77>
nopl   0x0(%rax)
lea    -0x1(%rax),%ecx
cmp    $0x5,%ecx
cmovb  %eax,%ebp
add    $0x1,%r13
cmp    $0x5,%r13
je     130c <Place_Campaign_Humans+0x1ac>
mov    (%r12,%r13,4),%eax
cmp    $0x6,%eax
jne    11c0 <Place_Campaign_Humans+0x60>
lea    0xe29(%rip),%rsi
cmp    $0x5,%ebp
je     11f3 <Place_Campaign_Humans+0x93>
lea    0xe54(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcat@plt>
mov    %r14,%rdi
lea    0xe70(%rip),%rsi
call   1050 <strcat@plt>
mov    %ebp,%edi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1060 <Get_Coordinates@plt>
xor    %eax,%eax
call   1080 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    0x4(%rsp),%ecx
lea    (%rcx,%rax,1),%ebx
add    $0xfffffe0c,%ebx
xor    %eax,%eax
call   1080 <rand@plt>
and    $0x3e8,%eax
mov    (%rsp),%ecx
lea    (%rax,%rcx,1),%r15d
add    $0xfffffe0c,%r15d
mov    %ebp,%r12d
mov    %r14,%rbp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
lea    0xe08(%rip),%rsi
mov    %ebx,%edx
mov    %r15d,%ecx
call   1070 <sprintf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %rbp,%r14
mov    %r12d,%ebp
call   1050 <strcat@plt>
mov    %r14,%rdi
lea    0xded(%rip),%rsi
call   1050 <strcat@plt>
cmp    $0x4,%r12d
mov    0x8(%rsp),%r12
jne    11c9 <Place_Campaign_Humans+0x69>
mov    %r14,%rdi
lea    0xdfe(%rip),%rsi
call   1050 <strcat@plt>
mov    %r14,%rdi
lea    0xda9(%rip),%rsi
call   1050 <strcat@plt>
add    $0xc8,%ebx
add    $0xffffff9c,%r15d
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
lea    0xde8(%rip),%rsi
mov    %ebx,%edx
mov    %r15d,%ecx
call   1070 <sprintf@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1050 <strcat@plt>
mov    $0x4,%ebp
jmp    11c9 <Place_Campaign_Humans+0x69>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"# Place humans\0A\00"
@.str.1 = [55 x i8] c"create_human default need_rescue alert aware in_water\0A\00"
@.str.2 = [46 x i8] c"create_human default need_rescue alert aware\0A\00"
@.str.3 = [13 x i8] c"translation \00"
@.str.4 = [10 x i8] c"%d %d 0.0\00"
@.str.5 = [47 x i8] c"\0Aset_human_mesg_enter Thank you for the lift.\0A\00"
@.str.6 = [23 x i8] c"create_fire 10.0 15.0\0A\00"
@.str.7 = [11 x i8] c"%d %d 0.0\0A\00"
define i8* @Place_Campaign_Humans(i32 %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca [256 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 0, i32* %8
%14 = load i32, i32* %4
store i32 %14, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
%15 = call i64 @calloc(i32 4096, i32 1)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %2
store i8* null, i8** %3
br label %111
20: ; preds = %2
%21 = load i8*, i8** %6
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %106, %20
%24 = load i32, i32* %8
%25 = icmp slt i32 %24, 5
br i1 %25, label %26, label %109
26: ; preds = %23
%27 = load i32*, i32** %5
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = icmp eq i32 %31, 6
br i1 %32, label %33, label %85
33: ; preds = %26
%34 = load i32, i32* %9
%35 = icmp eq i32 %34, 5
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i8*, i8** %6
%38 = call i32 @strcat(i8* %37, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
br label %42
39: ; preds = %33
%40 = load i8*, i8** %6
%41 = call i32 @strcat(i8* %40, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %39, %36
%43 = load i8*, i8** %6
%44 = call i32 @strcat(i8* %43, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%45 = load i32, i32* %9
%46 = call i32 @Get_Coordinates(i32 %45, i32* %10, i32* %11)
%47 = call i32 (...) @rand()
%48 = srem i32 %47, 1000
%49 = sub nsw i32 %48, 500
store i32 %49, i32* %12
%50 = load i32, i32* %10
%51 = load i32, i32* %12
%52 = add nsw i32 %50, %51
store i32 %52, i32* %12
%53 = call i32 (...) @rand()
%54 = and i32 %53, 1000
%55 = sub nsw i32 %54, 500
store i32 %55, i32* %13
%56 = load i32, i32* %11
%57 = load i32, i32* %13
%58 = add nsw i32 %56, %57
store i32 %58, i32* %13
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%60 = load i32, i32* %12
%61 = load i32, i32* %13
%62 = call i32 @sprintf(i8* %59, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %60, i32 %61)
%63 = load i8*, i8** %6
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%65 = call i32 @strcat(i8* %63, i8* %64)
%66 = load i8*, i8** %6
%67 = call i32 @strcat(i8* %66, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
%68 = load i32, i32* %9
%69 = icmp eq i32 %68, 4
br i1 %69, label %70, label %84
70: ; preds = %42
%71 = load i8*, i8** %6
%72 = call i32 @strcat(i8* %71, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%73 = load i8*, i8** %6
%74 = call i32 @strcat(i8* %73, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%75 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%76 = load i32, i32* %12
%77 = add nsw i32 %76, 200
%78 = load i32, i32* %13
%79 = sub nsw i32 %78, 100
%80 = call i32 @sprintf(i8* %75, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i32 %77, i32 %79)
%81 = load i8*, i8** %6
%82 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%83 = call i32 @strcat(i8* %81, i8* %82)
br label %84
84: ; preds = %70, %42
br label %106
85: ; preds = %26
%86 = load i32*, i32** %5
%87 = load i32, i32* %8
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i32, i32* %86, i64 %88
%90 = load i32, i32* %89
%91 = icmp sgt i32 %90, 0
br i1 %91, label %92, label %105
92: ; preds = %85
%93 = load i32*, i32** %5
%94 = load i32, i32* %8
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i32, i32* %93, i64 %95
%97 = load i32, i32* %96
%98 = icmp slt i32 %97, 6
br i1 %98, label %99, label %105
99: ; preds = %92
%100 = load i32*, i32** %5
%101 = load i32, i32* %8
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i32, i32* %100, i64 %102
%104 = load i32, i32* %103
store i32 %104, i32* %9
br label %105
105: ; preds = %99, %92, %85
br label %106
106: ; preds = %105, %84
%107 = load i32, i32* %8
%108 = add nsw i32 %107, 1
store i32 %108, i32* %8
br label %23
109: ; preds = %23
%110 = load i8*, i8** %6
store i8* %110, i8** %3
br label %111
111: ; preds = %109, %19
%112 = load i8*, i8** %3
ret i8* %112
}

LLVM IR (-O2):
@.str = [16 x i8] c"# Place humans\0A\00"
@.str.1 = [55 x i8] c"create_human default need_rescue alert aware in_water\0A\00"
@.str.2 = [46 x i8] c"create_human default need_rescue alert aware\0A\00"
@.str.3 = [13 x i8] c"translation \00"
@.str.4 = [10 x i8] c"%d %d 0.0\00"
@.str.5 = [47 x i8] c"\0Aset_human_mesg_enter Thank you for the lift.\0A\00"
@.str.6 = [23 x i8] c"create_fire 10.0 15.0\0A\00"
@.str.7 = [11 x i8] c"%d %d 0.0\0A\00"
define i8* @Place_Campaign_Humans(i32 %0, i32* nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%8 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%9 = tail call i64 @calloc(i32 4096, i32 1)
%10 = inttoptr i64 %9 to i8*
%11 = icmp eq i64 %9, 0
br i1 %11, label %55, label %12
12: ; preds = %2
%13 = tail call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %51
%15 = phi i64 [ 0, %12 ], [ %53, %51 ]
%16 = phi i32 [ %0, %12 ], [ %52, %51 ]
%17 = getelementptr inbounds i32, i32* %1, i64 %15
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, 6
br i1 %19, label %20, label %47
20: ; preds = %14
%21 = icmp eq i32 %16, 5
%22 = select i1 %21, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0)
%23 = call i32 @strcat(i8* %10, i8* %22)
%24 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @Get_Coordinates(i32 %16, i32* %4, i32* %5)
%26 = call i32 (...) @rand()
%27 = srem i32 %26, 1000
%28 = add nsw i32 %27, -500
%29 = load i32, i32* %4
%30 = add nsw i32 %28, %29
%31 = call i32 (...) @rand()
%32 = and i32 %31, 1000
%33 = add nsw i32 %32, -500
%34 = load i32, i32* %5
%35 = add nsw i32 %33, %34
%36 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %30, i32 %35)
%37 = call i32 @strcat(i8* %10, i8* %6)
%38 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
%39 = icmp eq i32 %16, 4
br i1 %39, label %40, label %51
40: ; preds = %20
%41 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%42 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%43 = add nsw i32 %30, 200
%44 = add nsw i32 %35, -100
%45 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i32 %43, i32 %44)
%46 = call i32 @strcat(i8* %10, i8* %6)
br label %51
47: ; preds = %14
%48 = add i32 %18, -1
%49 = icmp ult i32 %48, 5
%50 = select i1 %49, i32 %18, i32 %16
br label %51
51: ; preds = %47, %20, %40
%52 = phi i32 [ 4, %40 ], [ %16, %20 ], [ %50, %47 ]
%53 = add nuw nsw i64 %15, 1
%54 = icmp eq i64 %53, 5
br i1 %54, label %55, label %14
55: ; preds = %51, %2
%56 = phi i8* [ null, %2 ], [ %10, %51 ]
ret i8* %56
}