#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*/ chdir(char *);
int /*<<< orphan*/ fb_close();
int /*<<< orphan*/ input_close();
scalar_t__ is_fb_available();
int /*<<< orphan*/ logprintf(char *);
int /*<<< orphan*/ qfprintf(char *, char *);
int /*<<< orphan*/ sync();
int /*<<< orphan*/ system_logged(char *);
int /*<<< orphan*/ umount(char *);
int /*<<< orphan*/ umount_lv(char *);
void do_shutdown(void) {
  logprintf("0stopping tssrv");
  system_logged("killall tssrv");
  system_logged("killall adbd");
  qfprintf("/sys/class/usb_composite/adb/enable", "0");
  qfprintf("/sys/class/usb_composite/rndis/enable", "0");
  logprintf("0unmounting base volumes");
  umount_lv("media");
  umount_lv("root");
  logprintf("0unmounting base partitions");
  logprintf("0 - /mnt/boot");
  umount("/mnt/boot");
  logprintf("0 - /mnt/firmware");
  umount("/mnt/firmware");
  logprintf("0disabling framebuffer");
  if (is_fb_available())
    fb_close();
  logprintf("0disabling input");
  input_close();
  logprintf("0unmounting all volumes");
  (void)chdir("/");
  sync();
  qfprintf("/proc/sysrq-trigger", "u");
  logprintf("0syncing");
  sync();
}


