#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 */

/* Variables and functions */
scalar_t__ set(int, int);
int /*<<< orphan*/ usleep(unsigned int);
int pulse(int gpio, unsigned int period, unsigned int duration) {
  if (set(gpio, 1) != 0) {
    return -1;
  }
  (void)usleep(duration);
  if (set(gpio, 0) != 0) {
    return -2;
  }
  (void)usleep(period - duration);
  return 0;
}


x86 assembly (clang, -O0):
<pulse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1030 <set@plt>
cmp    $0x0,%rax
je     1154 <pulse+0x34>
movl   $0xffffffff,-0x4(%rbp)
jmp    118e <pulse+0x6e>
mov    -0x10(%rbp),%edi
call   1040 <usleep@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1030 <set@plt>
cmp    $0x0,%rax
je     117c <pulse+0x5c>
movl   $0xfffffffe,-0x4(%rbp)
jmp    118e <pulse+0x6e>
mov    -0xc(%rbp),%edi
sub    -0x10(%rbp),%edi
call   1040 <usleep@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pulse>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %esi,%r14d
mov    %edi,%ebx
mov    $0x1,%esi
call   1030 <set@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    116c <pulse+0x4c>
mov    %ebp,%edi
call   1040 <usleep@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <set@plt>
mov    %rax,%rcx
mov    $0xfffffffe,%eax
test   %rcx,%rcx
jne    116c <pulse+0x4c>
sub    %ebp,%r14d
mov    %r14d,%edi
call   1040 <usleep@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pulse(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %5
%9 = call i64 @set(i32 %8, i32 1)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 -1, i32* %4
br label %24
12: ; preds = %3
%13 = load i32, i32* %7
%14 = call i32 @usleep(i32 %13)
%15 = load i32, i32* %5
%16 = call i64 @set(i32 %15, i32 0)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %12
store i32 -2, i32* %4
br label %24
19: ; preds = %12
%20 = load i32, i32* %6
%21 = load i32, i32* %7
%22 = sub i32 %20, %21
%23 = call i32 @usleep(i32 %22)
store i32 0, i32* %4
br label %24
24: ; preds = %19, %18, %11
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
define i32 @pulse(i32 %0, i32 %1, i32 %2) {
%4 = tail call i64 @set(i32 %0, i32 1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = tail call i32 @usleep(i32 %2)
%8 = tail call i64 @set(i32 %0, i32 0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = sub i32 %1, %2
%12 = tail call i32 @usleep(i32 %11)
br label %13
13: ; preds = %6, %3, %10
%14 = phi i32 [ 0, %10 ], [ -1, %3 ], [ -2, %6 ]
ret i32 %14
}