#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pwrite(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int strlen(char *);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ usleep(int);
scalar_t__ write(int, char *, int);
int main(void) {
  int i;
  int v = 0;
  int fd;
  char buffer[64];
  system("echo soc:leds >  /sys/class/leds/led0/device/driver/unbind");
  fd = open("/sys/class/gpio/export", O_WRONLY);
  if (fd < 0) {
    perror("unable to open gpio/export");
    exit(EXIT_FAILURE);
  }
  snprintf(buffer, 64, "%d", 35);
  write(fd, buffer, strlen(buffer));
  close(fd);
  snprintf(buffer, 64, "/sys/class/gpio/gpio%d/direction", 35);
  fd = open(buffer, O_WRONLY);
  if (fd < 0) {
    perror("unable to open GPIO direction");
    exit(EXIT_FAILURE);
  }
  if (write(fd, "out", 3) < 0) {
    perror("unable to set GPIO direction");
    exit(EXIT_FAILURE);
  }
  close(fd);
  snprintf(buffer, 64, "/sys/class/gpio/gpio%d/value", 35);
  fd = open(buffer, O_WRONLY);
  if (fd < 0) {
    perror("unable to open GPIO value");
    exit(EXIT_FAILURE);
  }
  while (1) {
    v = 0;
    for (i = 1; i < 50; i++) {
      snprintf(buffer, 64, "%d", v);
      pwrite(fd, buffer, strlen(buffer), 0);
      usleep(1000000 / i);
      v = 1 - v;
    }
  }
  close(fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe43(%rip),%rdi
call   1050 <system@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
lea    0xe69(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11fe <main+0x5e>
lea    0xe67(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    -0x50(%rbp),%rdi
mov    $0x40,%esi
lea    0xe5f(%rip),%rdx
mov    $0x23,%ecx
call   1060 <snprintf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x5c(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%edi
call   1070 <close@plt>
lea    -0x50(%rbp),%rdi
mov    $0x40,%esi
lea    0xe1b(%rip),%rdx
mov    $0x23,%ecx
call   1060 <snprintf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1298 <main+0xf8>
lea    0xe0c(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%edi
lea    0xe0d(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    12d0 <main+0x130>
lea    0xdf6(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%edi
call   1070 <close@plt>
lea    -0x50(%rbp),%rdi
mov    $0x40,%esi
lea    0xde8(%rip),%rdx
mov    $0x23,%ecx
call   1060 <snprintf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2cd3(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    132b <main+0x18b>
lea    0xdd5(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
jmp    1330 <main+0x190>
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0x32,-0x8(%rbp)
jge    13b0 <main+0x210>
lea    -0x50(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x40,%esi
lea    0xd12(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x6c(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <pwrite@plt>
mov    $0xf4240,%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,%edi
call   10c0 <usleep@plt>
mov    $0x1,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    133e <main+0x19e>
jmp    1330 <main+0x190>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
lea    0xe4d(%rip),%rdi
call   1050 <system@plt>
mov    0x2e11(%rip),%r14
mov    (%r14),%esi
lea    0xe72(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     12fc <main+0x15c>
mov    %eax,%ebp
lea    0xe8e(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    $0x23,%ecx
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1070 <close@plt>
lea    0xe5a(%rip),%rdx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    $0x23,%ecx
call   1060 <snprintf@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1305 <main+0x165>
mov    %eax,%ebx
lea    0xe6b(%rip),%rsi
mov    %eax,%edi
mov    $0x3,%edx
call   1030 <write@plt>
test   %rax,%rax
js     130e <main+0x16e>
mov    %ebx,%edi
call   1070 <close@plt>
lea    0xe69(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    $0x23,%ecx
call   1060 <snprintf@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1317 <main+0x177>
mov    %eax,%r15d
lea    0xdd4(%rip),%r14
mov    %rsp,%r12
nopl   0x0(%rax)
xor    %ebp,%ebp
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x40,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1060 <snprintf@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <pwrite@plt>
mov    $0xf4240,%eax
xor    %edx,%edx
div    %ebx
mov    %eax,%edi
call   10c0 <usleep@plt>
mov    $0x1,%eax
sub    %ebp,%eax
add    $0x1,%ebx
mov    %eax,%ebp
cmp    $0x32,%ebx
jne    12b0 <main+0x110>
jmp    12a0 <main+0x100>
lea    0xd4f(%rip),%rdi
jmp    131e <main+0x17e>
lea    0xd85(%rip),%rdi
jmp    131e <main+0x17e>
lea    0xd9e(%rip),%rdi
jmp    131e <main+0x17e>
lea    0xdcf(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [59 x i8] c"echo soc:leds > /sys/class/leds/led0/device/driver/unbind\00"
@.str.1 = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@.str.2 = [27 x i8] c"unable to open gpio/export\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [33 x i8] c"/sys/class/gpio/gpio%d/direction\00"
@.str.5 = [30 x i8] c"unable to open GPIO direction\00"
@.str.6 = [4 x i8] c"out\00"
@.str.7 = [29 x i8] c"unable to set GPIO direction\00"
@.str.8 = [29 x i8] c"/sys/class/gpio/gpio%d/value\00"
@.str.9 = [26 x i8] c"unable to open GPIO value\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [64 x i8]
store i32 0, i32* %1
store i32 0, i32* %3
%6 = call i32 @system(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @O_WRONLY
%8 = call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%17 = call i32 @snprintf(i8* %16, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 35)
%18 = load i32, i32* %4
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = call i64 @write(i32 %18, i8* %19, i32 %21)
%23 = load i32, i32* %4
%24 = call i32 @close(i32 %23)
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%26 = call i32 @snprintf(i8* %25, i32 64, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 35)
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%28 = load i32, i32* @O_WRONLY
%29 = call i32 @open(i8* %27, i32 %28)
store i32 %29, i32* %4
%30 = load i32, i32* %4
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %15
%33 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %15
%37 = load i32, i32* %4
%38 = call i64 @write(i32 %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 3)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %36
%45 = load i32, i32* %4
%46 = call i32 @close(i32 %45)
%47 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%48 = call i32 @snprintf(i8* %47, i32 64, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i32 35)
%49 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%50 = load i32, i32* @O_WRONLY
%51 = call i32 @open(i8* %49, i32 %50)
store i32 %51, i32* %4
%52 = load i32, i32* %4
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %44
%55 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %44
br label %59
59: ; preds = %58, %80
store i32 0, i32* %3
store i32 1, i32* %2
br label %60
60: ; preds = %77, %59
%61 = load i32, i32* %2
%62 = icmp slt i32 %61, 50
br i1 %62, label %63, label %80
63: ; preds = %60
%64 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%65 = load i32, i32* %3
%66 = call i32 @snprintf(i8* %64, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %65)
%67 = load i32, i32* %4
%68 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%69 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%70 = call i32 @strlen(i8* %69)
%71 = call i32 @pwrite(i32 %67, i8* %68, i32 %70, i32 0)
%72 = load i32, i32* %2
%73 = sdiv i32 1000000, %72
%74 = call i32 @usleep(i32 %73)
%75 = load i32, i32* %3
%76 = sub nsw i32 1, %75
store i32 %76, i32* %3
br label %77
77: ; preds = %63
%78 = load i32, i32* %2
%79 = add nsw i32 %78, 1
store i32 %79, i32* %2
br label %60
80: ; preds = %60
br label %59
}

LLVM IR (-O2):
@.str = [59 x i8] c"echo soc:leds > /sys/class/leds/led0/device/driver/unbind\00"
@.str.1 = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@.str.2 = [27 x i8] c"unable to open gpio/export\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [33 x i8] c"/sys/class/gpio/gpio%d/direction\00"
@.str.5 = [30 x i8] c"unable to open GPIO direction\00"
@.str.6 = [4 x i8] c"out\00"
@.str.7 = [29 x i8] c"unable to set GPIO direction\00"
@.str.8 = [29 x i8] c"/sys/class/gpio/gpio%d/value\00"
@.str.9 = [26 x i8] c"unable to open GPIO value\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [64 x i8]
%2 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @system(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @O_WRONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = call i32 @snprintf(i8* %2, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 35)
%13 = call i32 @strlen(i8* %2)
%14 = call i64 @write(i32 %5, i8* %2, i32 %13)
%15 = call i32 @close(i32 %5)
%16 = call i32 @snprintf(i8* %2, i32 64, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 35)
%17 = load i32, i32* @O_WRONLY
%18 = call i32 @open(i8* %2, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %11
%21 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %11
%25 = call i64 @write(i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 3)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %24
%32 = call i32 @close(i32 %18)
%33 = call i32 @snprintf(i8* %2, i32 64, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i32 35)
%34 = load i32, i32* @O_WRONLY
%35 = call i32 @open(i8* %2, i32 %34)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %31
%38 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %42, %31
br label %42
42: ; preds = %41, %42
%43 = phi i32 [ 0, %41 ], [ %50, %42 ]
%44 = phi i32 [ 1, %41 ], [ %51, %42 ]
%45 = call i32 @snprintf(i8* %2, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %43)
%46 = call i32 @strlen(i8* %2)
%47 = call i32 @pwrite(i32 %35, i8* %2, i32 %46, i32 0)
%48 = udiv i32 1000000, %44
%49 = call i32 @usleep(i32 %48)
%50 = sub nsw i32 1, %43
%51 = add nuw nsw i32 %44, 1
%52 = icmp eq i32 %51, 50
br i1 %52, label %41, label %42
}