#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*/ DetermineAction(int, float *, float *);
int /*<<< orphan*/ DriveMotors(float, float);
int /*<<< orphan*/ Finish();
scalar_t__ GetFinished();
int GetGroundSensor();
int GetNumberOfBeacons();
int /*<<< orphan*/ GetReturningLed();
scalar_t__ GetStartButton();
scalar_t__ GetStopButton();
int GetTime();
int /*<<< orphan*/ GetVisitingLed();
int InitRobot(char *, int, char *);
int /*<<< orphan*/ ReadSensors();
int /*<<< orphan*/ RequestBeaconSensor(int);
int /*<<< orphan*/ RequestGroundSensor();
int /*<<< orphan*/ RequestObstacleSensor(int /*<<< orphan*/);
int /*<<< orphan*/ RequestSensors(int, char *, char *);
int /*<<< orphan*/ Say(char *);
int /*<<< orphan*/ SetVisitingLed(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char *argv[]) {
  char host[100] = "localhost";
  char rob_name[20] = "robsample";
  float lPow, rPow;
  int state = 2, stoppedState = 1, rob_id = 1;
  int beaconToFollow = 0;
  printf(" Sample Robot\n Copyright (C) 2001-2013 Universidade de Aveiro\n");
  while (argc > 2) {
    if (strcmp(argv[1], "-host") == 0) {
      strncpy(host, argv[2], 99);
      host[99] = '\0';
    } else if (strcmp(argv[1], "-robname") == 0) {
      strncpy(rob_name, argv[2], 19);
      rob_name[19] = '\0';
    } else if (strcmp(argv[1], "-pos") == 0) {
      if (sscanf(argv[2], "%d", &rob_id) != 1)
        argc = 0;
    } else {
      break;
    }
    argc -= 2;
    argv += 2;
  }
  if (argc != 1) {
    fprintf(stderr, "Bad number of parameters\n"
                    "SYNOPSIS: mainRob [-host hostname] [-robname robotname] "
                    "[-pos posnumber]\n");
    return 1;
  }
  if (InitRobot(rob_name, rob_id, host) == -1) {
    printf("%s Failed to connect\n", rob_name);
    exit(1);
  }
  printf("%s Connected\n", rob_name);
  state = 2;
  while (1) {
    ReadSensors();
    if (GetFinished()) {
      printf("%s Exiting\n", rob_name);
      exit(0);
    }
    if (state == 2 && GetStartButton())
      state = stoppedState;
    if (state != 2 && GetStopButton()) {
      stoppedState = state;
      state = 2;
    }
    switch (state) {
    case 1:
      if (GetVisitingLed())
        state = 3;
      if (GetGroundSensor() == 0) {
        SetVisitingLed(1);
        printf("%s visited target at %d\n", rob_name, GetTime());
      } else {
        DetermineAction(0, &lPow, &rPow);
        DriveMotors(lPow, rPow);
      }
      break;
    case 3:
      if (GetReturningLed())
        state = 4;
      DriveMotors(0.0, 0.0);
      break;
    case 4:
      if (GetGroundSensor() == 1) {
        Finish();
        printf("%s found home at %d\n", rob_name, GetTime());
      } else {
        DetermineAction(1, &lPow, &rPow);
        DriveMotors(lPow, rPow);
      }
      break;
    }
    Say(rob_name);
    if (GetTime() % 2 == 0) {
      RequestObstacleSensor(0);
      if (GetTime() % 8 == 0 || beaconToFollow == GetNumberOfBeacons())
        RequestGroundSensor();
      else
        RequestBeaconSensor(beaconToFollow);
    } else {
      RequestSensors(2, "IRSensor1", "IRSensor2");
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xd3c(%rip),%rsi
mov    $0x64,%edx
call   1100 <memcpy@plt>
mov    0xd9b(%rip),%rax
mov    %rax,-0xa0(%rbp)
mov    0xd95(%rip),%rax
mov    %rax,-0x98(%rbp)
mov    0xd90(%rip),%eax
mov    %eax,-0x90(%rbp)
movl   $0x2,-0xac(%rbp)
movl   $0x1,-0xb0(%rbp)
movl   $0x1,-0xb4(%rbp)
movl   $0x0,-0xb8(%rbp)
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
jle    142d <main+0x18d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd7e(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    1373 <main+0xd3>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    $0x63,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x1d(%rbp)
jmp    1413 <main+0x173>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd47(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    13b6 <main+0x116>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    $0x13,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x8d(%rbp)
jmp    140e <main+0x16e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd0d(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    1404 <main+0x164>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xcf4(%rip),%rsi
lea    -0xb4(%rbp),%rdx
call   1140 <sscanf@plt>
cmp    $0x1,%eax
je     13ff <main+0x15f>
movl   $0x0,-0x8(%rbp)
jmp    1409 <main+0x169>
jmp    142d <main+0x18d>
jmp    140e <main+0x16e>
jmp    1413 <main+0x173>
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x10(%rbp)
jmp    132c <main+0x8c>
cmpl   $0x1,-0x8(%rbp)
je     145a <main+0x1ba>
mov    0x2ba2(%rip),%rax
mov    (%rax),%edi
lea    0xc93(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0x1,%eax
add    $0xe0,%rsp
pop    %rbp
ret
lea    -0xa0(%rbp),%rdi
mov    -0xb4(%rbp),%esi
lea    -0x80(%rbp),%rdx
call   1050 <InitRobot@plt>
cmp    $0xffffffff,%eax
jne    1498 <main+0x1f8>
lea    -0xa0(%rbp),%rsi
lea    0xcb6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   11b0 <exit@plt>
lea    -0xa0(%rbp),%rsi
lea    0xcad(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x2,-0xac(%rbp)
mov    $0x0,%al
call   1080 <ReadSensors@plt>
mov    $0x0,%al
call   10f0 <GetFinished@plt>
cmp    $0x0,%rax
je     14eb <main+0x24b>
lea    -0xa0(%rbp),%rsi
lea    0xc84(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   11b0 <exit@plt>
cmpl   $0x2,-0xac(%rbp)
jne    1515 <main+0x275>
mov    $0x0,%al
call   10a0 <GetStartButton@plt>
cmp    $0x0,%rax
je     1515 <main+0x275>
mov    -0xb0(%rbp),%eax
mov    %eax,-0xac(%rbp)
cmpl   $0x2,-0xac(%rbp)
je     1549 <main+0x2a9>
mov    $0x0,%al
call   1160 <GetStopButton@plt>
cmp    $0x0,%rax
je     1549 <main+0x2a9>
mov    -0xac(%rbp),%eax
mov    %eax,-0xb0(%rbp)
movl   $0x2,-0xac(%rbp)
mov    -0xac(%rbp),%eax
mov    %eax,-0xbc(%rbp)
sub    $0x1,%eax
je     158b <main+0x2eb>
jmp    1563 <main+0x2c3>
mov    -0xbc(%rbp),%eax
sub    $0x3,%eax
je     161f <main+0x37f>
jmp    1577 <main+0x2d7>
mov    -0xbc(%rbp),%eax
sub    $0x4,%eax
je     1649 <main+0x3a9>
jmp    16c3 <main+0x423>
mov    $0x0,%al
call   1060 <GetVisitingLed@plt>
cmp    $0x0,%eax
je     15a5 <main+0x305>
movl   $0x3,-0xac(%rbp)
mov    $0x0,%al
call   1180 <GetGroundSensor@plt>
cmp    $0x0,%eax
jne    15f0 <main+0x350>
mov    $0x1,%edi
call   1130 <SetVisitingLed@plt>
lea    -0xa0(%rbp),%rax
mov    %rax,-0xc8(%rbp)
mov    $0x0,%al
call   10e0 <GetTime@plt>
mov    -0xc8(%rbp),%rsi
mov    %eax,%edx
lea    0xb89(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    161a <main+0x37a>
xor    %edi,%edi
lea    -0xa4(%rbp),%rsi
lea    -0xa8(%rbp),%rdx
call   1110 <DetermineAction@plt>
movss  -0xa4(%rbp),%xmm0
ff
movss  -0xa8(%rbp),%xmm1
ff
call   11c0 <DriveMotors@plt>
jmp    16c3 <main+0x423>
mov    $0x0,%al
call   1170 <GetReturningLed@plt>
cmp    $0x0,%eax
je     1639 <main+0x399>
movl   $0x4,-0xac(%rbp)
xorps  %xmm1,%xmm1
movaps %xmm1,%xmm0
call   11c0 <DriveMotors@plt>
jmp    16c3 <main+0x423>
mov    $0x0,%al
call   1180 <GetGroundSensor@plt>
cmp    $0x1,%eax
jne    1691 <main+0x3f1>
mov    $0x0,%al
call   1150 <Finish@plt>
lea    -0xa0(%rbp),%rax
mov    %rax,-0xd0(%rbp)
mov    $0x0,%al
call   10e0 <GetTime@plt>
mov    -0xd0(%rbp),%rsi
mov    %eax,%edx
lea    0xb01(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    16be <main+0x41e>
mov    $0x1,%edi
lea    -0xa4(%rbp),%rsi
lea    -0xa8(%rbp),%rdx
call   1110 <DetermineAction@plt>
movss  -0xa4(%rbp),%xmm0
ff
movss  -0xa8(%rbp),%xmm1
ff
call   11c0 <DriveMotors@plt>
jmp    16c3 <main+0x423>
lea    -0xa0(%rbp),%rdi
call   11a0 <Say@plt>
mov    $0x0,%al
call   10e0 <GetTime@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1745 <main+0x4a5>
xor    %edi,%edi
call   1090 <RequestObstacleSensor@plt>
mov    $0x0,%al
call   10e0 <GetTime@plt>
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1729 <main+0x489>
mov    -0xb8(%rbp),%eax
mov    %eax,-0xd4(%rbp)
mov    $0x0,%al
call   1040 <GetNumberOfBeacons@plt>
mov    %eax,%ecx
mov    -0xd4(%rbp),%eax
cmp    %ecx,%eax
jne    1735 <main+0x495>
mov    $0x0,%al
call   1120 <RequestGroundSensor@plt>
jmp    1740 <main+0x4a0>
mov    -0xb8(%rbp),%edi
call   10b0 <RequestBeaconSensor@plt>
jmp    175d <main+0x4bd>
mov    $0x2,%edi
lea    0xa4a(%rip),%rsi
lea    0xa4d(%rip),%rdx
call   1190 <RequestSensors@plt>
jmp    14b7 <main+0x217>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movaps 0xd93(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xd74(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xd58(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xd3c(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xd20(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xd04(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movl   $0x0,0x90(%rsp)
movaps 0xd5d(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x20(%rsp)
movl   $0x1,0xc(%rsp)
lea    0xe41(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x3,%ebp
jl     13f9 <main+0x159>
add    $0x10,%rbx
lea    0xd3c(%rip),%r14
lea    0xd3b(%rip),%r12
lea    0xd3d(%rip),%r13
lea    0xc(%rsp),%r15
jmp    138b <main+0xeb>
nopl   (%rax)
mov    (%rbx),%rsi
lea    0x30(%rsp),%rdi
mov    $0x63,%edx
call   1030 <strncpy@plt>
lea    0x93(%rsp),%rax
movb   $0x0,(%rax)
lea    -0x2(%rbp),%eax
add    $0x10,%rbx
cmp    $0x4,%ebp
mov    %eax,%ebp
jbe    13fb <main+0x15b>
mov    -0x8(%rbx),%rdi
mov    %r14,%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
je     1360 <main+0xc0>
mov    -0x8(%rbx),%rdi
mov    %r12,%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
je     13e0 <main+0x140>
mov    -0x8(%rbx),%rdi
mov    %r13,%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
jne    1400 <main+0x160>
mov    (%rbx),%rdi
lea    0xcd0(%rip),%rsi
mov    %r15,%rdx
call   1140 <sscanf@plt>
cmp    $0x1,%eax
je     137d <main+0xdd>
jmp    1400 <main+0x160>
nopw   0x0(%rax,%rax,1)
mov    (%rbx),%rsi
lea    0x10(%rsp),%rdi
mov    $0x13,%edx
call   1030 <strncpy@plt>
lea    0x23(%rsp),%rax
jmp    137a <main+0xda>
mov    %ebp,%eax
cmp    $0x1,%eax
je     142c <main+0x18c>
mov    0x2bd9(%rip),%rax
mov    (%rax),%edi
lea    0xc8b(%rip),%rsi
call   10e0 <fprintf@plt>
mov    $0x1,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0xc(%rsp),%esi
lea    0x10(%rsp),%rdi
lea    0x30(%rsp),%rdx
call   1060 <InitRobot@plt>
cmp    $0xffffffff,%eax
jne    1461 <main+0x1c1>
lea    0xcb3(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%edi
call   11b0 <exit@plt>
lea    0xcac(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
call   1090 <ReadSensors@plt>
xor    %eax,%eax
call   1100 <GetFinished@plt>
test   %rax,%rax
jne    1665 <main+0x3c5>
mov    $0x2,%ebp
mov    $0x1,%r12d
lea    0x10(%rsp),%rbx
lea    0xcba(%rip),%r14
lea    0xcbd(%rip),%r15
jmp    14d2 <main+0x232>
mov    $0x2,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1190 <RequestSensors@plt>
xor    %eax,%eax
call   1090 <ReadSensors@plt>
xor    %eax,%eax
call   1100 <GetFinished@plt>
test   %rax,%rax
jne    1665 <main+0x3c5>
mov    %ebp,%r13d
cmp    $0x2,%ebp
jne    14f4 <main+0x254>
xor    %eax,%eax
call   10b0 <GetStartButton@plt>
mov    $0x2,%ebp
test   %rax,%rax
je     1508 <main+0x268>
mov    %r12d,%r13d
cmp    $0x2,%r12d
je     1508 <main+0x268>
xor    %eax,%eax
call   1160 <GetStopButton@plt>
mov    $0x2,%ebp
test   %rax,%rax
je     1550 <main+0x2b0>
mov    %r13d,%r12d
mov    %rbx,%rdi
call   11a0 <Say@plt>
xor    %eax,%eax
call   10f0 <GetTime@plt>
test   $0x1,%al
jne    14ab <main+0x20b>
xor    %edi,%edi
call   10a0 <RequestObstacleSensor@plt>
xor    %eax,%eax
call   10f0 <GetTime@plt>
test   $0x7,%al
je     1544 <main+0x2a4>
xor    %eax,%eax
call   1050 <GetNumberOfBeacons@plt>
test   %eax,%eax
je     1544 <main+0x2a4>
xor    %edi,%edi
call   10c0 <RequestBeaconSensor@plt>
jmp    14bb <main+0x21b>
xor    %eax,%eax
call   1120 <RequestGroundSensor@plt>
jmp    14bb <main+0x21b>
cmp    $0x4,%r13d
je     15b4 <main+0x314>
cmp    $0x3,%r13d
je     15e3 <main+0x343>
cmp    $0x1,%r13d
jne    1605 <main+0x365>
xor    %eax,%eax
call   1070 <GetVisitingLed@plt>
xor    %ecx,%ecx
test   %eax,%eax
setne  %cl
lea    (%rcx,%rcx,1),%ebp
add    $0x1,%ebp
xor    %eax,%eax
call   1180 <GetGroundSensor@plt>
test   %eax,%eax
je     163c <main+0x39c>
xor    %edi,%edi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1110 <DetermineAction@plt>
movss  0x8(%rsp),%xmm0
movss  0x4(%rsp),%xmm1
call   11c0 <DriveMotors@plt>
jmp    1508 <main+0x268>
xor    %eax,%eax
call   1180 <GetGroundSensor@plt>
cmp    $0x1,%eax
jne    160d <main+0x36d>
xor    %eax,%eax
call   1150 <Finish@plt>
xor    %eax,%eax
call   10f0 <GetTime@plt>
lea    0xb72(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1632 <main+0x392>
xor    %eax,%eax
call   1170 <GetReturningLed@plt>
cmp    $0x1,%eax
mov    $0x4,%ebp
sbb    $0x0,%ebp
xorps  %xmm0,%xmm0
xorps  %xmm1,%xmm1
call   11c0 <DriveMotors@plt>
jmp    1508 <main+0x268>
mov    %r13d,%ebp
jmp    1508 <main+0x268>
mov    $0x1,%edi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1110 <DetermineAction@plt>
movss  0x8(%rsp),%xmm0
movss  0x4(%rsp),%xmm1
call   11c0 <DriveMotors@plt>
mov    $0x4,%ebp
jmp    1508 <main+0x268>
mov    $0x1,%edi
call   1130 <SetVisitingLed@plt>
xor    %eax,%eax
call   10f0 <GetTime@plt>
lea    0xada(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1508 <main+0x268>
lea    0xab6(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %edi,%edi
call   11b0 <exit@plt>

LLVM IR (-O0):
@__const.main.host = [100 x i8] c"localhost\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.rob_name = [20 x i8] c"robsample\00\00\00\00\00\00\00\00\00\00\00"
@.str = [63 x i8] c" Sample Robot\0A Copyright (C) 2001-2013 Universidade de Aveiro\0A\00"
@.str.1 = [6 x i8] c"-host\00"
@.str.2 = [9 x i8] c"-robname\00"
@.str.3 = [5 x i8] c"-pos\00"
@.str.4 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.5 = [99 x i8] c"Bad number of parameters\0ASYNOPSIS: mainRob [-host hostname] [-robname robotname] [-pos posnumber]\0A\00"
@.str.6 = [22 x i8] c"%s Failed to connect\0A\00"
@.str.7 = [14 x i8] c"%s Connected\0A\00"
@.str.8 = [12 x i8] c"%s Exiting\0A\00"
@.str.9 = [25 x i8] c"%s visited target at %d\0A\00"
@.str.10 = [21 x i8] c"%s found home at %d\0A\00"
@.str.11 = [10 x i8] c"IRSensor1\00"
@.str.12 = [10 x i8] c"IRSensor2\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca [20 x i8]
%8 = alloca float
%9 = alloca float
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = bitcast [100 x i8]* %6 to i8*
%15 = bitcast [20 x i8]* %7 to i8*
store i32 2, i32* %10
store i32 1, i32* %11
store i32 1, i32* %12
store i32 0, i32* %13
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %63, %2
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 2
br i1 %19, label %20, label %68
20: ; preds = %17
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %20
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @strncpy(i8* %27, i8* %30, i32 99)
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 99
store i8 0, i8* %32
br label %63
33: ; preds = %20
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %46
39: ; preds = %33
%40 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = call i32 @strncpy(i8* %40, i8* %43, i32 19)
%45 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 19
store i8 0, i8* %45
br label %62
46: ; preds = %33
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i64 @strcmp(i8* %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %60
52: ; preds = %46
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 2
%55 = load i8*, i8** %54
%56 = call i32 @sscanf(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %12)
%57 = icmp ne i32 %56, 1
br i1 %57, label %58, label %59
58: ; preds = %52
store i32 0, i32* %4
br label %59
59: ; preds = %58, %52
br label %61
60: ; preds = %46
br label %68
61: ; preds = %59
br label %62
62: ; preds = %61, %39
br label %63
63: ; preds = %62, %26
%64 = load i32, i32* %4
%65 = sub nsw i32 %64, 2
store i32 %65, i32* %4
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 2
store i8** %67, i8*** %5
br label %17
68: ; preds = %60, %17
%69 = load i32, i32* %4
%70 = icmp ne i32 %69, 1
br i1 %70, label %71, label %74
71: ; preds = %68
%72 = load i32, i32* @stderr
%73 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.5, i64 0, i64 0))
ret i32 1
74: ; preds = %68
%75 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%76 = load i32, i32* %12
%77 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%78 = call i32 @InitRobot(i8* %75, i32 %76, i8* %77)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %84
80: ; preds = %74
%81 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %81)
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %74
%85 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %85)
store i32 2, i32* %10
br label %87
87: ; preds = %84, %174
%88 = call i32 (...) @ReadSensors()
%89 = call i64 (...) @GetFinished()
%90 = icmp ne i64 %89, 0
br i1 %90, label %91, label %95
91: ; preds = %87
%92 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %92)
%94 = call i32 @exit(i32 0)
unreachable
95: ; preds = %87
%96 = load i32, i32* %10
%97 = icmp eq i32 %96, 2
br i1 %97, label %98, label %103
98: ; preds = %95
%99 = call i64 (...) @GetStartButton()
%100 = icmp ne i64 %99, 0
br i1 %100, label %101, label %103
101: ; preds = %98
%102 = load i32, i32* %11
store i32 %102, i32* %10
br label %103
103: ; preds = %101, %98, %95
%104 = load i32, i32* %10
%105 = icmp ne i32 %104, 2
br i1 %105, label %106, label %111
106: ; preds = %103
%107 = call i64 (...) @GetStopButton()
%108 = icmp ne i64 %107, 0
br i1 %108, label %109, label %111
109: ; preds = %106
%110 = load i32, i32* %10
store i32 %110, i32* %11
store i32 2, i32* %10
br label %111
111: ; preds = %109, %106, %103
%112 = load i32, i32* %10
switch i32 %112, label %151 [
i32 1, label %113
i32 3, label %131
i32 4, label %137
]
113: ; preds = %111
%114 = call i32 (...) @GetVisitingLed()
%115 = icmp ne i32 %114, 0
br i1 %115, label %116, label %117
116: ; preds = %113
store i32 3, i32* %10
br label %117
117: ; preds = %116, %113
%118 = call i32 (...) @GetGroundSensor()
%119 = icmp eq i32 %118, 0
br i1 %119, label %120, label %125
120: ; preds = %117
%121 = call i32 @SetVisitingLed(i32 1)
%122 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%123 = call i32 (...) @GetTime()
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i8* %122, i32 %123)
br label %130
125: ; preds = %117
%126 = call i32 @DetermineAction(i32 0, float* %8, float* %9)
%127 = load float, float* %8
%128 = load float, float* %9
%129 = call i32 @DriveMotors(float %127, float %128)
br label %130
130: ; preds = %125, %120
br label %151
131: ; preds = %111
%132 = call i32 (...) @GetReturningLed()
%133 = icmp ne i32 %132, 0
br i1 %133, label %134, label %135
134: ; preds = %131
store i32 4, i32* %10
br label %135
135: ; preds = %134, %131
%136 = call i32 @DriveMotors(float 0.000000e+00, float 0.000000e+00)
br label %151
137: ; preds = %111
%138 = call i32 (...) @GetGroundSensor()
%139 = icmp eq i32 %138, 1
br i1 %139, label %140, label %145
140: ; preds = %137
%141 = call i32 (...) @Finish()
%142 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%143 = call i32 (...) @GetTime()
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i8* %142, i32 %143)
br label %150
145: ; preds = %137
%146 = call i32 @DetermineAction(i32 1, float* %8, float* %9)
%147 = load float, float* %8
%148 = load float, float* %9
%149 = call i32 @DriveMotors(float %147, float %148)
br label %150
150: ; preds = %145, %140
br label %151
151: ; preds = %111, %150, %135, %130
%152 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%153 = call i32 @Say(i8* %152)
%154 = call i32 (...) @GetTime()
%155 = srem i32 %154, 2
%156 = icmp eq i32 %155, 0
br i1 %156, label %157, label %172
157: ; preds = %151
%158 = call i32 @RequestObstacleSensor(i32 0)
%159 = call i32 (...) @GetTime()
%160 = srem i32 %159, 8
%161 = icmp eq i32 %160, 0
br i1 %161, label %166, label %162
162: ; preds = %157
%163 = load i32, i32* %13
%164 = call i32 (...) @GetNumberOfBeacons()
%165 = icmp eq i32 %163, %164
br i1 %165, label %166, label %168
166: ; preds = %162, %157
%167 = call i32 (...) @RequestGroundSensor()
br label %171
168: ; preds = %162
%169 = load i32, i32* %13
%170 = call i32 @RequestBeaconSensor(i32 %169)
br label %171
171: ; preds = %168, %166
br label %174
172: ; preds = %151
%173 = call i32 @RequestSensors(i32 2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i64 0, i64 0))
br label %174
174: ; preds = %172, %171
br label %87
}

LLVM IR (-O2):
@__const.main.host = [100 x i8] c"localhost\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.rob_name = [20 x i8] c"robsample\00\00\00\00\00\00\00\00\00\00\00"
@.str.1 = [6 x i8] c"-host\00"
@.str.2 = [9 x i8] c"-robname\00"
@.str.3 = [5 x i8] c"-pos\00"
@.str.4 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.5 = [99 x i8] c"Bad number of parameters\0ASYNOPSIS: mainRob [-host hostname] [-robname robotname] [-pos posnumber]\0A\00"
@.str.6 = [22 x i8] c"%s Failed to connect\0A\00"
@.str.7 = [14 x i8] c"%s Connected\0A\00"
@.str.8 = [12 x i8] c"%s Exiting\0A\00"
@.str.9 = [25 x i8] c"%s visited target at %d\0A\00"
@.str.10 = [21 x i8] c"%s found home at %d\0A\00"
@.str.11 = [10 x i8] c"IRSensor1\00"
@.str.12 = [10 x i8] c"IRSensor2\00"
@str = [62 x i8] c" Sample Robot\0A Copyright (C) 2001-2013 Universidade de Aveiro\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = alloca [20 x i8]
%5 = alloca float
%6 = alloca float
%7 = alloca i32
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%10 = bitcast float* %5 to i8*
%11 = bitcast float* %6 to i8*
%12 = bitcast i32* %7 to i8*
store i32 1, i32* %7
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str, i64 0, i64 0))
%14 = icmp sgt i32 %0, 2
br i1 %14, label %15, label %52
15: ; preds = %2
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 19
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 99
br label %18
18: ; preds = %15, %48
%19 = phi i32 [ %0, %15 ], [ %49, %48 ]
%20 = phi i8** [ %1, %15 ], [ %50, %48 ]
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = getelementptr inbounds i8*, i8** %20, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @strncpy(i8* %8, i8* %27, i32 99)
br label %46
29: ; preds = %18
%30 = load i8*, i8** %21
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = getelementptr inbounds i8*, i8** %20, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @strncpy(i8* %9, i8* %35, i32 19)
br label %46
37: ; preds = %29
%38 = load i8*, i8** %21
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %55
41: ; preds = %37
%42 = getelementptr inbounds i8*, i8** %20, i64 2
%43 = load i8*, i8** %42
%44 = call i32 @sscanf(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %7)
%45 = icmp eq i32 %44, 1
br i1 %45, label %48, label %55
46: ; preds = %25, %33
%47 = phi i8* [ %16, %33 ], [ %17, %25 ]
store i8 0, i8* %47
br label %48
48: ; preds = %46, %41
%49 = add nsw i32 %19, -2
%50 = getelementptr inbounds i8*, i8** %20, i64 2
%51 = icmp ugt i32 %19, 4
br i1 %51, label %18, label %52
52: ; preds = %48, %2
%53 = phi i32 [ %0, %2 ], [ %49, %48 ]
%54 = icmp eq i32 %53, 1
br i1 %54, label %58, label %55
55: ; preds = %41, %37, %52
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.5, i64 0, i64 0))
ret i32 1
58: ; preds = %52
%59 = load i32, i32* %7
%60 = call i32 @InitRobot(i8* %9, i32 %59, i8* %8)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %65
62: ; preds = %58
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %9)
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %58
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %9)
%67 = call i32 (...) @ReadSensors()
%68 = call i64 (...) @GetFinished()
%69 = icmp eq i64 %68, 0
br i1 %69, label %73, label %70
70: ; preds = %140, %65
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %9)
%72 = call i32 @exit(i32 0)
unreachable
73: ; preds = %65, %140
%74 = phi i32 [ %120, %140 ], [ 1, %65 ]
%75 = phi i32 [ %121, %140 ], [ 2, %65 ]
%76 = icmp eq i32 %75, 2
br i1 %76, label %77, label %82
77: ; preds = %73
%78 = call i64 (...) @GetStartButton()
%79 = icmp eq i64 %78, 0
%80 = icmp eq i32 %74, 2
%81 = select i1 %79, i1 true, i1 %80
br i1 %81, label %119, label %82
82: ; preds = %77, %73
%83 = phi i32 [ %75, %73 ], [ %74, %77 ]
%84 = call i64 (...) @GetStopButton()
%85 = icmp eq i64 %84, 0
br i1 %85, label %86, label %119
86: ; preds = %82
switch i32 %83, label %119 [
i32 1, label %87
i32 3, label %102
i32 4, label %107
]
87: ; preds = %86
%88 = call i32 (...) @GetVisitingLed()
%89 = icmp eq i32 %88, 0
%90 = select i1 %89, i32 1, i32 3
%91 = call i32 (...) @GetGroundSensor()
%92 = icmp eq i32 %91, 0
br i1 %92, label %93, label %97
93: ; preds = %87
%94 = call i32 @SetVisitingLed(i32 1)
%95 = call i32 (...) @GetTime()
%96 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i8* %9, i32 %95)
br label %119
97: ; preds = %87
%98 = call i32 @DetermineAction(i32 0, float* %5, float* %6)
%99 = load float, float* %5
%100 = load float, float* %6
%101 = call i32 @DriveMotors(float %99, float %100)
br label %119
102: ; preds = %86
%103 = call i32 (...) @GetReturningLed()
%104 = icmp eq i32 %103, 0
%105 = select i1 %104, i32 3, i32 4
%106 = call i32 @DriveMotors(float 0.000000e+00, float 0.000000e+00)
br label %119
107: ; preds = %86
%108 = call i32 (...) @GetGroundSensor()
%109 = icmp eq i32 %108, 1
br i1 %109, label %110, label %114
110: ; preds = %107
%111 = call i32 (...) @Finish()
%112 = call i32 (...) @GetTime()
%113 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i8* %9, i32 %112)
br label %119
114: ; preds = %107
%115 = call i32 @DetermineAction(i32 1, float* %5, float* %6)
%116 = load float, float* %5
%117 = load float, float* %6
%118 = call i32 @DriveMotors(float %116, float %117)
br label %119
119: ; preds = %77, %82, %110, %114, %93, %97, %86, %102
%120 = phi i32 [ %74, %86 ], [ %74, %110 ], [ %74, %114 ], [ %74, %102 ], [ %74, %93 ], [ %74, %97 ], [ %83, %82 ], [ %74, %77 ]
%121 = phi i32 [ %83, %86 ], [ 4, %110 ], [ 4, %114 ], [ %105, %102 ], [ %90, %93 ], [ %90, %97 ], [ 2, %82 ], [ 2, %77 ]
%122 = call i32 @Say(i8* %9)
%123 = call i32 (...) @GetTime()
%124 = and i32 %123, 1
%125 = icmp eq i32 %124, 0
br i1 %125, label %126, label %138
126: ; preds = %119
%127 = call i32 @RequestObstacleSensor(i32 0)
%128 = call i32 (...) @GetTime()
%129 = and i32 %128, 7
%130 = icmp eq i32 %129, 0
br i1 %130, label %134, label %131
131: ; preds = %126
%132 = call i32 (...) @GetNumberOfBeacons()
%133 = icmp eq i32 %132, 0
br i1 %133, label %134, label %136
134: ; preds = %131, %126
%135 = call i32 (...) @RequestGroundSensor()
br label %140
136: ; preds = %131
%137 = call i32 @RequestBeaconSensor(i32 0)
br label %140
138: ; preds = %119
%139 = call i32 @RequestSensors(i32 2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i64 0, i64 0))
br label %140
140: ; preds = %134, %136, %138
%141 = call i32 (...) @ReadSensors()
%142 = call i64 (...) @GetFinished()
%143 = icmp eq i64 %142, 0
br i1 %143, label %73, label %70
}