#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;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
int /*<<< orphan*/ gpio_layer(int);
int /*<<< orphan*/ gpio_le(int);
int /*<<< orphan*/ gpio_oe(int);
int /*<<< orphan*/ gpio_plane(unsigned char *);
void display(int duration, unsigned char *data) {
  struct timeval t0, now;
  int z, msec;
  gettimeofday(&t0, 0);
  z = 0;
  for (;;) {
    gpio_plane(data + z * 8);
    gpio_oe(0);
    gpio_le(0);
    gpio_le(1);
    gpio_layer(z);
    gpio_oe(1);
    z++;
    if (z >= 8) {
      z = 0;
      gettimeofday(&now, 0);
      msec = (now.tv_sec - t0.tv_sec) * 1000;
      msec += (now.tv_usec - t0.tv_usec) / 1000;
      if (msec >= duration)
        break;
    }
  }
}


x86 assembly (clang, -O0):
<display>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%rdi
call   1060 <gpio_plane@plt>
xor    %edi,%edi
call   1030 <gpio_oe@plt>
xor    %edi,%edi
call   1070 <gpio_le@plt>
mov    $0x1,%edi
call   1070 <gpio_le@plt>
mov    -0x24(%rbp),%edi
call   1050 <gpio_layer@plt>
mov    $0x1,%edi
call   1030 <gpio_oe@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x8,-0x24(%rbp)
jl     120d <display+0xbd>
movl   $0x0,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    -0x20(%rbp),%eax
sub    -0x18(%rbp),%eax
imul   $0x3e8,%eax,%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x4(%rbp),%eax
jl     1208 <display+0xb8>
jmp    1212 <display+0xc2>
jmp    120d <display+0xbd>
jmp    1171 <display+0x21>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0x10(%rsp),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0x8(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x0(,%rbp,8),%eax
movslq %eax,%rdi
add    %rbx,%rdi
call   1060 <gpio_plane@plt>
xor    %edi,%edi
call   1030 <gpio_oe@plt>
xor    %edi,%edi
call   1070 <gpio_le@plt>
mov    $0x1,%edi
call   1070 <gpio_le@plt>
mov    %ebp,%edi
call   1050 <gpio_layer@plt>
mov    $0x1,%edi
call   1030 <gpio_oe@plt>
lea    0x1(%rbp),%eax
cmp    $0x7,%ebp
mov    %eax,%ebp
jl     1180 <display+0x30>
xor    %ebp,%ebp
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
sub    0x10(%rsp),%eax
sub    0x14(%rsp),%ecx
imul   $0x3e8,%eax,%eax
movslq %ecx,%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
add    %eax,%ecx
cmp    %r14d,%ecx
jl     1180 <display+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define void @display(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%9 = call i32 @gettimeofday(%struct.timeval* %5, i32 0)
store i32 0, i32* %7
br label %10
10: ; preds = %48, %2
%11 = load i8*, i8** %4
%12 = load i32, i32* %7
%13 = mul nsw i32 %12, 8
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = call i32 @gpio_plane(i8* %15)
%17 = call i32 @gpio_oe(i32 0)
%18 = call i32 @gpio_le(i32 0)
%19 = call i32 @gpio_le(i32 1)
%20 = load i32, i32* %7
%21 = call i32 @gpio_layer(i32 %20)
%22 = call i32 @gpio_oe(i32 1)
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp sge i32 %25, 8
br i1 %26, label %27, label %48
27: ; preds = %10
store i32 0, i32* %7
%28 = call i32 @gettimeofday(%struct.timeval* %6, i32 0)
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%32 = load i32, i32* %31
%33 = sub nsw i32 %30, %32
%34 = mul nsw i32 %33, 1000
store i32 %34, i32* %8
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%36 = load i32, i32* %35
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%38 = load i32, i32* %37
%39 = sub nsw i32 %36, %38
%40 = sdiv i32 %39, 1000
%41 = load i32, i32* %8
%42 = add nsw i32 %41, %40
store i32 %42, i32* %8
%43 = load i32, i32* %8
%44 = load i32, i32* %3
%45 = icmp sge i32 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %27
br label %49
47: ; preds = %27
br label %48
48: ; preds = %47, %10
br label %10
49: ; preds = %46
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define void @display(i32 %0, i8* %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
br label %12
12: ; preds = %37, %2
%13 = phi i32 [ 0, %2 ], [ %38, %37 ]
%14 = shl nsw i32 %13, 3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = call i32 @gpio_plane(i8* %16)
%18 = call i32 @gpio_oe(i32 0)
%19 = call i32 @gpio_le(i32 0)
%20 = call i32 @gpio_le(i32 1)
%21 = call i32 @gpio_layer(i32 %13)
%22 = call i32 @gpio_oe(i32 1)
%23 = add nsw i32 %13, 1
%24 = icmp sgt i32 %13, 6
br i1 %24, label %25, label %37
25: ; preds = %12
%26 = call i32 @gettimeofday(%struct.timeval* %4, i32 0)
%27 = load i32, i32* %8
%28 = load i32, i32* %9
%29 = sub nsw i32 %27, %28
%30 = mul nsw i32 %29, 1000
%31 = load i32, i32* %10
%32 = load i32, i32* %11
%33 = sub nsw i32 %31, %32
%34 = sdiv i32 %33, 1000
%35 = add nsw i32 %34, %30
%36 = icmp slt i32 %35, %0
br i1 %36, label %37, label %39
37: ; preds = %25, %12
%38 = phi i32 [ 0, %25 ], [ %23, %12 ]
br label %12
39: ; preds = %25
ret void
}