#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_sec;
  unsigned int tv_usec;
};
struct timespec {
  unsigned int tv_sec;
  unsigned int tv_nsec;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int nanosleep(struct timespec *, int /*<<< orphan*/ *);
int select(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int usleep(unsigned int);
int main(int argc, char **argv) {
  unsigned int nTimeTestSec = 0;
  unsigned int nTimeTest = 0;
  struct timeval tvBegin;
  struct timeval tvNow;
  int ret = 0;
  unsigned int nDelay = 0;
  fd_set rfds;
  struct timeval tv;
  int fd = 1;
  int i = 0;
  struct timespec req;
  unsigned int delay[20] = {500000, 100000, 50000, 10000, 1000, 900,
                            500,    100,    10,    1,     0};
  int nReduce = 0;
  fprintf(stderr, "%18s%12s%12s%12s\n", "function", "time(usec)", "realTime",
          "reduce");
  fprintf(
      stderr,
      "-------------------------------------------------------------------\n");
  for (i = 0; i < 20; i++) {
    if (delay[i] <= 0)
      break;
    nDelay = delay[i];
    gettimeofday(&tvBegin, NULL);
    ret = usleep(nDelay);
    if (-1 == ret) {
      fprintf(stderr, " usleep error . errno=%d [%s]\n", errno,
              strerror(errno));
    }
    gettimeofday(&tvNow, NULL);
    nTimeTest = (tvNow.tv_sec - tvBegin.tv_sec) * 1000000 + tvNow.tv_usec -
                tvBegin.tv_usec;
    nReduce = nTimeTest - nDelay;
    fprintf(stderr, "\t usleep       %8u   %8u   %8d\n", nDelay, nTimeTest,
            nReduce);
    gettimeofday(&tvBegin, NULL);
    req.tv_sec = nDelay / 1000000;
    req.tv_nsec = (nDelay % 1000000) * 1000;
    ret = nanosleep(&req, NULL);
    if (-1 == ret) {
      fprintf(stderr, "\t nanosleep    %8u   not support\n", nDelay);
    } else {
      gettimeofday(&tvNow, NULL);
      nTimeTest = (tvNow.tv_sec - tvBegin.tv_sec) * 1000000 + tvNow.tv_usec -
                  tvBegin.tv_usec;
      nReduce = nTimeTest - nDelay;
      fprintf(stderr, "\t nanosleep    %8u   %8u   %8d\n", nDelay, nTimeTest,
              nReduce);
    }
    gettimeofday(&tvBegin, NULL);
    FD_ZERO(&rfds);
    FD_SET(fd, &rfds);
    tv.tv_sec = 0;
    tv.tv_usec = nDelay;
    ret = select(0, NULL, NULL, NULL, &tv);
    if (-1 == ret) {
      fprintf(stderr, " select error . errno=%d [%s]\n", errno,
              strerror(errno));
    }
    gettimeofday(&tvNow, NULL);
    nTimeTest = (tvNow.tv_sec - tvBegin.tv_sec) * 1000000 + tvNow.tv_usec -
                tvBegin.tv_usec;
    nReduce = nTimeTest - nDelay;
    fprintf(stderr, "\t select       %8u   %8u   %8d\n", nDelay, nTimeTest,
            nReduce);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x1,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0xe1f(%rip),%rsi
mov    $0x50,%edx
call   1060 <memcpy@plt>
movl   $0x0,-0xa4(%rbp)
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
lea    0xe56(%rip),%rdx
lea    0xe58(%rip),%rcx
lea    0xe5c(%rip),%r8
lea    0xe5e(%rip),%r9
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x48(%rbp)
cmpl   $0x14,-0x48(%rbp)
jge    14f4 <main+0x364>
movslq -0x48(%rbp),%rax
cmpl   $0x0,-0xa0(%rbp,%rax,4)
ja     1267 <main+0xd7>
jmp    14f4 <main+0x364>
movslq -0x48(%rbp),%rax
mov    -0xa0(%rbp,%rax,4),%eax
mov    %eax,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x30(%rbp),%edi
call   10b0 <usleep@plt>
mov    %eax,-0x2c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x2c(%rbp),%eax
jne    12e4 <main+0x154>
mov    0x2d3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    0x2d27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa8(%rbp)
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0xac(%rbp),%edi
mov    -0xa8(%rbp),%edx
mov    %rax,%rcx
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x28(%rbp),%eax
sub    -0x20(%rbp),%eax
imul   $0xf4240,%eax,%eax
add    -0x24(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x30(%rbp),%eax
mov    %eax,-0xa4(%rbp)
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0xa4(%rbp),%r8d
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x30(%rbp),%eax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x50(%rbp)
mov    -0x30(%rbp),%eax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %ecx
imul   $0x3e8,%edx,%eax
mov    %eax,-0x4c(%rbp)
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <nanosleep@plt>
mov    %eax,-0x2c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x2c(%rbp),%eax
jne    13a4 <main+0x214>
mov    0x2c54(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
lea    0xd72(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    13f6 <main+0x266>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x28(%rbp),%eax
sub    -0x20(%rbp),%eax
imul   $0xf4240,%eax,%eax
add    -0x24(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x30(%rbp),%eax
mov    %eax,-0xa4(%rbp)
mov    0x2c07(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0xa4(%rbp),%r8d
lea    0xd3d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x34(%rbp),%rdi
call   1070 <FD_ZERO@plt>
mov    -0x44(%rbp),%edi
lea    -0x34(%rbp),%rsi
call   10a0 <FD_SET@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x3c(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x40(%rbp),%r8
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1080 <select@plt>
mov    %eax,-0x2c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x2c(%rbp),%eax
jne    1494 <main+0x304>
mov    0x2b8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb4(%rbp)
mov    0x2b77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb0(%rbp)
mov    0x2b68(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0xb4(%rbp),%edi
mov    -0xb0(%rbp),%edx
mov    %rax,%rcx
lea    0xcbf(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x28(%rbp),%eax
sub    -0x20(%rbp),%eax
imul   $0xf4240,%eax,%eax
add    -0x24(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x30(%rbp),%eax
mov    %eax,-0xa4(%rbp)
mov    0x2b17(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0xa4(%rbp),%r8d
lea    0xc8c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1246 <main+0xb6>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2e4b(%rip),%r13
mov    0x0(%r13),%edi
lea    0xeb0(%rip),%rsi
lea    0xebb(%rip),%rdx
lea    0xebd(%rip),%rcx
lea    0xec1(%rip),%r8
lea    0xec3(%rip),%r9
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xeb8(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x7a120,%ebp
mov    $0x1,%r14d
lea    0x8(%rsp),%r15
mov    %rsp,%r12
jmp    1242 <main+0xc2>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    (%rsp),%eax
sub    0x8(%rsp),%eax
imul   $0xf4240,%eax,%ecx
add    0x4(%rsp),%ecx
sub    0xc(%rsp),%ecx
mov    %ecx,%r8d
sub    %ebp,%r8d
mov    0x0(%r13),%edi
lea    0xf4b(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xdd0(%rip),%rax
mov    (%rax,%r14,4),%ebp
add    $0x1,%r14
cmp    $0xb,%r14
je     13e8 <main+0x268>
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    %ebp,%edi
call   10a0 <usleep@plt>
cmp    $0xffffffff,%eax
jne    128f <main+0x10f>
mov    0x0(%r13),%r12d
mov    0x2d75(%rip),%rax
mov    (%rax),%r13d
mov    %r13d,%edi
call   1080 <strerror@plt>
mov    %r12d,%edi
mov    %rsp,%r12
lea    0xe50(%rip),%rsi
mov    %r13d,%edx
mov    0x2d5b(%rip),%r13
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r12,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    (%rsp),%eax
sub    0x8(%rsp),%eax
imul   $0xf4240,%eax,%ecx
add    0x4(%rsp),%ecx
sub    0xc(%rsp),%ecx
mov    %ecx,%r8d
sub    %ebp,%r8d
mov    0x0(%r13),%edi
lea    0xe2b(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    %ebp,%eax
imul   $0x431bde83,%rax,%rax
shr    $0x32,%rax
mov    %eax,0x10(%rsp)
imul   $0xf4240,%eax,%eax
mov    %ebp,%ecx
sub    %eax,%ecx
imul   $0x3e8,%ecx,%eax
mov    %eax,0x14(%rsp)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
cmp    $0xffffffff,%eax
je     1350 <main+0x1d0>
mov    %r12,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    (%rsp),%eax
sub    0x8(%rsp),%eax
imul   $0xf4240,%eax,%ecx
add    0x4(%rsp),%ecx
sub    0xc(%rsp),%ecx
mov    %ecx,%r8d
sub    %ebp,%r8d
mov    0x0(%r13),%edi
lea    0xdf4(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1364 <main+0x1e4>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%r13),%edi
lea    0xdaf(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0x24(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <FD_ZERO@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
call   1090 <FD_SET@plt>
movl   $0x0,0x18(%rsp)
mov    %ebp,0x1c(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
lea    0x18(%rsp),%r8
call   1070 <select@plt>
cmp    $0xffffffff,%eax
jne    11f0 <main+0x70>
mov    0x0(%r13),%r12d
mov    0x2c1e(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1080 <strerror@plt>
mov    %r12d,%edi
mov    %rsp,%r12
lea    0xd7c(%rip),%rsi
mov    %ebx,%edx
mov    0x2c07(%rip),%r13
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11f0 <main+0x70>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.timespec = type { i32, i32 }
@__const.main.delay = <{ [10 x i32], [10 x i32] }> <{ [10 x i32] [i32 500000, i32 100000, i32 50000, i32 10000, i32 1000, i32 900, i32 500, i32 100, i32 10, i32 1], [10 x i32] zeroinitializer }>
@stderr = global i32 0
@.str = [18 x i8] c"%18s%12s%12s%12s\0A\00"
@.str.1 = [9 x i8] c"function\00"
@.str.2 = [11 x i8] c"time(usec)\00"
@.str.3 = [9 x i8] c"realTime\00"
@.str.4 = [7 x i8] c"reduce\00"
@.str.5 = [69 x i8] c"-------------------------------------------------------------------\0A\00"
@.str.6 = [31 x i8] c" usleep error . errno=%d [%s]\0A\00"
@errno = global i32 0
@.str.7 = [32 x i8] c"\09 usleep %8u %8u %8d\0A\00"
@.str.8 = [34 x i8] c"\09 nanosleep %8u not support\0A\00"
@.str.9 = [32 x i8] c"\09 nanosleep %8u %8u %8d\0A\00"
@.str.10 = [31 x i8] c" select error . errno=%d [%s]\0A\00"
@.str.11 = [32 x i8] c"\09 select %8u %8u %8d\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 %struct.timeval
%9 = alloca %struct.timeval
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.timeval
%14 = alloca i32
%15 = alloca i32
%16 = alloca %struct.timespec
%17 = alloca [20 x i32]
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %10
store i32 0, i32* %11
store i32 1, i32* %14
store i32 0, i32* %15
%19 = bitcast [20 x i32]* %17 to i8*
store i32 0, i32* %18
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %15
br label %24
24: ; preds = %148, %2
%25 = load i32, i32* %15
%26 = icmp slt i32 %25, 20
br i1 %26, label %27, label %151
27: ; preds = %24
%28 = load i32, i32* %15
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [20 x i32], [20 x i32]* %17, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = icmp ule i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27
br label %151
34: ; preds = %27
%35 = load i32, i32* %15
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [20 x i32], [20 x i32]* %17, i64 0, i64 %36
%38 = load i32, i32* %37
store i32 %38, i32* %11
%39 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%40 = load i32, i32* %11
%41 = call i32 @usleep(i32 %40)
store i32 %41, i32* %10
%42 = load i32, i32* %10
%43 = icmp eq i32 -1, %42
br i1 %43, label %44, label %50
44: ; preds = %34
%45 = load i32, i32* @stderr
%46 = load i32, i32* @errno
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %46, i8* %48)
br label %50
50: ; preds = %44, %34
%51 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%52 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%53 = load i32, i32* %52
%54 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%55 = load i32, i32* %54
%56 = sub nsw i32 %53, %55
%57 = mul nsw i32 %56, 1000000
%58 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%59 = load i32, i32* %58
%60 = add i32 %57, %59
%61 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%62 = load i32, i32* %61
%63 = sub i32 %60, %62
store i32 %63, i32* %7
%64 = load i32, i32* %7
%65 = load i32, i32* %11
%66 = sub i32 %64, %65
store i32 %66, i32* %18
%67 = load i32, i32* @stderr
%68 = load i32, i32* %11
%69 = load i32, i32* %7
%70 = load i32, i32* %18
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i32 %68, i32 %69, i32 %70)
%72 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%73 = load i32, i32* %11
%74 = udiv i32 %73, 1000000
%75 = getelementptr inbounds %struct.timespec, %struct.timespec* %16, i32 0, i32 0
store i32 %74, i32* %75
%76 = load i32, i32* %11
%77 = urem i32 %76, 1000000
%78 = mul i32 %77, 1000
%79 = getelementptr inbounds %struct.timespec, %struct.timespec* %16, i32 0, i32 1
store i32 %78, i32* %79
%80 = call i32 @nanosleep(%struct.timespec* %16, i32* null)
store i32 %80, i32* %10
%81 = load i32, i32* %10
%82 = icmp eq i32 -1, %81
br i1 %82, label %83, label %87
83: ; preds = %50
%84 = load i32, i32* @stderr
%85 = load i32, i32* %11
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i32 %85)
br label %109
87: ; preds = %50
%88 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%89 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%90 = load i32, i32* %89
%91 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%92 = load i32, i32* %91
%93 = sub nsw i32 %90, %92
%94 = mul nsw i32 %93, 1000000
%95 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%96 = load i32, i32* %95
%97 = add i32 %94, %96
%98 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%99 = load i32, i32* %98
%100 = sub i32 %97, %99
store i32 %100, i32* %7
%101 = load i32, i32* %7
%102 = load i32, i32* %11
%103 = sub i32 %101, %102
store i32 %103, i32* %18
%104 = load i32, i32* @stderr
%105 = load i32, i32* %11
%106 = load i32, i32* %7
%107 = load i32, i32* %18
%108 = call i32 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i32 %105, i32 %106, i32 %107)
br label %109
109: ; preds = %87, %83
%110 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%111 = call i32 @FD_ZERO(i32* %12)
%112 = load i32, i32* %14
%113 = call i32 @FD_SET(i32 %112, i32* %12)
%114 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
store i32 0, i32* %114
%115 = load i32, i32* %11
%116 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
store i32 %115, i32* %116
%117 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %13)
store i32 %117, i32* %10
%118 = load i32, i32* %10
%119 = icmp eq i32 -1, %118
br i1 %119, label %120, label %126
120: ; preds = %109
%121 = load i32, i32* @stderr
%122 = load i32, i32* @errno
%123 = load i32, i32* @errno
%124 = call i8* @strerror(i32 %123)
%125 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), i32 %122, i8* %124)
br label %126
126: ; preds = %120, %109
%127 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%128 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%129 = load i32, i32* %128
%130 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%131 = load i32, i32* %130
%132 = sub nsw i32 %129, %131
%133 = mul nsw i32 %132, 1000000
%134 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%135 = load i32, i32* %134
%136 = add i32 %133, %135
%137 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%138 = load i32, i32* %137
%139 = sub i32 %136, %138
store i32 %139, i32* %7
%140 = load i32, i32* %7
%141 = load i32, i32* %11
%142 = sub i32 %140, %141
store i32 %142, i32* %18
%143 = load i32, i32* @stderr
%144 = load i32, i32* %11
%145 = load i32, i32* %7
%146 = load i32, i32* %18
%147 = call i32 (i32, i8*, ...) @fprintf(i32 %143, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.11, i64 0, i64 0), i32 %144, i32 %145, i32 %146)
br label %148
148: ; preds = %126
%149 = load i32, i32* %15
%150 = add nsw i32 %149, 1
store i32 %150, i32* %15
br label %24
151: ; preds = %33, %24
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.timespec = type { i32, i32 }
@__const.main.delay = <{ [10 x i32], [10 x i32] }> <{ [10 x i32] [i32 500000, i32 100000, i32 50000, i32 10000, i32 1000, i32 900, i32 500, i32 100, i32 10, i32 1], [10 x i32] zeroinitializer }>
@stderr = global i32 0
@.str = [18 x i8] c"%18s%12s%12s%12s\0A\00"
@.str.1 = [9 x i8] c"function\00"
@.str.2 = [11 x i8] c"time(usec)\00"
@.str.3 = [9 x i8] c"realTime\00"
@.str.4 = [7 x i8] c"reduce\00"
@.str.5 = [69 x i8] c"-------------------------------------------------------------------\0A\00"
@.str.6 = [31 x i8] c" usleep error . errno=%d [%s]\0A\00"
@errno = global i32 0
@.str.7 = [32 x i8] c"\09 usleep %8u %8u %8d\0A\00"
@.str.8 = [34 x i8] c"\09 nanosleep %8u not support\0A\00"
@.str.9 = [32 x i8] c"\09 nanosleep %8u %8u %8d\0A\00"
@.str.10 = [31 x i8] c" select error . errno=%d [%s]\0A\00"
@.str.11 = [32 x i8] c"\09 select %8u %8u %8d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca i32
%6 = alloca %struct.timeval
%7 = alloca %struct.timespec
%8 = bitcast %struct.timeval* %3 to i8*
%9 = bitcast %struct.timeval* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast %struct.timeval* %6 to i8*
%12 = bitcast %struct.timespec* %7 to i8*
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.5, i64 0, i64 0))
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i64 0, i32 0
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i64 0, i32 1
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
br label %25
25: ; preds = %2, %82
%26 = phi i32 [ 500000, %2 ], [ %97, %82 ]
%27 = phi i64 [ 0, %2 ], [ %95, %82 ]
%28 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%29 = call i32 @usleep(i32 %26)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %36
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %33, i8* %34)
br label %36
36: ; preds = %31, %25
%37 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%38 = load i32, i32* %17
%39 = load i32, i32* %18
%40 = sub nsw i32 %38, %39
%41 = mul nsw i32 %40, 1000000
%42 = load i32, i32* %19
%43 = add i32 %41, %42
%44 = load i32, i32* %20
%45 = sub i32 %43, %44
%46 = sub i32 %45, %26
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i32 %26, i32 %45, i32 %46)
%49 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%50 = udiv i32 %26, 1000000
store i32 %50, i32* %21
%51 = urem i32 %26, 1000000
%52 = mul nuw nsw i32 %51, 1000
store i32 %52, i32* %22
%53 = call i32 @nanosleep(%struct.timespec* %7, i32* null)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %58
55: ; preds = %36
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i32 %26)
br label %71
58: ; preds = %36
%59 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%60 = load i32, i32* %17
%61 = load i32, i32* %18
%62 = sub nsw i32 %60, %61
%63 = mul nsw i32 %62, 1000000
%64 = load i32, i32* %19
%65 = add i32 %63, %64
%66 = load i32, i32* %20
%67 = sub i32 %65, %66
%68 = sub i32 %67, %26
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i32 %26, i32 %67, i32 %68)
br label %71
71: ; preds = %58, %55
%72 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%73 = call i32 @FD_ZERO(i32* %5)
%74 = call i32 @FD_SET(i32 1, i32* %5)
store i32 0, i32* %23
store i32 %26, i32* %24
%75 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %6)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %82
77: ; preds = %71
%78 = load i32, i32* @stderr
%79 = load i32, i32* @errno
%80 = call i8* @strerror(i32 %79)
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), i32 %79, i8* %80)
br label %82
82: ; preds = %77, %71
%83 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%84 = load i32, i32* %17
%85 = load i32, i32* %18
%86 = sub nsw i32 %84, %85
%87 = mul nsw i32 %86, 1000000
%88 = load i32, i32* %19
%89 = add i32 %87, %88
%90 = load i32, i32* %20
%91 = sub i32 %89, %90
%92 = sub i32 %91, %26
%93 = load i32, i32* @stderr
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.11, i64 0, i64 0), i32 %26, i32 %91, i32 %92)
%95 = add nuw nsw i64 %27, 1
%96 = getelementptr inbounds [20 x i32], [20 x i32]* bitcast (<{ [10 x i32], [10 x i32] }>* @__const.main.delay to [20 x i32]*), i64 0, i64 %95
%97 = load i32, i32* %96
%98 = icmp eq i64 %95, 10
br i1 %98, label %99, label %25
99: ; preds = %82
ret i32 0
}