#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 timespec {
  int tv_sec;
  int tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ output(int, int);
void outputSequence(int gpio, int period, char *sequence) {
  int i, value;
  struct timespec ts;
  ts.tv_sec = period / 1000;
  ts.tv_nsec = (period % 1000) * 1000000;
  for (i = 0; sequence[i] != '\0'; i++) {
    if (sequence[i] == '1') {
      value = 1;
    } else {
      value = 0;
    }
    output(gpio, value);
    nanosleep(&ts, NULL);
  }
}


x86 assembly (clang, -O0):
<outputSequence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
imul   $0xf4240,%edx,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11be <outputSequence+0x9e>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x31,%eax
jne    1191 <outputSequence+0x71>
movl   $0x1,-0x18(%rbp)
jmp    1198 <outputSequence+0x78>
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <output@plt>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <nanosleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115b <outputSequence+0x3b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<outputSequence>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %edi,%ebp
movslq %esi,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
mov    %ecx,0x8(%rsp)
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
imul   $0xf4240,%eax,%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%r14
jmp    1185 <outputSequence+0x65>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <output@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
add    $0x1,%rbx
movzbl (%rbx),%eax
mov    $0x1,%esi
cmp    $0x31,%al
je     1170 <outputSequence+0x50>
test   %al,%al
je     1199 <outputSequence+0x79>
xor    %esi,%esi
jmp    1170 <outputSequence+0x50>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
define void @outputSequence(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.timespec
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = load i32, i32* %5
%11 = sdiv i32 %10, 1000
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 0
store i32 %11, i32* %12
%13 = load i32, i32* %5
%14 = srem i32 %13, 1000
%15 = mul nsw i32 %14, 1000000
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 1
store i32 %15, i32* %16
store i32 0, i32* %7
br label %17
17: ; preds = %40, %3
%18 = load i8*, i8** %6
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %43
25: ; preds = %17
%26 = load i8*, i8** %6
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 49
br i1 %32, label %33, label %34
33: ; preds = %25
store i32 1, i32* %8
br label %35
34: ; preds = %25
store i32 0, i32* %8
br label %35
35: ; preds = %34, %33
%36 = load i32, i32* %4
%37 = load i32, i32* %8
%38 = call i32 @output(i32 %36, i32 %37)
%39 = call i32 @nanosleep(%struct.timespec* %9, i32* null)
br label %40
40: ; preds = %35
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %17
43: ; preds = %17
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
define void @outputSequence(i32 %0, i32 %1, i8* nocapture %2) {
%4 = alloca %struct.timespec
%5 = bitcast %struct.timespec* %4 to i8*
%6 = sdiv i32 %1, 1000
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
store i32 %6, i32* %7
%8 = srem i32 %1, 1000
%9 = mul nsw i32 %8, 1000000
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
store i32 %9, i32* %10
br label %11
11: ; preds = %16, %3
%12 = phi i64 [ %20, %16 ], [ 0, %3 ]
%13 = getelementptr inbounds i8, i8* %2, i64 %12
%14 = load i8, i8* %13
switch i8 %14, label %15 [
i8 0, label %21
i8 49, label %16
]
15: ; preds = %11
br label %16
16: ; preds = %11, %15
%17 = phi i32 [ 0, %15 ], [ 1, %11 ]
%18 = call i32 @output(i32 %0, i32 %17)
%19 = call i32 @nanosleep(%struct.timespec* %4, i32* null)
%20 = add nuw i64 %12, 1
br label %11
21: ; preds = %11
ret void
}