#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;
};
struct sigaction {
  int dummy;
};
typedef int /*<<< orphan*/ pthread_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int timevaldiff(struct timeval *, struct timeval *);
int /*<<< orphan*/ turn_off(int);
int /*<<< orphan*/ turn_on(int);
int main() {
  pthread_t blinker;
  struct sigaction new_action;
  int device, i;
  struct timeval start, end;
  device = open("/dev/mygpio", O_RDWR);
  if (device < 0) {
    fprintf(stderr, "could not open "
                    "/dev/mygpio"
                    "\n");
  }
  gettimeofday(&start, NULL);
  for (i = 0; i < 10; i++) {
    turn_on(device);
    turn_off(device);
  }
  gettimeofday(&end, NULL);
  printf("%lf usec\n", timevaldiff(&start, &end) / 10);
  close(device);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    0xe61(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11c6 <main+0x46>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
call   1080 <fprintf@plt>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0xa,-0x18(%rbp)
jge    1202 <main+0x82>
mov    -0x14(%rbp),%edi
call   1070 <turn_on@plt>
mov    -0x14(%rbp),%edi
call   1090 <turn_off@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11da <main+0x5a>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <timevaldiff@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xdfb(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
lea    0xe67(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11b9 <main+0x39>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
call   1080 <fprintf@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    %ebx,%edi
call   1070 <turn_on@plt>
mov    %ebx,%edi
call   1090 <turn_off@plt>
mov    %ebx,%edi
call   1070 <turn_on@plt>
mov    %ebx,%edi
call   1090 <turn_off@plt>
mov    %ebx,%edi
call   1070 <turn_on@plt>
mov    %ebx,%edi
call   1090 <turn_off@plt>
mov    %ebx,%edi
call   1070 <turn_on@plt>
mov    %ebx,%edi
call   1090 <turn_off@plt>
mov    %ebx,%edi
call   1070 <turn_on@plt>
mov    %ebx,%edi
call   1090 <turn_off@plt>
mov    %ebx,%edi
call   1070 <turn_on@plt>
mov    %ebx,%edi
call   1090 <turn_off@plt>
mov    %ebx,%edi
call   1070 <turn_on@plt>
mov    %ebx,%edi
call   1090 <turn_off@plt>
mov    %ebx,%edi
call   1070 <turn_on@plt>
mov    %ebx,%edi
call   1090 <turn_off@plt>
mov    %ebx,%edi
call   1070 <turn_on@plt>
mov    %ebx,%edi
call   1090 <turn_off@plt>
mov    %ebx,%edi
call   1070 <turn_on@plt>
mov    %ebx,%edi
call   1090 <turn_off@plt>
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <timevaldiff@plt>
cltq
imul   $0x66666667,%rax,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x22,%rsi
add    %eax,%esi
lea    0xd9f(%rip),%rdi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sigaction = type { i32 }
%struct.timeval = type { i32 }
@.str = [12 x i8] c"/dev/mygpio\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [28 x i8] c"could not open /dev/mygpio\0A\00"
@.str.2 = [10 x i8] c"%lf usec\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sigaction
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
store i32 0, i32* %1
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %12, %0
%16 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
store i32 0, i32* %5
br label %17
17: ; preds = %25, %15
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 10
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = load i32, i32* %4
%22 = call i32 @turn_on(i32 %21)
%23 = load i32, i32* %4
%24 = call i32 @turn_off(i32 %23)
br label %25
25: ; preds = %20
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %17
28: ; preds = %17
%29 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%30 = call i32 @timevaldiff(%struct.timeval* %6, %struct.timeval* %7)
%31 = sdiv i32 %30, 10
%32 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %4
%34 = call i32 @close(i32 %33)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@.str = [12 x i8] c"/dev/mygpio\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [28 x i8] c"could not open /dev/mygpio\0A\00"
@.str.2 = [10 x i8] c"%lf usec\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %8, %0
%12 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%13 = tail call i32 @turn_on(i32 %6)
%14 = tail call i32 @turn_off(i32 %6)
%15 = tail call i32 @turn_on(i32 %6)
%16 = tail call i32 @turn_off(i32 %6)
%17 = tail call i32 @turn_on(i32 %6)
%18 = tail call i32 @turn_off(i32 %6)
%19 = tail call i32 @turn_on(i32 %6)
%20 = tail call i32 @turn_off(i32 %6)
%21 = tail call i32 @turn_on(i32 %6)
%22 = tail call i32 @turn_off(i32 %6)
%23 = tail call i32 @turn_on(i32 %6)
%24 = tail call i32 @turn_off(i32 %6)
%25 = tail call i32 @turn_on(i32 %6)
%26 = tail call i32 @turn_off(i32 %6)
%27 = tail call i32 @turn_on(i32 %6)
%28 = tail call i32 @turn_off(i32 %6)
%29 = tail call i32 @turn_on(i32 %6)
%30 = tail call i32 @turn_off(i32 %6)
%31 = tail call i32 @turn_on(i32 %6)
%32 = tail call i32 @turn_off(i32 %6)
%33 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%34 = call i32 @timevaldiff(%struct.timeval* %1, %struct.timeval* %2)
%35 = sdiv i32 %34, 10
%36 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = call i32 @close(i32 %6)
ret i32 0
}