x86 assembly (clang, -O0):
<do_shutdown>:
push   %rbp
mov    %rsp,%rbp
lea    0xe55(%rip),%rdi
call   10c0 <logprintf@plt>
lea    0xe59(%rip),%rdi
call   1060 <system_logged@plt>
lea    0xe5b(%rip),%rdi
call   1060 <system_logged@plt>
lea    0xe5c(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1080 <qfprintf@plt>
lea    0xe6f(%rip),%rdi
lea    0xe66(%rip),%rsi
call   1080 <qfprintf@plt>
lea    0xe82(%rip),%rdi
call   10c0 <logprintf@plt>
lea    0xe8f(%rip),%rdi
call   10b0 <umount_lv@plt>
lea    0xe89(%rip),%rdi
call   10b0 <umount_lv@plt>
lea    0xe82(%rip),%rdi
call   10c0 <logprintf@plt>
lea    0xe92(%rip),%rdi
call   10c0 <logprintf@plt>
lea    0xe8a(%rip),%rdi
call   1040 <umount@plt>
lea    0xe88(%rip),%rdi
call   10c0 <logprintf@plt>
lea    0xe80(%rip),%rdi
call   1040 <umount@plt>
lea    0xe82(%rip),%rdi
call   10c0 <logprintf@plt>
mov    $0x0,%al
call   1090 <is_fb_available@plt>
cmp    $0x0,%rax
je     1272 <do_shutdown+0xd2>
mov    $0x0,%al
call   1030 <fb_close@plt>
lea    0xe75(%rip),%rdi
call   10c0 <logprintf@plt>
mov    $0x0,%al
call   10a0 <input_close@plt>
lea    0xe73(%rip),%rdi
call   10c0 <logprintf@plt>
lea    0xe7f(%rip),%rdi
call   1050 <chdir@plt>
mov    $0x0,%al
call   1070 <sync@plt>
lea    0xe6e(%rip),%rdi
lea    0xe7b(%rip),%rsi
call   1080 <qfprintf@plt>
lea    0xe71(%rip),%rdi
call   10c0 <logprintf@plt>
mov    $0x0,%al
call   1070 <sync@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_shutdown>:
push   %rbx
lea    0xe58(%rip),%rdi
call   10c0 <logprintf@plt>
lea    0xe5c(%rip),%rdi
call   1060 <system_logged@plt>
lea    0xe5e(%rip),%rdi
call   1060 <system_logged@plt>
lea    0xe5f(%rip),%rdi
lea    0xe7c(%rip),%rbx
mov    %rbx,%rsi
call   1080 <qfprintf@plt>
lea    0xe6f(%rip),%rdi
mov    %rbx,%rsi
call   1080 <qfprintf@plt>
lea    0xe86(%rip),%rdi
call   10c0 <logprintf@plt>
lea    0xe93(%rip),%rdi
call   10b0 <umount_lv@plt>
lea    0xe8d(%rip),%rdi
call   10b0 <umount_lv@plt>
lea    0xe86(%rip),%rdi
call   10c0 <logprintf@plt>
lea    0xe96(%rip),%rdi
call   10c0 <logprintf@plt>
lea    0xe8e(%rip),%rdi
call   1040 <umount@plt>
lea    0xe8c(%rip),%rdi
call   10c0 <logprintf@plt>
lea    0xe84(%rip),%rdi
call   1040 <umount@plt>
lea    0xe86(%rip),%rdi
call   10c0 <logprintf@plt>
xor    %eax,%eax
call   1090 <is_fb_available@plt>
test   %rax,%rax
je     1269 <do_shutdown+0xc9>
xor    %eax,%eax
call   1030 <fb_close@plt>
lea    0xe7e(%rip),%rdi
call   10c0 <logprintf@plt>
xor    %eax,%eax
call   10a0 <input_close@plt>
lea    0xe7c(%rip),%rdi
call   10c0 <logprintf@plt>
lea    0xe88(%rip),%rdi
call   1050 <chdir@plt>
xor    %eax,%eax
call   1070 <sync@plt>
lea    0xe77(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1080 <qfprintf@plt>
lea    0xe7a(%rip),%rdi
call   10c0 <logprintf@plt>
xor    %eax,%eax
pop    %rbx
jmp    1070 <sync@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"0stopping tssrv\00"
@.str.1 = [14 x i8] c"killall tssrv\00"
@.str.2 = [13 x i8] c"killall adbd\00"
@.str.3 = [36 x i8] c"/sys/class/usb_composite/adb/enable\00"
@.str.4 = [2 x i8] c"0\00"
@.str.5 = [38 x i8] c"/sys/class/usb_composite/rndis/enable\00"
@.str.6 = [25 x i8] c"0unmounting base volumes\00"
@.str.7 = [6 x i8] c"media\00"
@.str.8 = [5 x i8] c"root\00"
@.str.9 = [28 x i8] c"0unmounting base partitions\00"
@.str.10 = [14 x i8] c"0 - /mnt/boot\00"
@.str.11 = [10 x i8] c"/mnt/boot\00"
@.str.12 = [18 x i8] c"0 - /mnt/firmware\00"
@.str.13 = [14 x i8] c"/mnt/firmware\00"
@.str.14 = [23 x i8] c"0disabling framebuffer\00"
@.str.15 = [17 x i8] c"0disabling input\00"
@.str.16 = [24 x i8] c"0unmounting all volumes\00"
@.str.17 = [2 x i8] c"/\00"
@.str.18 = [20 x i8] c"/proc/sysrq-trigger\00"
@.str.19 = [2 x i8] c"u\00"
@.str.20 = [9 x i8] c"0syncing\00"
define void @do_shutdown() {
%1 = call i32 @logprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%2 = call i32 @system_logged(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%3 = call i32 @system_logged(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%4 = call i32 @qfprintf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%5 = call i32 @qfprintf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%6 = call i32 @logprintf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%7 = call i32 @umount_lv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%8 = call i32 @umount_lv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%9 = call i32 @logprintf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0))
%10 = call i32 @logprintf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0))
%11 = call i32 @umount(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
%12 = call i32 @logprintf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
%13 = call i32 @umount(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0))
%14 = call i32 @logprintf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0))
%15 = call i64 (...) @is_fb_available()
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %0
%18 = call i32 (...) @fb_close()
br label %19
19: ; preds = %17, %0
%20 = call i32 @logprintf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.15, i64 0, i64 0))
%21 = call i32 (...) @input_close()
%22 = call i32 @logprintf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.16, i64 0, i64 0))
%23 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
%24 = call i32 (...) @sync()
%25 = call i32 @qfprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.18, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.19, i64 0, i64 0))
%26 = call i32 @logprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.20, i64 0, i64 0))
%27 = call i32 (...) @sync()
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"0stopping tssrv\00"
@.str.1 = [14 x i8] c"killall tssrv\00"
@.str.2 = [13 x i8] c"killall adbd\00"
@.str.3 = [36 x i8] c"/sys/class/usb_composite/adb/enable\00"
@.str.4 = [2 x i8] c"0\00"
@.str.5 = [38 x i8] c"/sys/class/usb_composite/rndis/enable\00"
@.str.6 = [25 x i8] c"0unmounting base volumes\00"
@.str.7 = [6 x i8] c"media\00"
@.str.8 = [5 x i8] c"root\00"
@.str.9 = [28 x i8] c"0unmounting base partitions\00"
@.str.10 = [14 x i8] c"0 - /mnt/boot\00"
@.str.11 = [10 x i8] c"/mnt/boot\00"
@.str.12 = [18 x i8] c"0 - /mnt/firmware\00"
@.str.13 = [14 x i8] c"/mnt/firmware\00"
@.str.14 = [23 x i8] c"0disabling framebuffer\00"
@.str.15 = [17 x i8] c"0disabling input\00"
@.str.16 = [24 x i8] c"0unmounting all volumes\00"
@.str.17 = [2 x i8] c"/\00"
@.str.18 = [20 x i8] c"/proc/sysrq-trigger\00"
@.str.19 = [2 x i8] c"u\00"
@.str.20 = [9 x i8] c"0syncing\00"
define void @do_shutdown() {
%1 = tail call i32 @logprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @system_logged(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @system_logged(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i32 @qfprintf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%5 = tail call i32 @qfprintf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%6 = tail call i32 @logprintf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%7 = tail call i32 @umount_lv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%8 = tail call i32 @umount_lv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%9 = tail call i32 @logprintf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0))
%10 = tail call i32 @logprintf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0))
%11 = tail call i32 @umount(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
%12 = tail call i32 @logprintf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
%13 = tail call i32 @umount(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0))
%14 = tail call i32 @logprintf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0))
%15 = tail call i64 (...) @is_fb_available()
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %0
%18 = tail call i32 (...) @fb_close()
br label %19
19: ; preds = %17, %0
%20 = tail call i32 @logprintf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.15, i64 0, i64 0))
%21 = tail call i32 (...) @input_close()
%22 = tail call i32 @logprintf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.16, i64 0, i64 0))
%23 = tail call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
%24 = tail call i32 (...) @sync()
%25 = tail call i32 @qfprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.18, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.19, i64 0, i64 0))
%26 = tail call i32 @logprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.20, i64 0, i64 0))
%27 = tail call i32 (...) @sync()
ret void
}