#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 */
typedef int /*<<< orphan*/ frame;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ fputc(unsigned char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  const char frame[] = "000101011010110010101010";
  FILE *fd = fopen("/sys/devices/virtual/gpio/gpio44/value", "ab");
  if (!fd) {
    fprintf(stderr, "%s: failed to open '%s':\n", argv[0],
            "/sys/devices/virtual/gpio/gpio44/value");
    perror(NULL);
    exit(1);
  }
  for (unsigned int i = 0; i < sizeof(frame) - 1; i++) {
    unsigned char output = frame[i] ^ 0x1;
    fputc(output, fd);
    fflush(fd);
    usleep(1800);
  }
  fputs("0\n", fd);
  fclose(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe53(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe50(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe4d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe4b(%rip),%al
mov    %al,-0x18(%rbp)
lea    0xe42(%rip),%rdi
lea    0xe62(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1228 <main+0x98>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe3a(%rip),%rsi
lea    0xe09(%rip),%rcx
call   1060 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    $0x18,%rax
jae    127a <main+0xea>
mov    -0x3c(%rbp),%eax
movsbl -0x30(%rbp,%rax,1),%eax
xor    $0x1,%eax
mov    %al,-0x3d(%rbp)
mov    -0x3d(%rbp),%al
mov    -0x38(%rbp),%rsi
movzbl %al,%edi
call   1050 <fputc@plt>
mov    -0x38(%rbp),%rdi
call   1070 <fflush@plt>
mov    $0x708,%edi
call   10b0 <usleep@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    122f <main+0x9f>
mov    -0x38(%rbp),%rsi
lea    0xdd8(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xe7a(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1215 <main+0x85>
mov    %rax,%r15
xor    %ebx,%ebx
lea    0xe44(%rip),%r14
nopl   0x0(%rax)
movzbl (%rbx,%r14,1),%edi
xor    $0x1,%edi
mov    %r15,%rsi
call   1040 <fputc@plt>
mov    %r15,%rdi
call   1060 <fflush@plt>
mov    $0x708,%edi
call   10b0 <usleep@plt>
add    $0x1,%rbx
cmp    $0x18,%rbx
jne    11c0 <main+0x30>
lea    0xe6a(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   10a0 <fwrite@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe1b(%rip),%rsi
lea    0xdea(%rip),%rcx
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@__const.main.frame = [25 x i8] c"000101011010110010101010\00"
@.str = [39 x i8] c"/sys/devices/virtual/gpio/gpio44/value\00"
@.str.1 = [3 x i8] c"ab\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"%s: failed to open '%s':\0A\00"
@.str.3 = [3 x i8] c"0\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [25 x i8]
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [25 x i8]* %6 to i8*
%11 = call i32* @fopen(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %7
%12 = load i32*, i32** %7
%13 = icmp ne i32* %12, null
br i1 %13, label %22, label %14
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %18, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @perror(i32* null)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
store i32 0, i32* %8
br label %23
23: ; preds = %41, %22
%24 = load i32, i32* %8
%25 = zext i32 %24 to i64
%26 = icmp ult i64 %25, 24
br i1 %26, label %27, label %44
27: ; preds = %23
%28 = load i32, i32* %8
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [25 x i8], [25 x i8]* %6, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = xor i32 %32, 1
%34 = trunc i32 %33 to i8
store i8 %34, i8* %9
%35 = load i8, i8* %9
%36 = load i32*, i32** %7
%37 = call i32 @fputc(i8 zeroext %35, i32* %36)
%38 = load i32*, i32** %7
%39 = call i32 @fflush(i32* %38)
%40 = call i32 @usleep(i32 1800)
br label %41
41: ; preds = %27
%42 = load i32, i32* %8
%43 = add i32 %42, 1
store i32 %43, i32* %8
br label %23
44: ; preds = %23
%45 = load i32*, i32** %7
%46 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %45)
%47 = load i32*, i32** %7
%48 = call i32 @fclose(i32* %47)
ret i32 0
}

LLVM IR (-O2):
@__const.main.frame = [25 x i8] c"000101011010110010101010\00"
@.str = [39 x i8] c"/sys/devices/virtual/gpio/gpio44/value\00"
@.str.1 = [3 x i8] c"ab\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"%s: failed to open '%s':\0A\00"
@.str.3 = [3 x i8] c"0\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @perror(i32* null)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %14
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 2, i64 1, i32* %3)
%13 = tail call i32 @fclose(i32* %3)
ret i32 0
14: ; preds = %2, %14
%15 = phi i64 [ %22, %14 ], [ 0, %2 ]
%16 = getelementptr inbounds [25 x i8], [25 x i8]* @__const.main.frame, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = xor i8 %17, 1
%19 = tail call i32 @fputc(i8 zeroext %18, i32* %3)
%20 = tail call i32 @fflush(i32* %3)
%21 = tail call i32 @usleep(i32 1800)
%22 = add nuw nsw i64 %15, 1
%23 = icmp eq i64 %22, 24
br i1 %23, label %11, label %14
}