#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*/ _printf(int, int, char *, ...);
int /*<<< orphan*/ clearLine(int, int);
void stub1(int);
void stub2(int);
int svcCustomKernelCommand(int, int);
int /*<<< orphan*/ svcShutdown(int);
void wait_format_confirmation(void) {
  int timeout = 600;
  while (1) {
    _printf(
        20, 30,
        "No NAND dump detected. SD Format and complete NAND dump required.");
    _printf(20, 40,
            "Press the POWER button to format SD card otherwise the console "
            "will reboot in %d seconds.",
            timeout / 10);
    if (svcCustomKernelCommand(1, 0x0d8000e8) & 0x01)
      break;
    if (--timeout == 0) {
      ((void (*)(int))0x1071D668)(1000);
      svcShutdown(1);
    }
    ((void (*)(int))0x1071D668)(100);
  }
  clearLine(30, 0x000000FF);
  clearLine(40, 0x000000FF);
}


x86 assembly (clang, -O0):
<wait_format_confirmation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x258,-0x4(%rbp)
mov    $0x14,%edi
mov    $0x1e,%esi
lea    0xea0(%rip),%rdx
mov    $0x0,%al
call   1030 <_printf@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    $0x14,%edi
mov    $0x28,%esi
lea    0xebd(%rip),%rdx
mov    $0x0,%al
call   1030 <_printf@plt>
mov    $0x1,%edi
mov    $0xd8000e8,%esi
call   1060 <svcCustomKernelCommand@plt>
and    $0x1,%eax
cmp    $0x0,%eax
je     11ac <wait_format_confirmation+0x6c>
jmp    11e5 <wait_format_confirmation+0xa5>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jne    11d4 <wait_format_confirmation+0x94>
mov    $0x3e8,%edi
mov    $0x1071d668,%eax
call   *%rax
mov    $0x1,%edi
call   1050 <svcShutdown@plt>
mov    $0x64,%edi
mov    $0x1071d668,%eax
call   *%rax
jmp    114f <wait_format_confirmation+0xf>
mov    $0x1e,%edi
mov    $0xff,%esi
call   1040 <clearLine@plt>
mov    $0x28,%edi
mov    $0xff,%esi
call   1040 <clearLine@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_format_confirmation>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x258,%ebp
lea    0xead(%rip),%r14
lea    0xee8(%rip),%r15
mov    $0x1071d668,%ebx
jmp    117a <wait_format_confirmation+0x3a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x64,%edi
call   *%rbx
add    $0xffffffff,%ebp
mov    $0x14,%edi
mov    $0x1e,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <_printf@plt>
movslq %ebp,%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
sar    $0x22,%rcx
add    %eax,%ecx
mov    $0x14,%edi
mov    $0x28,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <_printf@plt>
mov    $0x1,%edi
mov    $0xd8000e8,%esi
call   1060 <svcCustomKernelCommand@plt>
test   $0x1,%al
jne    11e4 <wait_format_confirmation+0xa4>
cmp    $0x1,%ebp
jne    1170 <wait_format_confirmation+0x30>
mov    $0x3e8,%edi
call   *%rbx
mov    $0x1,%edi
call   1050 <svcShutdown@plt>
jmp    1170 <wait_format_confirmation+0x30>
mov    $0x1e,%edi
mov    $0xff,%esi
call   1040 <clearLine@plt>
mov    $0x28,%edi
mov    $0xff,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <clearLine@plt>

LLVM IR (-O0):
@.str = [66 x i8] c"No NAND dump detected. SD Format and complete NAND dump required.\00"
@.str.1 = [90 x i8] c"Press the POWER button to format SD card otherwise the console will reboot in %d seconds.\00"
define void @wait_format_confirmation() {
%1 = alloca i32
store i32 600, i32* %1
br label %2
2: ; preds = %0, %17
%3 = call i32 (i32, i32, i8*, ...) @_printf(i32 20, i32 30, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* %1
%5 = sdiv i32 %4, 10
%6 = call i32 (i32, i32, i8*, ...) @_printf(i32 20, i32 40, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = call i32 @svcCustomKernelCommand(i32 1, i32 226492648)
%8 = and i32 %7, 1
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
br label %18
11: ; preds = %2
%12 = load i32, i32* %1
%13 = add nsw i32 %12, -1
store i32 %13, i32* %1
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @svcShutdown(i32 1)
br label %17
17: ; preds = %15, %11
br label %2
18: ; preds = %10
%19 = call i32 @clearLine(i32 30, i32 255)
%20 = call i32 @clearLine(i32 40, i32 255)
ret void
}

LLVM IR (-O2):
@.str = [66 x i8] c"No NAND dump detected. SD Format and complete NAND dump required.\00"
@.str.1 = [90 x i8] c"Press the POWER button to format SD card otherwise the console will reboot in %d seconds.\00"
define void @wait_format_confirmation() {
br label %1
1: ; preds = %14, %0
%2 = phi i32 [ 600, %0 ], [ %10, %14 ]
%3 = tail call i32 (i32, i32, i8*, ...) @_printf(i32 20, i32 30, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%4 = sdiv i32 %2, 10
%5 = tail call i32 (i32, i32, i8*, ...) @_printf(i32 20, i32 40, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = tail call i32 @svcCustomKernelCommand(i32 1, i32 226492648)
%7 = and i32 %6, 1
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = add nsw i32 %2, -1
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
tail call void inttoptr (i64 275895912 to void (i32)*)(i32 1000)
%13 = tail call i32 @svcShutdown(i32 1)
br label %14
14: ; preds = %12, %9
tail call void inttoptr (i64 275895912 to void (i32)*)(i32 100)
br label %1
15: ; preds = %1
%16 = tail call i32 @clearLine(i32 30, i32 255)
%17 = tail call i32 @clearLine(i32 40, i32 255)
ret void
}