#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*/ gLEDOn(int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ usleep(int);
void gSigHandler(int signo) {
  FILE *fp0 = NULL;
  FILE *fp1 = NULL;
  FILE *fp2 = NULL;
  int i;
  printf("6Q soft-reset:%d\n", signo);
  fp0 = popen("/bin/rm -rf /dev/led ; /bin/mknod /dev/led_sr c 1987 1", "r");
  if (fp0) {
    pclose(fp0);
  }
  for (i = 0; i < 10; i++) {
    gLEDOn(0);
    usleep(1000 * 100);
    gLEDOn(1);
    usleep(1000 * 100);
  }
  fp1 = popen("/bin/rm -rf /home/CEAMS/6QWeb/cgi-bin/ip.manual", "r");
  if (fp1) {
    pclose(fp1);
  }
  fp2 = popen("/bin/sync;/sbin/reboot", "r");
  if (fp2) {
    pclose(fp2);
  }
}


x86 assembly (clang, -O0):
<gSigHandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
lea    0xe89(%rip),%rdi
lea    0xeb9(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ad <gSigHandler+0x5d>
mov    -0x10(%rbp),%rdi
call   1050 <pclose@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0xa,-0x24(%rbp)
jge    11f1 <gSigHandler+0xa1>
xor    %edi,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
mov    $0x1,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b4 <gSigHandler+0x64>
lea    0xe53(%rip),%rdi
lea    0xe4a(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     121c <gSigHandler+0xcc>
mov    -0x18(%rbp),%rdi
call   1050 <pclose@plt>
lea    0xe58(%rip),%rdi
lea    0xe1f(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1247 <gSigHandler+0xf7>
mov    -0x20(%rbp),%rdi
call   1050 <pclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gSigHandler>:
push   %rax
mov    %edi,%esi
lea    0xea6(%rip),%rdi
call   1040 <printf@plt>
lea    0xeac(%rip),%rdi
lea    0xedc(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     117f <gSigHandler+0x2f>
mov    %rax,%rdi
call   1050 <pclose@plt>
xor    %edi,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
mov    $0x1,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
xor    %edi,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
mov    $0x1,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
xor    %edi,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
mov    $0x1,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
xor    %edi,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
mov    $0x1,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
xor    %edi,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
mov    $0x1,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
xor    %edi,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
mov    $0x1,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
xor    %edi,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
mov    $0x1,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
xor    %edi,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
mov    $0x1,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
xor    %edi,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
mov    $0x1,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
xor    %edi,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
mov    $0x1,%edi
call   1030 <gLEDOn@plt>
mov    $0x186a0,%edi
call   1070 <usleep@plt>
lea    0xd53(%rip),%rdi
lea    0xd4a(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     1311 <gSigHandler+0x1c1>
mov    %rax,%rdi
call   1050 <pclose@plt>
lea    0xd63(%rip),%rdi
lea    0xd2a(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     1332 <gSigHandler+0x1e2>
mov    %rax,%rdi
pop    %rax
jmp    1050 <pclose@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [18 x i8] c"6Q soft-reset:%d\0A\00"
@.str.1 = [55 x i8] c"/bin/rm -rf /dev/led ; /bin/mknod /dev/led_sr c 1987 1\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [48 x i8] c"/bin/rm -rf /home/CEAMS/6QWeb/cgi-bin/ip.manual\00"
@.str.4 = [23 x i8] c"/bin/sync;/sbin/reboot\00"
define void @gSigHandler(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %2
store i32* null, i32** %3
store i32* null, i32** %4
store i32* null, i32** %5
%7 = load i32, i32* %2
%8 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i32* @popen(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %9, i32** %3
%10 = load i32*, i32** %3
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i32*, i32** %3
%14 = call i32 @pclose(i32* %13)
br label %15
15: ; preds = %12, %1
store i32 0, i32* %6
br label %16
16: ; preds = %24, %15
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 10
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = call i32 @gLEDOn(i32 0)
%21 = call i32 @usleep(i32 100000)
%22 = call i32 @gLEDOn(i32 1)
%23 = call i32 @usleep(i32 100000)
br label %24
24: ; preds = %19
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %16
27: ; preds = %16
%28 = call i32* @popen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %28, i32** %4
%29 = load i32*, i32** %4
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i32*, i32** %4
%33 = call i32 @pclose(i32* %32)
br label %34
34: ; preds = %31, %27
%35 = call i32* @popen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %35, i32** %5
%36 = load i32*, i32** %5
%37 = icmp ne i32* %36, null
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i32*, i32** %5
%40 = call i32 @pclose(i32* %39)
br label %41
41: ; preds = %38, %34
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"6Q soft-reset:%d\0A\00"
@.str.1 = [55 x i8] c"/bin/rm -rf /dev/led ; /bin/mknod /dev/led_sr c 1987 1\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [48 x i8] c"/bin/rm -rf /home/CEAMS/6QWeb/cgi-bin/ip.manual\00"
@.str.4 = [23 x i8] c"/bin/sync;/sbin/reboot\00"
define void @gSigHandler(i32 %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = tail call i32* @popen(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 @pclose(i32* %3)
br label %7
7: ; preds = %5, %1
%8 = tail call i32 @gLEDOn(i32 0)
%9 = tail call i32 @usleep(i32 100000)
%10 = tail call i32 @gLEDOn(i32 1)
%11 = tail call i32 @usleep(i32 100000)
%12 = tail call i32 @gLEDOn(i32 0)
%13 = tail call i32 @usleep(i32 100000)
%14 = tail call i32 @gLEDOn(i32 1)
%15 = tail call i32 @usleep(i32 100000)
%16 = tail call i32 @gLEDOn(i32 0)
%17 = tail call i32 @usleep(i32 100000)
%18 = tail call i32 @gLEDOn(i32 1)
%19 = tail call i32 @usleep(i32 100000)
%20 = tail call i32 @gLEDOn(i32 0)
%21 = tail call i32 @usleep(i32 100000)
%22 = tail call i32 @gLEDOn(i32 1)
%23 = tail call i32 @usleep(i32 100000)
%24 = tail call i32 @gLEDOn(i32 0)
%25 = tail call i32 @usleep(i32 100000)
%26 = tail call i32 @gLEDOn(i32 1)
%27 = tail call i32 @usleep(i32 100000)
%28 = tail call i32 @gLEDOn(i32 0)
%29 = tail call i32 @usleep(i32 100000)
%30 = tail call i32 @gLEDOn(i32 1)
%31 = tail call i32 @usleep(i32 100000)
%32 = tail call i32 @gLEDOn(i32 0)
%33 = tail call i32 @usleep(i32 100000)
%34 = tail call i32 @gLEDOn(i32 1)
%35 = tail call i32 @usleep(i32 100000)
%36 = tail call i32 @gLEDOn(i32 0)
%37 = tail call i32 @usleep(i32 100000)
%38 = tail call i32 @gLEDOn(i32 1)
%39 = tail call i32 @usleep(i32 100000)
%40 = tail call i32 @gLEDOn(i32 0)
%41 = tail call i32 @usleep(i32 100000)
%42 = tail call i32 @gLEDOn(i32 1)
%43 = tail call i32 @usleep(i32 100000)
%44 = tail call i32 @gLEDOn(i32 0)
%45 = tail call i32 @usleep(i32 100000)
%46 = tail call i32 @gLEDOn(i32 1)
%47 = tail call i32 @usleep(i32 100000)
%48 = tail call i32* @popen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%49 = icmp eq i32* %48, null
br i1 %49, label %52, label %50
50: ; preds = %7
%51 = tail call i32 @pclose(i32* %48)
br label %52
52: ; preds = %50, %7
%53 = tail call i32* @popen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%54 = icmp eq i32* %53, null
br i1 %54, label %57, label %55
55: ; preds = %52
%56 = tail call i32 @pclose(i32* %53)
br label %57
57: ; preds = %55, %52
ret void
}