#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 {
  unsigned int tv_sec;
  unsigned int tv_usec;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
int FILENAME_MAX;
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ getpid();
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ usleep(unsigned int);
int /*<<< orphan*/ write_to_file(char *, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int count, i = 0, iteration = 0;
  int fail = 0, ALLOWED;
  char mytaskfile[FILENAME_MAX];
  int test_num;
  struct timeval prev_time, cur_time;
  unsigned int actual, actual_s, actual_us, sleeptime;
  unsigned int delta, delta_max = 0;
  pid_t script_pid;
  if ((argc < 4) || (argc > 5)) {
    printf("Invalid #args received from script. Exiting test..\n");
    exit(1);
  }
  test_num = atoi(argv[1]);
  script_pid = (pid_t)atoi(argv[2]);
  ALLOWED = atoi(argv[3]);
  if ((test_num < 0) || (script_pid < 0) || (ALLOWED < 0)) {
    printf("Invalid args received from script. Exiting test..\n");
    exit(1);
  }
  if (test_num == 2) {
    strncpy(mytaskfile, argv[4], FILENAME_MAX);
    strncat(mytaskfile, "/tasks", FILENAME_MAX - strlen(mytaskfile) - 1);
    write_to_file(mytaskfile, "a", getpid());
    sleep(8);
  }
  printf("TINFO \tThe latency check task started\n");
  for (count = 200; count >= 0; count -= 1) {
    if (gettimeofday(&prev_time, NULL) == -1)
      perror("In Iteration no 1 \n");
    sleeptime = count * 1000;
    usleep(sleeptime);
    if (gettimeofday(&cur_time, NULL) == -1)
      perror("In Iteration no 1 \n");
    actual_s = cur_time.tv_sec - prev_time.tv_sec;
    actual_us = cur_time.tv_usec - prev_time.tv_usec;
    actual = 1e6 * actual_s + actual_us;
    delta = actual - sleeptime;
    if (delta >= delta_max) {
      delta_max = delta;
      iteration = i;
    }
    if (delta > ALLOWED)
      fail = 1;
    do {
    } while (0);
    ;
  }
  if (fail) {
    printf("FAIL \tThe Latency test %d failed\n", test_num);
    printf("Max latency observed = %u in Iteration %d\n", delta_max, iteration);
    printf("The results FAIL is just intuitive and not exact"
           " failure. Please look at cpuctl_testplan.txt in the test "
           "directory.\n");
    ;
  } else {
    printf("PASS \tThe Latency test %d passed\n", test_num);
    printf("Max latency observed = %u microsec in Iteration %d\n", delta_max,
           iteration);
  }
  return fail;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x78(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x68(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     1235 <main+0x75>
cmpl   $0x5,-0x8(%rbp)
jle    124d <main+0x8d>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
cltq
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jl     129f <main+0xdf>
cmpq   $0x0,-0x70(%rbp)
jl     129f <main+0xdf>
cmpl   $0x0,-0x24(%rbp)
jge    12b7 <main+0xf7>
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
cmpl   $0x2,-0x3c(%rbp)
jne    132b <main+0x16b>
mov    -0x78(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rsi
mov    0x2d14(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    -0x78(%rbp),%rdi
mov    0x2d02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
call   1050 <strlen@plt>
mov    -0x7c(%rbp),%edx
mov    -0x78(%rbp),%rdi
sub    %eax,%edx
sub    $0x1,%edx
lea    0xd6c(%rip),%rsi
call   1090 <strncat@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x78(%rbp),%rdi
mov    %eax,%edx
lea    0xd5a(%rip),%rsi
call   1070 <write_to_file@plt>
mov    $0x8,%edi
call   10d0 <sleep@plt>
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xc8,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1434 <main+0x274>
lea    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
cmp    $0xffffffff,%eax
jne    136c <main+0x1ac>
lea    0xd38(%rip),%rdi
call   10a0 <perror@plt>
imul   $0x3e8,-0x14(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%edi
call   10e0 <usleep@plt>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
cmp    $0xffffffff,%eax
jne    13a0 <main+0x1e0>
lea    0xd04(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x50(%rbp),%eax
mov    -0x48(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x58(%rbp)
mov    -0x4c(%rbp),%eax
mov    -0x44(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x58(%rbp),%eax
cvtsi2sd %rax,%xmm0
mov    -0x5c(%rbp),%eax
cvtsi2sd %rax,%xmm1
movsd  0xc32(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
sub    -0x60(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x68(%rbp),%eax
jb     13ff <main+0x23f>
mov    -0x64(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x24(%rbp),%eax
jbe    1412 <main+0x252>
movl   $0x1,-0x20(%rbp)
jmp    1417 <main+0x257>
jmp    141c <main+0x25c>
jmp    1421 <main+0x261>
jmp    1426 <main+0x266>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1340 <main+0x180>
cmpl   $0x0,-0x20(%rbp)
je     1476 <main+0x2b6>
mov    -0x3c(%rbp),%esi
lea    0xc6b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x68(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xc79(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xc96(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    149b <main+0x2db>
mov    -0x3c(%rbp),%esi
lea    0xcf5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x68(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xd03(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e00(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
add    $0xfffffffa,%edi
cmp    $0xfffffffd,%edi
jbe    13fa <main+0x22a>
mov    %rsi,%r12
mov    0x8(%rsi),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r15d
mov    0x10(%r12),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r13d
mov    0x18(%r12),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    %r15d,-0x2c(%rbp)
test   %r15d,%r15d
js     1403 <main+0x233>
test   %r13d,%r13d
js     1403 <main+0x233>
cmpl   $0x0,-0x30(%rbp)
js     1403 <main+0x233>
cmpl   $0x2,-0x2c(%rbp)
jne    12b2 <main+0xe2>
mov    0x20(%r12),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1030 <strncpy@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%r14d
mov    %rbx,%rdi
call   1060 <strlen@plt>
not    %eax
add    %eax,%r14d
lea    0xd83(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   10a0 <strncat@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xd71(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1080 <write_to_file@plt>
mov    $0x8,%edi
call   10e0 <sleep@plt>
lea    0xe0f(%rip),%rdi
call   1040 <puts@plt>
xor    %r12d,%r12d
mov    $0x30d40,%ebx
mov    $0xfffcf2c0,%r14d
xor    %r13d,%r13d
jmp    12fc <main+0x12c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xfffffc18,%ebx
add    $0x3e8,%r14d
mov    %r15d,%r13d
cmp    $0xfffffc18,%ebx
je     138d <main+0x1bd>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
call   1090 <gettimeofday@plt>
cmp    $0xffffffff,%eax
je     1371 <main+0x1a1>
mov    %ebx,%edi
call   10f0 <usleep@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
call   1090 <gettimeofday@plt>
cmp    $0xffffffff,%eax
je     137f <main+0x1af>
mov    -0x38(%rbp),%eax
mov    -0x34(%rbp),%ecx
sub    -0x40(%rbp),%eax
sub    -0x3c(%rbp),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %rcx,%xmm1
mulsd  0xcb9(%rip),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
add    %r14d,%eax
cmp    %r12d,%eax
cmovae %eax,%r12d
mov    $0x1,%r15d
cmp    -0x30(%rbp),%eax
ja     12e0 <main+0x110>
mov    %r13d,%r15d
jmp    12e0 <main+0x110>
lea    0xc99(%rip),%rdi
call   10b0 <perror@plt>
jmp    130c <main+0x13c>
lea    0xc8b(%rip),%rdi
call   10b0 <perror@plt>
jmp    1323 <main+0x153>
test   %r15d,%r15d
je     13c4 <main+0x1f4>
lea    0xc8c(%rip),%rdi
mov    -0x2c(%rbp),%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xc9d(%rip),%rdi
mov    %r12d,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd31(%rip),%rdi
call   1040 <puts@plt>
jmp    13e8 <main+0x218>
lea    0xca7(%rip),%rdi
mov    -0x2c(%rbp),%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xcb8(%rip),%rdi
mov    %r12d,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd93(%rip),%rdi
jmp    140a <main+0x23a>
lea    0xd58(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@FILENAME_MAX = global i32 0
@.str = [52 x i8] c"Invalid #args received from script. Exiting test..\0A\00"
@.str.1 = [51 x i8] c"Invalid args received from script. Exiting test..\0A\00"
@.str.2 = [7 x i8] c"/tasks\00"
@.str.3 = [2 x i8] c"a\00"
@.str.4 = [39 x i8] c"TINFO \09The latency check task started\0A\00"
@.str.5 = [20 x i8] c"In Iteration no 1 \0A\00"
@.str.6 = [34 x i8] c"FAIL \09The Latency test %d failed\0A\00"
@.str.7 = [43 x i8] c"Max latency observed = %u in Iteration %d\0A\00"
@.str.8 = [117 x i8] c"The results FAIL is just intuitive and not exact failure. Please look at cpuctl_testplan.txt in the test directory.\0A\00"
@.str.9 = [34 x i8] c"PASS \09The Latency test %d passed\0A\00"
@.str.10 = [52 x i8] c"Max latency observed = %u microsec in Iteration %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
%14 = alloca %struct.timeval
%15 = alloca %struct.timeval
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%23 = load i32, i32* @FILENAME_MAX
%24 = zext i32 %23 to i64
%25 = call i8* @llvm.stacksave()
store i8* %25, i8** %11
%26 = alloca i8, i64 %24
store i64 %24, i64* %12
store i32 0, i32* %21
%27 = load i32, i32* %4
%28 = icmp slt i32 %27, 4
br i1 %28, label %32, label %29
29: ; preds = %2
%30 = load i32, i32* %4
%31 = icmp sgt i32 %30, 5
br i1 %31, label %32, label %35
32: ; preds = %29, %2
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %29
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
store i32 %39, i32* %13
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i32 @atoi(i8* %42)
%44 = sext i32 %43 to i64
store i64 %44, i64* %22
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 3
%47 = load i8*, i8** %46
%48 = call i32 @atoi(i8* %47)
store i32 %48, i32* %10
%49 = load i32, i32* %13
%50 = icmp slt i32 %49, 0
br i1 %50, label %57, label %51
51: ; preds = %35
%52 = load i64, i64* %22
%53 = icmp slt i64 %52, 0
br i1 %53, label %57, label %54
54: ; preds = %51
%55 = load i32, i32* %10
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %54, %51, %35
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %54
%61 = load i32, i32* %13
%62 = icmp eq i32 %61, 2
br i1 %62, label %63, label %77
63: ; preds = %60
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 4
%66 = load i8*, i8** %65
%67 = load i32, i32* @FILENAME_MAX
%68 = call i32 @strncpy(i8* %26, i8* %66, i32 %67)
%69 = load i32, i32* @FILENAME_MAX
%70 = call i32 @strlen(i8* %26)
%71 = sub nsw i32 %69, %70
%72 = sub nsw i32 %71, 1
%73 = call i32 @strncat(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %72)
%74 = call i32 (...) @getpid()
%75 = call i32 @write_to_file(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %74)
%76 = call i32 @sleep(i32 8)
br label %77
77: ; preds = %63, %60
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
store i32 200, i32* %6
br label %79
79: ; preds = %131, %77
%80 = load i32, i32* %6
%81 = icmp sge i32 %80, 0
br i1 %81, label %82, label %134
82: ; preds = %79
%83 = call i32 @gettimeofday(%struct.timeval* %14, i32* null)
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %87
85: ; preds = %82
%86 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %87
87: ; preds = %85, %82
%88 = load i32, i32* %6
%89 = mul nsw i32 %88, 1000
store i32 %89, i32* %19
%90 = load i32, i32* %19
%91 = call i32 @usleep(i32 %90)
%92 = call i32 @gettimeofday(%struct.timeval* %15, i32* null)
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %96
94: ; preds = %87
%95 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %96
96: ; preds = %94, %87
%97 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%98 = load i32, i32* %97
%99 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%100 = load i32, i32* %99
%101 = sub i32 %98, %100
store i32 %101, i32* %17
%102 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
%103 = load i32, i32* %102
%104 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%105 = load i32, i32* %104
%106 = sub i32 %103, %105
store i32 %106, i32* %18
%107 = load i32, i32* %17
%108 = uitofp i32 %107 to double
%109 = load i32, i32* %18
%110 = uitofp i32 %109 to double
%111 = call double @llvm.fmuladd.f64(double 1.000000e+06, double %108, double %110)
%112 = fptoui double %111 to i32
store i32 %112, i32* %16
%113 = load i32, i32* %16
%114 = load i32, i32* %19
%115 = sub i32 %113, %114
store i32 %115, i32* %20
%116 = load i32, i32* %20
%117 = load i32, i32* %21
%118 = icmp uge i32 %116, %117
br i1 %118, label %119, label %122
119: ; preds = %96
%120 = load i32, i32* %20
store i32 %120, i32* %21
%121 = load i32, i32* %7
store i32 %121, i32* %8
br label %122
122: ; preds = %119, %96
%123 = load i32, i32* %20
%124 = load i32, i32* %10
%125 = icmp ugt i32 %123, %124
br i1 %125, label %126, label %127
126: ; preds = %122
store i32 1, i32* %9
br label %127
127: ; preds = %126, %122
br label %128
128: ; preds = %127
br label %129
129: ; preds = %128
br label %130
130: ; preds = %129
br label %131
131: ; preds = %130
%132 = load i32, i32* %6
%133 = sub nsw i32 %132, 1
store i32 %133, i32* %6
br label %79
134: ; preds = %79
%135 = load i32, i32* %9
%136 = icmp ne i32 %135, 0
br i1 %136, label %137, label %144
137: ; preds = %134
%138 = load i32, i32* %13
%139 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 %138)
%140 = load i32, i32* %21
%141 = load i32, i32* %8
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0), i32 %140, i32 %141)
%143 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([117 x i8], [117 x i8]* @.str.8, i64 0, i64 0))
br label %150
144: ; preds = %134
%145 = load i32, i32* %13
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0), i32 %145)
%147 = load i32, i32* %21
%148 = load i32, i32* %8
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.10, i64 0, i64 0), i32 %147, i32 %148)
br label %150
150: ; preds = %144, %137
%151 = load i32, i32* %9
store i32 %151, i32* %3
%152 = load i8*, i8** %11
%153 = load i32, i32* %3
ret i32 %153
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@FILENAME_MAX = global i32 0
@.str.2 = [7 x i8] c"/tasks\00"
@.str.3 = [2 x i8] c"a\00"
@.str.5 = [20 x i8] c"In Iteration no 1 \0A\00"
@.str.6 = [34 x i8] c"FAIL \09The Latency test %d failed\0A\00"
@.str.7 = [43 x i8] c"Max latency observed = %u in Iteration %d\0A\00"
@.str.9 = [34 x i8] c"PASS \09The Latency test %d passed\0A\00"
@.str.10 = [52 x i8] c"Max latency observed = %u microsec in Iteration %d\0A\00"
@str = [38 x i8] c"TINFO \09The latency check task started\00"
@str.11 = [116 x i8] c"The results FAIL is just intuitive and not exact failure. Please look at cpuctl_testplan.txt in the test directory.\00"
@str.12 = [50 x i8] c"Invalid args received from script. Exiting test..\00"
@str.13 = [51 x i8] c"Invalid #args received from script. Exiting test..\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = load i32, i32* @FILENAME_MAX
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = bitcast %struct.timeval* %3 to i8*
%9 = bitcast %struct.timeval* %4 to i8*
%10 = add i32 %0, -6
%11 = icmp ult i32 %10, -2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.13, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = getelementptr inbounds i8*, i8** %1, i64 3
%23 = load i8*, i8** %22
%24 = tail call i32 @atoi(i8* %23)
%25 = icmp slt i32 %18, 0
%26 = icmp slt i32 %21, 0
%27 = select i1 %25, i1 true, i1 %26
%28 = icmp slt i32 %24, 0
%29 = select i1 %27, i1 true, i1 %28
br i1 %29, label %30, label %33
30: ; preds = %15
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.12, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %15
%34 = icmp eq i32 %18, 2
br i1 %34, label %35, label %47
35: ; preds = %33
%36 = getelementptr inbounds i8*, i8** %1, i64 4
%37 = load i8*, i8** %36
%38 = call i32 @strncpy(i8* %7, i8* %37, i32 %5)
%39 = load i32, i32* @FILENAME_MAX
%40 = call i32 @strlen(i8* %7)
%41 = xor i32 %40, -1
%42 = add i32 %39, %41
%43 = call i32 @strncat(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = call i32 (...) @getpid()
%45 = call i32 @write_to_file(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%46 = call i32 @sleep(i32 8)
br label %47
47: ; preds = %35, %33
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%51 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%52 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
br label %53
53: ; preds = %47, %68
%54 = phi i32 [ 0, %47 ], [ %81, %68 ]
%55 = phi i32 [ 200, %47 ], [ %84, %68 ]
%56 = phi i32 [ 0, %47 ], [ %83, %68 ]
%57 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %61
59: ; preds = %53
%60 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %61
61: ; preds = %59, %53
%62 = mul nuw nsw i32 %55, 1000
%63 = call i32 @usleep(i32 %62)
%64 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %68
66: ; preds = %61
%67 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %68
68: ; preds = %66, %61
%69 = load i32, i32* %49
%70 = load i32, i32* %50
%71 = sub i32 %69, %70
%72 = load i32, i32* %51
%73 = load i32, i32* %52
%74 = sub i32 %72, %73
%75 = uitofp i32 %71 to double
%76 = uitofp i32 %74 to double
%77 = call double @llvm.fmuladd.f64(double %75, double 1.000000e+06, double %76)
%78 = fptoui double %77 to i32
%79 = sub i32 %78, %62
%80 = icmp ult i32 %79, %54
%81 = select i1 %80, i32 %54, i32 %79
%82 = icmp ugt i32 %79, %24
%83 = select i1 %82, i32 1, i32 %56
%84 = add nsw i32 %55, -1
%85 = icmp eq i32 %55, 0
br i1 %85, label %86, label %53
86: ; preds = %68
%87 = icmp eq i32 %83, 0
br i1 %87, label %92, label %88
88: ; preds = %86
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 %18)
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0), i32 %81, i32 0)
%91 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([116 x i8], [116 x i8]* @str.11, i64 0, i64 0))
br label %95
92: ; preds = %86
%93 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0), i32 %18)
%94 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.10, i64 0, i64 0), i32 %81, i32 0)
br label %95
95: ; preds = %92, %88
ret i32 %83
}