#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 */
struct menu_s {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ menu_display_error(struct menu_s *, int, char *, char *);
int /*<<< orphan*/ sleep(int);
scalar_t__ system(char *);
int /*<<< orphan*/ write(int, char *, int);
void ftp_upgrade(struct menu_s *parent, int displayfd, int arg) {
  write(displayfd, "\x1f\x72\x00", 3);
  write(displayfd, "\x1f\x24\x00\x00\x01\x00", 6);
  write(displayfd, "                ", 16);
  write(displayfd, "\x1f\x24\x00\x00\x00\x00", 6);
  write(displayfd, "Downloading...  ", 16);
  chdir("/tmp");
  if (system("/bin/ftpget -u looperupgrade -p vf605pk "
             "upgrade.looperlative.com lp1upgrade.tar lp1upgrade.tar"
             "> /dev/null 2>&1") != 0) {
    menu_display_error(parent, displayfd, "Upgrade Error", "Download failed");
    return;
  }
  write(displayfd, "\x1f\x24\x00\x00\x00\x00", 6);
  write(displayfd, "Unpacking...    ", 16);
  if (system("tar xf lp1upgrade.tar > /dev/null 2>&1") != 0) {
    menu_display_error(parent, displayfd, "Upgrade Error", "Unpack failed");
    return;
  }
  write(displayfd, "\x1f\x24\x00\x00\x00\x00", 6);
  write(displayfd, "Upgrading...    ", 16);
  if (system("sh upgrade.sh > /dev/console 2>&1") != 0) {
    menu_display_error(parent, displayfd, "Upgrade Error", "Upgrade failed");
    return;
  }
  write(displayfd, "\x1f\x24\x00\x00\x00\x00", 6);
  write(displayfd, "Upgrade Complete", 16);
  write(displayfd, "\x1f\x24\x00\x00\x01\x00Please reboot", 19);
  sleep(2);
  while (1)
    ;
}


x86 assembly (clang, -O0):
<ftp_upgrade>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    0xe94(%rip),%rsi
mov    $0x3,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
lea    0xe84(%rip),%rsi
mov    $0x6,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
lea    0xe92(%rip),%rsi
mov    $0x10,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
lea    0xe63(%rip),%rsi
mov    $0x6,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
lea    0xe7b(%rip),%rsi
mov    $0x10,%edx
call   1040 <write@plt>
lea    0xe7b(%rip),%rdi
call   1050 <chdir@plt>
lea    0xe74(%rip),%rdi
call   1060 <system@plt>
cmp    $0x0,%rax
je     1207 <ftp_upgrade+0xb7>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    0xec6(%rip),%rdx
lea    0xecd(%rip),%rcx
call   1030 <menu_display_error@plt>
jmp    130c <ftp_upgrade+0x1bc>
mov    -0xc(%rbp),%edi
lea    0xdfa(%rip),%rsi
mov    $0x6,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
lea    0xeb5(%rip),%rsi
mov    $0x10,%edx
call   1040 <write@plt>
lea    0xeb5(%rip),%rdi
call   1060 <system@plt>
cmp    $0x0,%rax
je     1264 <ftp_upgrade+0x114>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    0xe69(%rip),%rdx
lea    0xeb8(%rip),%rcx
call   1030 <menu_display_error@plt>
jmp    130c <ftp_upgrade+0x1bc>
mov    -0xc(%rbp),%edi
lea    0xd9d(%rip),%rsi
mov    $0x6,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
lea    0xe9e(%rip),%rsi
mov    $0x10,%edx
call   1040 <write@plt>
lea    0xe9e(%rip),%rdi
call   1060 <system@plt>
cmp    $0x0,%rax
je     12c1 <ftp_upgrade+0x171>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    0xe0c(%rip),%rdx
lea    0xe9c(%rip),%rcx
call   1030 <menu_display_error@plt>
jmp    130c <ftp_upgrade+0x1bc>
mov    -0xc(%rbp),%edi
lea    0xd40(%rip),%rsi
mov    $0x6,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
lea    0xe83(%rip),%rsi
mov    $0x10,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
lea    0xd1f(%rip),%rsi
mov    $0x13,%edx
call   1040 <write@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
jmp    1307 <ftp_upgrade+0x1b7>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftp_upgrade>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xea0(%rip),%rsi
mov    %ebx,%edi
mov    $0x3,%edx
call   1040 <write@plt>
lea    0xe91(%rip),%rsi
mov    %ebx,%edi
mov    $0x6,%edx
call   1040 <write@plt>
lea    0xea0(%rip),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   1040 <write@plt>
lea    0xe72(%rip),%rsi
mov    %ebx,%edi
mov    $0x6,%edx
call   1040 <write@plt>
lea    0xe8b(%rip),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   1040 <write@plt>
lea    0xe89(%rip),%rdi
call   1050 <chdir@plt>
lea    0xe82(%rip),%rdi
call   1060 <system@plt>
test   %rax,%rax
je     11de <ftp_upgrade+0x8e>
lea    0xeee(%rip),%rcx
jmp    125c <ftp_upgrade+0x10c>
lea    0xe26(%rip),%rsi
mov    %ebx,%edi
mov    $0x6,%edx
call   1040 <write@plt>
lea    0xee2(%rip),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   1040 <write@plt>
lea    0xee0(%rip),%rdi
call   1060 <system@plt>
test   %rax,%rax
je     121e <ftp_upgrade+0xce>
lea    0xef6(%rip),%rcx
jmp    125c <ftp_upgrade+0x10c>
lea    0xde6(%rip),%rsi
mov    %ebx,%edi
mov    $0x6,%edx
call   1040 <write@plt>
lea    0xee8(%rip),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   1040 <write@plt>
lea    0xee6(%rip),%rdi
call   1060 <system@plt>
test   %rax,%rax
je     1274 <ftp_upgrade+0x124>
lea    0xef7(%rip),%rcx
lea    0xe59(%rip),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <menu_display_error@plt>
lea    0xd90(%rip),%rsi
mov    %ebx,%edi
mov    $0x6,%edx
call   1040 <write@plt>
lea    0xed4(%rip),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   1040 <write@plt>
lea    0xd71(%rip),%rsi
mov    %ebx,%edi
mov    $0x13,%edx
call   1040 <write@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
nopw   0x0(%rax,%rax,1)
jmp    12c0 <ftp_upgrade+0x170>

LLVM IR (-O0):
%struct.menu_s = type { i32 }
@.str = [4 x i8] c"\1Fr\00\00"
@.str.1 = [7 x i8] c"\1F$\00\00\01\00\00"
@.str.2 = [17 x i8] c" \00"
@.str.3 = [7 x i8] c"\1F$\00\00\00\00\00"
@.str.4 = [17 x i8] c"Downloading... \00"
@.str.5 = [5 x i8] c"/tmp\00"
@.str.6 = [111 x i8] c"/bin/ftpget -u looperupgrade -p vf605pk upgrade.looperlative.com lp1upgrade.tar lp1upgrade.tar> /dev/null 2>&1\00"
@.str.7 = [14 x i8] c"Upgrade Error\00"
@.str.8 = [16 x i8] c"Download failed\00"
@.str.9 = [17 x i8] c"Unpacking... \00"
@.str.10 = [39 x i8] c"tar xf lp1upgrade.tar > /dev/null 2>&1\00"
@.str.11 = [14 x i8] c"Unpack failed\00"
@.str.12 = [17 x i8] c"Upgrading... \00"
@.str.13 = [34 x i8] c"sh upgrade.sh > /dev/console 2>&1\00"
@.str.14 = [15 x i8] c"Upgrade failed\00"
@.str.15 = [17 x i8] c"Upgrade Complete\00"
@.str.16 = [20 x i8] c"\1F$\00\00\01\00Please reboot\00"
define void @ftp_upgrade(%struct.menu_s* %0, i32 %1, i32 %2) {
%4 = alloca %struct.menu_s*
%5 = alloca i32
%6 = alloca i32
store %struct.menu_s* %0, %struct.menu_s** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %5
%8 = call i32 @write(i32 %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%9 = load i32, i32* %5
%10 = call i32 @write(i32 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%11 = load i32, i32* %5
%12 = call i32 @write(i32 %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 16)
%13 = load i32, i32* %5
%14 = call i32 @write(i32 %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%15 = load i32, i32* %5
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 16)
%17 = call i32 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%18 = call i64 @system(i8* getelementptr inbounds ([111 x i8], [111 x i8]* @.str.6, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %3
%21 = load %struct.menu_s*, %struct.menu_s** %4
%22 = load i32, i32* %5
%23 = call i32 @menu_display_error(%struct.menu_s* %21, i32 %22, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
br label %55
24: ; preds = %3
%25 = load i32, i32* %5
%26 = call i32 @write(i32 %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%27 = load i32, i32* %5
%28 = call i32 @write(i32 %27, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i32 16)
%29 = call i64 @system(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.10, i64 0, i64 0))
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %24
%32 = load %struct.menu_s*, %struct.menu_s** %4
%33 = load i32, i32* %5
%34 = call i32 @menu_display_error(%struct.menu_s* %32, i32 %33, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
br label %55
35: ; preds = %24
%36 = load i32, i32* %5
%37 = call i32 @write(i32 %36, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%38 = load i32, i32* %5
%39 = call i32 @write(i32 %38, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0), i32 16)
%40 = call i64 @system(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.13, i64 0, i64 0))
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %35
%43 = load %struct.menu_s*, %struct.menu_s** %4
%44 = load i32, i32* %5
%45 = call i32 @menu_display_error(%struct.menu_s* %43, i32 %44, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.14, i64 0, i64 0))
br label %55
46: ; preds = %35
%47 = load i32, i32* %5
%48 = call i32 @write(i32 %47, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%49 = load i32, i32* %5
%50 = call i32 @write(i32 %49, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.15, i64 0, i64 0), i32 16)
%51 = load i32, i32* %5
%52 = call i32 @write(i32 %51, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.16, i64 0, i64 0), i32 19)
%53 = call i32 @sleep(i32 2)
br label %54
54: ; preds = %46, %54
br label %54
55: ; preds = %42, %31, %20
ret void
}

LLVM IR (-O2):
%struct.menu_s = type { i32 }
@.str = [4 x i8] c"\1Fr\00\00"
@.str.1 = [7 x i8] c"\1F$\00\00\01\00\00"
@.str.2 = [17 x i8] c" \00"
@.str.3 = [7 x i8] c"\1F$\00\00\00\00\00"
@.str.4 = [17 x i8] c"Downloading... \00"
@.str.5 = [5 x i8] c"/tmp\00"
@.str.6 = [111 x i8] c"/bin/ftpget -u looperupgrade -p vf605pk upgrade.looperlative.com lp1upgrade.tar lp1upgrade.tar> /dev/null 2>&1\00"
@.str.7 = [14 x i8] c"Upgrade Error\00"
@.str.8 = [16 x i8] c"Download failed\00"
@.str.9 = [17 x i8] c"Unpacking... \00"
@.str.10 = [39 x i8] c"tar xf lp1upgrade.tar > /dev/null 2>&1\00"
@.str.11 = [14 x i8] c"Unpack failed\00"
@.str.12 = [17 x i8] c"Upgrading... \00"
@.str.13 = [34 x i8] c"sh upgrade.sh > /dev/console 2>&1\00"
@.str.14 = [15 x i8] c"Upgrade failed\00"
@.str.15 = [17 x i8] c"Upgrade Complete\00"
@.str.16 = [20 x i8] c"\1F$\00\00\01\00Please reboot\00"
define void @ftp_upgrade(%struct.menu_s* %0, i32 %1, i32 %2) {
%4 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%5 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%6 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 16)
%7 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%8 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 16)
%9 = tail call i32 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%10 = tail call i64 @system(i8* getelementptr inbounds ([111 x i8], [111 x i8]* @.str.6, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %3
%13 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%14 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i32 16)
%15 = tail call i64 @system(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.10, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %12
%18 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%19 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0), i32 16)
%20 = tail call i64 @system(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.13, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %17
%23 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%24 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.15, i64 0, i64 0), i32 16)
%25 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.16, i64 0, i64 0), i32 19)
%26 = tail call i32 @sleep(i32 2)
br label %27
27: ; preds = %22, %27
br label %27
28: ; preds = %17, %12, %3
%29 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), %3 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0), %12 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.14, i64 0, i64 0), %17 ]
%30 = tail call i32 @menu_display_error(%struct.menu_s* %0, i32 %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %29)
ret void
}