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

/* Variables and functions */
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
void gLEDOn(int on) {
  FILE *fp;
  int i;
  char cmdBuffer[128];
  if (on) {
    for (i = 0; i < 4; i++) {
      sprintf(cmdBuffer, "/bin/echo -n %d1 > /dev/led_sr", i + 1);
      fp = popen(cmdBuffer, "r");
      if (fp) {
        pclose(fp);
      }
    }
  } else {
    for (i = 0; i < 4; i++) {
      sprintf(cmdBuffer, "/bin/echo -n %d0 > /dev/led_sr", i + 1);
      fp = popen(cmdBuffer, "r");
      if (fp) {
        pclose(fp);
      }
    }
  }
}


x86 assembly (clang, -O0):
<gLEDOn>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11b5 <gLEDOn+0x85>
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    11b0 <gLEDOn+0x80>
lea    -0xa0(%rbp),%rdi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
lea    0xe93(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xebc(%rip),%rsi
call   1040 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119d <gLEDOn+0x6d>
mov    -0x10(%rbp),%rdi
call   1030 <pclose@plt>
jmp    11a2 <gLEDOn+0x72>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114f <gLEDOn+0x1f>
jmp    1222 <gLEDOn+0xf2>
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    121d <gLEDOn+0xed>
lea    -0xa0(%rbp),%rdi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
lea    0xe45(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1040 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     120a <gLEDOn+0xda>
mov    -0x10(%rbp),%rdi
call   1030 <pclose@plt>
jmp    120f <gLEDOn+0xdf>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11bc <gLEDOn+0x8c>
jmp    1222 <gLEDOn+0xf2>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gLEDOn>:
push   %rbx
sub    $0x80,%rsp
test   %edi,%edi
je     11e5 <gLEDOn+0xb5>
lea    0xeb9(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1,%edx
call   1050 <sprintf@plt>
lea    0xede(%rip),%rsi
mov    %rbx,%rdi
call   1040 <popen@plt>
test   %rax,%rax
je     1173 <gLEDOn+0x43>
mov    %rax,%rdi
call   1030 <pclose@plt>
lea    0xe86(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x2,%edx
call   1050 <sprintf@plt>
lea    0xeab(%rip),%rsi
mov    %rbx,%rdi
call   1040 <popen@plt>
test   %rax,%rax
je     11a6 <gLEDOn+0x76>
mov    %rax,%rdi
call   1030 <pclose@plt>
lea    0xe53(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3,%edx
call   1050 <sprintf@plt>
lea    0xe78(%rip),%rsi
mov    %rbx,%rdi
call   1040 <popen@plt>
test   %rax,%rax
je     11d9 <gLEDOn+0xa9>
mov    %rax,%rdi
call   1030 <pclose@plt>
lea    0xe20(%rip),%rsi
jmp    1285 <gLEDOn+0x155>
lea    0xe33(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1,%edx
call   1050 <sprintf@plt>
lea    0xe39(%rip),%rsi
mov    %rbx,%rdi
call   1040 <popen@plt>
test   %rax,%rax
je     1218 <gLEDOn+0xe8>
mov    %rax,%rdi
call   1030 <pclose@plt>
lea    0xe00(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x2,%edx
call   1050 <sprintf@plt>
lea    0xe06(%rip),%rsi
mov    %rbx,%rdi
call   1040 <popen@plt>
test   %rax,%rax
je     124b <gLEDOn+0x11b>
mov    %rax,%rdi
call   1030 <pclose@plt>
lea    0xdcd(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3,%edx
call   1050 <sprintf@plt>
lea    0xdd3(%rip),%rsi
mov    %rbx,%rdi
call   1040 <popen@plt>
test   %rax,%rax
je     127e <gLEDOn+0x14e>
mov    %rax,%rdi
call   1030 <pclose@plt>
lea    0xd9a(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x4,%edx
call   1050 <sprintf@plt>
lea    0xda0(%rip),%rsi
mov    %rbx,%rdi
call   1040 <popen@plt>
test   %rax,%rax
je     12b9 <gLEDOn+0x189>
mov    %rax,%rdi
add    $0x80,%rsp
pop    %rbx
jmp    1030 <pclose@plt>
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [31 x i8] c"/bin/echo -n %d1 > /dev/led_sr\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"/bin/echo -n %d0 > /dev/led_sr\00"
define void @gLEDOn(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [128 x i8]
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %29
8: ; preds = %1
store i32 0, i32* %4
br label %9
9: ; preds = %25, %8
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 4
br i1 %11, label %12, label %28
12: ; preds = %9
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
%16 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%18 = call i32* @popen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %3
%19 = load i32*, i32** %3
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %12
%22 = load i32*, i32** %3
%23 = call i32 @pclose(i32* %22)
br label %24
24: ; preds = %21, %12
br label %25
25: ; preds = %24
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %9
28: ; preds = %9
br label %50
29: ; preds = %1
store i32 0, i32* %4
br label %30
30: ; preds = %46, %29
%31 = load i32, i32* %4
%32 = icmp slt i32 %31, 4
br i1 %32, label %33, label %49
33: ; preds = %30
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
%37 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%39 = call i32* @popen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %39, i32** %3
%40 = load i32*, i32** %3
%41 = icmp ne i32* %40, null
br i1 %41, label %42, label %45
42: ; preds = %33
%43 = load i32*, i32** %3
%44 = call i32 @pclose(i32* %43)
br label %45
45: ; preds = %42, %33
br label %46
46: ; preds = %45
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 1
store i32 %48, i32* %4
br label %30
49: ; preds = %30
br label %50
50: ; preds = %49, %28
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"/bin/echo -n %d1 > /dev/led_sr\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"/bin/echo -n %d0 > /dev/led_sr\00"
define void @gLEDOn(i32 %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = icmp eq i32 %0, 0
br i1 %4, label %9, label %5
5: ; preds = %1
%6 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 1)
%7 = call i32* @popen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %15, label %13
9: ; preds = %1
%10 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 1)
%11 = call i32* @popen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %33, label %31
13: ; preds = %5
%14 = tail call i32 @pclose(i32* %7)
br label %15
15: ; preds = %5, %13
%16 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 2)
%17 = call i32* @popen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = tail call i32 @pclose(i32* %17)
br label %21
21: ; preds = %19, %15
%22 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 3)
%23 = call i32* @popen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = tail call i32 @pclose(i32* %23)
br label %27
27: ; preds = %25, %21
%28 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 4)
%29 = call i32* @popen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %52, label %49
31: ; preds = %9
%32 = tail call i32 @pclose(i32* %11)
br label %33
33: ; preds = %9, %31
%34 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 2)
%35 = call i32* @popen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp eq i32* %35, null
br i1 %36, label %39, label %37
37: ; preds = %33
%38 = tail call i32 @pclose(i32* %35)
br label %39
39: ; preds = %37, %33
%40 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 3)
%41 = call i32* @popen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%42 = icmp eq i32* %41, null
br i1 %42, label %45, label %43
43: ; preds = %39
%44 = tail call i32 @pclose(i32* %41)
br label %45
45: ; preds = %43, %39
%46 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 4)
%47 = call i32* @popen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%48 = icmp eq i32* %47, null
br i1 %48, label %52, label %49
49: ; preds = %45, %27
%50 = phi i32* [ %29, %27 ], [ %47, %45 ]
%51 = tail call i32 @pclose(i32* %50)
br label %52
52: ; preds = %49, %45, %27
ret void
}