#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 dummy;
};
typedef int /*<<< orphan*/ adc_list;

/* Variables and functions */
int atoi(char *);
int getopt(int, char **, char *);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int loop(int, int *);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
char *optarg;
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ register_sig_handler();
int /*<<< orphan*/ show_elapsed(struct timeval *, struct timeval *, int);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int opt, delay_ms, adc, i;
  struct timeval start, end;
  int adc_list[6];
  register_sig_handler();
  delay_ms = 50;
  while ((opt = getopt(argc, argv, "d:h")) != -1) {
    switch (opt) {
    case 'd':
      delay_ms = atoi(optarg);
      if (delay_ms < 1) {
        printf("Invalid delay %d. Must be greater then zero.\n", delay_ms);
        usage(argv[0]);
      }
      break;
    case 'h':
    default:
      usage(argv[0]);
      break;
    }
  }
  if (optind == argc) {
    printf("A list of ADCs is required\n");
    usage(argv[0]);
  }
  memset(adc_list, 0, sizeof(adc_list));
  for (i = optind; i < argc; i++) {
    adc = atoi(argv[i]);
    if (adc < 2 || adc > 7) {
      printf("adc %d is out of range\n", adc);
      usage(argv[0]);
    }
    adc -= 2;
    if (adc_list[adc]) {
      printf("adc %d listed more then once\n", adc + 2);
      usage(argv[0]);
    }
    adc_list[adc] = 1;
  }
  if (gettimeofday(&start, NULL) < 0) {
    perror("gettimeofday: start");
    return 1;
  }
  int count = loop(delay_ms, adc_list);
  if (gettimeofday(&end, NULL) < 0)
    perror("gettimeofday: end");
  else
    show_elapsed(&start, &end, count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   10c0 <register_sig_handler@plt>
movl   $0x32,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe2e(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     125c <main+0xbc>
mov    -0x14(%rbp),%eax
mov    %eax,-0x58(%rbp)
sub    $0x64,%eax
je     1208 <main+0x68>
jmp    11f7 <main+0x57>
mov    -0x58(%rbp),%eax
sub    $0x68,%eax
je     1246 <main+0xa6>
jmp    124b <main+0xab>
mov    0x2de9(%rip),%rax
mov    (%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jge    1241 <main+0xa1>
mov    -0x18(%rbp),%esi
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <usage@plt>
jmp    1257 <main+0xb7>
jmp    124b <main+0xab>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <usage@plt>
jmp    11c4 <main+0x24>
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jne    1288 <main+0xe8>
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <usage@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1347 <main+0x1a7>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jl     12d8 <main+0x138>
cmpl   $0x7,-0x1c(%rbp)
jle    12f5 <main+0x155>
mov    -0x1c(%rbp),%esi
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <usage@plt>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmpl   $0x0,-0x50(%rbp,%rax,4)
je     132d <main+0x18d>
mov    -0x1c(%rbp),%esi
add    $0x2,%esi
lea    0xd4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <usage@plt>
movslq -0x1c(%rbp),%rax
movl   $0x1,-0x50(%rbp,%rax,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12a4 <main+0x104>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
cmp    $0x0,%rax
jge    1376 <main+0x1d6>
lea    0xd1f(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c4 <main+0x224>
mov    -0x18(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1030 <loop@plt>
mov    %eax,-0x54(%rbp)
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
cmp    $0x0,%rax
jge    13ad <main+0x20d>
lea    0xcf5(%rip),%rdi
call   1090 <perror@plt>
jmp    13bd <main+0x21d>
mov    -0x54(%rbp),%edx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <show_elapsed@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
mov    %edi,%r13d
xor    %eax,%eax
call   10d0 <register_sig_handler@plt>
mov    $0x32,%r14d
lea    0xe28(%rip),%r15
mov    0x2e19(%rip),%rbp
lea    0xe1e(%rip),%r12
jmp    11fd <main+0x4d>
nopl   0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
je     122f <main+0x7f>
mov    (%rbx),%rdi
call   1090 <usage@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   10b0 <getopt@plt>
cmp    $0x64,%eax
jne    11f0 <main+0x40>
mov    0x0(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r14d
test   %eax,%eax
jg     11fd <main+0x4d>
mov    %r12,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11f5 <main+0x45>
mov    0x2daa(%rip),%rbp
cmp    %r13d,0x0(%rbp)
jne    1250 <main+0xa0>
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rdi
call   1090 <usage@plt>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
movslq 0x0(%rbp),%rax
cmp    %r13d,%eax
jge    12ea <main+0x13a>
lea    (%rbx,%rax,8),%rcx
mov    %rcx,0x18(%rsp)
sub    %eax,%r13d
xor    %r12d,%r12d
jmp    1292 <main+0xe2>
nop
movl   $0x1,0x20(%rsp,%r15,4)
add    $0x1,%r12
cmp    %r12d,%r13d
je     12ea <main+0x13a>
mov    0x18(%rsp),%rax
mov    (%rax,%r12,8),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ebp
lea    -0x8(%rbp),%eax
cmp    $0xfffffff9,%eax
ja     12c2 <main+0x112>
lea    0xd81(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rdi
call   1090 <usage@plt>
movslq %ebp,%rax
lea    -0x2(%rax),%r15
cmpl   $0x0,0x18(%rsp,%rax,4)
je     1280 <main+0xd0>
lea    0xd73(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rdi
call   1090 <usage@plt>
jmp    1280 <main+0xd0>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
test   %rax,%rax
js     133f <main+0x18f>
lea    0x20(%rsp),%rsi
mov    %r14d,%edi
call   1040 <loop@plt>
mov    %eax,%ebp
xor    %ebx,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
test   %rax,%rax
js     1352 <main+0x1a2>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %ebp,%edx
call   1080 <show_elapsed@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd22(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%ebx
jmp    132e <main+0x17e>
lea    0xd23(%rip),%rdi
call   10a0 <perror@plt>
jmp    132e <main+0x17e>

LLVM IR (-O0):
%struct.timeval = type { i32 }
@.str = [4 x i8] c"d:h\00"
@optarg = global i8* null
@.str.1 = [46 x i8] c"Invalid delay %d. Must be greater then zero.\0A\00"
@optind = global i32 0
@.str.2 = [28 x i8] c"A list of ADCs is required\0A\00"
@.str.3 = [24 x i8] c"adc %d is out of range\0A\00"
@.str.4 = [30 x i8] c"adc %d listed more then once\0A\00"
@.str.5 = [20 x i8] c"gettimeofday: start\00"
@.str.6 = [18 x i8] c"gettimeofday: end\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 %struct.timeval
%11 = alloca %struct.timeval
%12 = alloca [6 x i32]
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 (...) @register_sig_handler()
store i32 50, i32* %7
br label %15
15: ; preds = %41, %2
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call i32 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %18, i32* %6
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %42
20: ; preds = %15
%21 = load i32, i32* %6
switch i32 %21, label %36 [
i32 100, label %22
i32 104, label %35
]
22: ; preds = %20
%23 = load i8*, i8** @optarg
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp slt i32 %25, 1
br i1 %26, label %27, label %34
27: ; preds = %22
%28 = load i32, i32* %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 @usage(i8* %32)
br label %34
34: ; preds = %27, %22
br label %41
35: ; preds = %20
br label %36
36: ; preds = %20, %35
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = call i32 @usage(i8* %39)
br label %41
41: ; preds = %36, %34
br label %15
42: ; preds = %15
%43 = load i32, i32* @optind
%44 = load i32, i32* %4
%45 = icmp eq i32 %43, %44
br i1 %45, label %46, label %52
46: ; preds = %42
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 0
%50 = load i8*, i8** %49
%51 = call i32 @usage(i8* %50)
br label %52
52: ; preds = %46, %42
%53 = getelementptr inbounds [6 x i32], [6 x i32]* %12, i64 0, i64 0
%54 = call i32 @memset(i32* %53, i32 0, i32 24)
%55 = load i32, i32* @optind
store i32 %55, i32* %9
br label %56
56: ; preds = %99, %52
%57 = load i32, i32* %9
%58 = load i32, i32* %4
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %102
60: ; preds = %56
%61 = load i8**, i8*** %5
%62 = load i32, i32* %9
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
%65 = load i8*, i8** %64
%66 = call i32 @atoi(i8* %65)
store i32 %66, i32* %8
%67 = load i32, i32* %8
%68 = icmp slt i32 %67, 2
br i1 %68, label %72, label %69
69: ; preds = %60
%70 = load i32, i32* %8
%71 = icmp sgt i32 %70, 7
br i1 %71, label %72, label %79
72: ; preds = %69, %60
%73 = load i32, i32* %8
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %73)
%75 = load i8**, i8*** %5
%76 = getelementptr inbounds i8*, i8** %75, i64 0
%77 = load i8*, i8** %76
%78 = call i32 @usage(i8* %77)
br label %79
79: ; preds = %72, %69
%80 = load i32, i32* %8
%81 = sub nsw i32 %80, 2
store i32 %81, i32* %8
%82 = load i32, i32* %8
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [6 x i32], [6 x i32]* %12, i64 0, i64 %83
%85 = load i32, i32* %84
%86 = icmp ne i32 %85, 0
br i1 %86, label %87, label %95
87: ; preds = %79
%88 = load i32, i32* %8
%89 = add nsw i32 %88, 2
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %89)
%91 = load i8**, i8*** %5
%92 = getelementptr inbounds i8*, i8** %91, i64 0
%93 = load i8*, i8** %92
%94 = call i32 @usage(i8* %93)
br label %95
95: ; preds = %87, %79
%96 = load i32, i32* %8
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [6 x i32], [6 x i32]* %12, i64 0, i64 %97
store i32 1, i32* %98
br label %99
99: ; preds = %95
%100 = load i32, i32* %9
%101 = add nsw i32 %100, 1
store i32 %101, i32* %9
br label %56
102: ; preds = %56
%103 = call i64 @gettimeofday(%struct.timeval* %10, i32* null)
%104 = icmp slt i64 %103, 0
br i1 %104, label %105, label %107
105: ; preds = %102
%106 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %119
107: ; preds = %102
%108 = load i32, i32* %7
%109 = getelementptr inbounds [6 x i32], [6 x i32]* %12, i64 0, i64 0
%110 = call i32 @loop(i32 %108, i32* %109)
store i32 %110, i32* %13
%111 = call i64 @gettimeofday(%struct.timeval* %11, i32* null)
%112 = icmp slt i64 %111, 0
br i1 %112, label %113, label %115
113: ; preds = %107
%114 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %118
115: ; preds = %107
%116 = load i32, i32* %13
%117 = call i32 @show_elapsed(%struct.timeval* %10, %struct.timeval* %11, i32 %116)
br label %118
118: ; preds = %115, %113
store i32 0, i32* %3
br label %119
119: ; preds = %118, %105
%120 = load i32, i32* %3
ret i32 %120
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@.str = [4 x i8] c"d:h\00"
@optarg = global i8* null
@.str.1 = [46 x i8] c"Invalid delay %d. Must be greater then zero.\0A\00"
@optind = global i32 0
@.str.3 = [24 x i8] c"adc %d is out of range\0A\00"
@.str.4 = [30 x i8] c"adc %d listed more then once\0A\00"
@.str.5 = [20 x i8] c"gettimeofday: start\00"
@.str.6 = [18 x i8] c"gettimeofday: end\00"
@str = [27 x i8] c"A list of ADCs is required\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca [6 x i32]
%6 = bitcast %struct.timeval* %3 to i8*
%7 = bitcast %struct.timeval* %4 to i8*
%8 = bitcast [6 x i32]* %5 to i8*
%9 = tail call i32 (...) @register_sig_handler()
br label %10
10: ; preds = %23, %2
%11 = phi i32 [ 50, %2 ], [ %24, %23 ]
%12 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %12, label %19 [
i32 -1, label %25
i32 100, label %13
]
13: ; preds = %10
%14 = load i8*, i8** @optarg
%15 = tail call i32 @atoi(i8* %14)
%16 = icmp slt i32 %15, 1
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %19
19: ; preds = %10, %17
%20 = phi i32 [ %15, %17 ], [ %11, %10 ]
%21 = load i8*, i8** %1
%22 = tail call i32 @usage(i8* %21)
br label %23
23: ; preds = %19, %13
%24 = phi i32 [ %15, %13 ], [ %20, %19 ]
br label %10
25: ; preds = %10
%26 = load i32, i32* @optind
%27 = icmp eq i32 %26, %0
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%30 = load i8*, i8** %1
%31 = tail call i32 @usage(i8* %30)
br label %32
32: ; preds = %28, %25
%33 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 0
%34 = call i32 @memset(i32* %33, i32 0, i32 24)
%35 = load i32, i32* @optind
%36 = icmp slt i32 %35, %0
br i1 %36, label %37, label %64
37: ; preds = %32
%38 = sext i32 %35 to i64
br label %39
39: ; preds = %37, %60
%40 = phi i64 [ %38, %37 ], [ %61, %60 ]
%41 = getelementptr inbounds i8*, i8** %1, i64 %40
%42 = load i8*, i8** %41
%43 = call i32 @atoi(i8* %42)
%44 = add i32 %43, -8
%45 = icmp ult i32 %44, -6
br i1 %45, label %46, label %50
46: ; preds = %39
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %43)
%48 = load i8*, i8** %1
%49 = call i32 @usage(i8* %48)
br label %50
50: ; preds = %39, %46
%51 = add nsw i32 %43, -2
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = icmp eq i32 %54, 0
br i1 %55, label %60, label %56
56: ; preds = %50
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %43)
%58 = load i8*, i8** %1
%59 = call i32 @usage(i8* %58)
br label %60
60: ; preds = %56, %50
store i32 1, i32* %53
%61 = add nsw i64 %40, 1
%62 = trunc i64 %61 to i32
%63 = icmp eq i32 %62, %0
br i1 %63, label %64, label %39
64: ; preds = %60, %32
%65 = call i64 @gettimeofday(%struct.timeval* %3, i32* null)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %64
%68 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %77
69: ; preds = %64
%70 = call i32 @loop(i32 %11, i32* %33)
%71 = call i64 @gettimeofday(%struct.timeval* %4, i32* null)
%72 = icmp slt i64 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %69
%74 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %77
75: ; preds = %69
%76 = call i32 @show_elapsed(%struct.timeval* %3, %struct.timeval* %4, i32 %70)
br label %77
77: ; preds = %73, %75, %67
%78 = phi i32 [ 1, %67 ], [ 0, %75 ], [ 0, %73 ]
ret i32 %78
}