#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 */
int /*<<< orphan*/ fsgpio_export(int);
int /*<<< orphan*/ fsgpio_set_output(int);
int /*<<< orphan*/ fsgpio_set_value(int, int);
int /*<<< orphan*/ fsgpio_unexport(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usleep(int);
int main(int args, char *argv[]) {
  int x = 0;
  printf("Exporting gpio %d\n", 1 * 32 + 28);
  if (!fsgpio_export(1 * 32 + 28)) {
    printf("Success.\n");
  }
  printf("Setting gpio %d as output", 1 * 32 + 28);
  if (!fsgpio_set_output(1 * 32 + 28)) {
    printf("Success.\n");
  }
  for (x = 0; x < 10; x++) {
    printf("Set 1\n");
    fsgpio_set_value(1 * 32 + 28, 1);
    usleep(500000);
    printf("Set 0\n");
    fsgpio_set_value(1 * 32 + 28, 0);
    usleep(500000);
  }
  printf("Unexporting gpio %d\n", 1 * 32 + 28);
  if (!fsgpio_unexport(1 * 32 + 28)) {
    printf("Success.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe7c(%rip),%rdi
mov    $0x3c,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x3c,%edi
call   1040 <fsgpio_export@plt>
cmp    $0x0,%eax
jne    11b1 <main+0x51>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe65(%rip),%rdi
mov    $0x3c,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x3c,%edi
call   1050 <fsgpio_set_output@plt>
cmp    $0x0,%eax
jne    11e5 <main+0x85>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    124f <main+0xef>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x3c,%edi
mov    $0x1,%esi
call   1070 <fsgpio_set_value@plt>
mov    $0x7a120,%edi
call   1080 <usleep@plt>
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x3c,%edi
xor    %esi,%esi
call   1070 <fsgpio_set_value@plt>
mov    $0x7a120,%edi
call   1080 <usleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ec <main+0x8c>
lea    0xdef(%rip),%rdi
mov    $0x3c,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x3c,%edi
call   1060 <fsgpio_unexport@plt>
cmp    $0x0,%eax
jne    1283 <main+0x123>
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xe85(%rip),%rdi
mov    $0x3c,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x3c,%edi
call   1050 <fsgpio_export@plt>
test   %eax,%eax
jne    11a1 <main+0x31>
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6b(%rip),%rdi
mov    $0x3c,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x3c,%edi
call   1060 <fsgpio_set_output@plt>
test   %eax,%eax
jne    11ce <main+0x5e>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa,%ebp
lea    0xe71(%rip),%r14
lea    0xe70(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    $0x3c,%edi
mov    $0x1,%esi
call   1080 <fsgpio_set_value@plt>
mov    $0x7a120,%edi
call   1090 <usleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x3c,%edi
xor    %esi,%esi
call   1080 <fsgpio_set_value@plt>
mov    $0x7a120,%edi
call   1090 <usleep@plt>
add    $0xffffffff,%ebp
jne    11f0 <main+0x80>
lea    0xdf2(%rip),%rdi
mov    $0x3c,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x3c,%edi
call   1070 <fsgpio_unexport@plt>
test   %eax,%eax
jne    1261 <main+0xf1>
lea    0xde6(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Exporting gpio %d\0A\00"
@.str.1 = [10 x i8] c"Success.\0A\00"
@.str.2 = [26 x i8] c"Setting gpio %d as output\00"
@.str.3 = [7 x i8] c"Set 1\0A\00"
@.str.4 = [7 x i8] c"Set 0\0A\00"
@.str.5 = [21 x i8] c"Unexporting gpio %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 60)
%8 = call i32 @fsgpio_export(i32 60)
%9 = icmp ne i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 60)
%14 = call i32 @fsgpio_set_output(i32 60)
%15 = icmp ne i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
store i32 0, i32* %6
br label %19
19: ; preds = %29, %18
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 10
br i1 %21, label %22, label %32
22: ; preds = %19
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @fsgpio_set_value(i32 60, i32 1)
%25 = call i32 @usleep(i32 500000)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 @fsgpio_set_value(i32 60, i32 0)
%28 = call i32 @usleep(i32 500000)
br label %29
29: ; preds = %22
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %19
32: ; preds = %19
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 60)
%34 = call i32 @fsgpio_unexport(i32 60)
%35 = icmp ne i32 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %32
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %36, %32
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"Exporting gpio %d\0A\00"
@.str.2 = [26 x i8] c"Setting gpio %d as output\00"
@.str.5 = [21 x i8] c"Unexporting gpio %d\0A\00"
@str.7 = [9 x i8] c"Success.\00"
@str.8 = [6 x i8] c"Set 1\00"
@str.9 = [6 x i8] c"Set 0\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 60)
%4 = tail call i32 @fsgpio_export(i32 60)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.7, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 60)
%10 = tail call i32 @fsgpio_set_output(i32 60)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.7, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
br label %15
15: ; preds = %14, %15
%16 = phi i32 [ %23, %15 ], [ 0, %14 ]
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.8, i64 0, i64 0))
%18 = tail call i32 @fsgpio_set_value(i32 60, i32 1)
%19 = tail call i32 @usleep(i32 500000)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.9, i64 0, i64 0))
%21 = tail call i32 @fsgpio_set_value(i32 60, i32 0)
%22 = tail call i32 @usleep(i32 500000)
%23 = add nuw nsw i32 %16, 1
%24 = icmp eq i32 %23, 10
br i1 %24, label %25, label %15
25: ; preds = %15
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 60)
%27 = tail call i32 @fsgpio_unexport(i32 60)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.7, i64 0, i64 0))
br label %31
31: ; preds = %29, %25
ret i32 0
}