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

/* Variables and functions */
scalar_t__ cc_up_is_valid_system_return(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
scalar_t__ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ system(char *);
int cc_up_reload_kernel(char *cc_up_kexe) {
  pid_t status;
  char command[64];
  if (snprintf(command, 64, "rmmod %s", cc_up_kexe) < 0) {
    printf("system command joint failed. \n");
    return -1;
  }
  status = system(command);
  if (cc_up_is_valid_system_return(status) < 0) {
    printf("insert kernel failed, maybe no module exist. \n");
    ;
  }
  if (snprintf(command, 64, "insmod %s", cc_up_kexe) < 0) {
    printf("system command joint failed. \n");
    return -1;
  }
  status = system(command);
  if (cc_up_is_valid_system_return(status) < 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<cc_up_reload_kernel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x40,%esi
lea    0xea0(%rip),%rdx
call   1060 <snprintf@plt>
cmp    $0x0,%rax
jge    1187 <cc_up_reload_kernel+0x47>
lea    0xe93(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <cc_up_reload_kernel+0xdd>
lea    -0x60(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <cc_up_is_valid_system_return@plt>
cmp    $0x0,%rax
jge    11b1 <cc_up_reload_kernel+0x71>
lea    0xe7c(%rip),%rdi
call   1050 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x40,%esi
lea    0xe92(%rip),%rdx
call   1060 <snprintf@plt>
cmp    $0x0,%rax
jge    11ec <cc_up_reload_kernel+0xac>
lea    0xe2e(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <cc_up_reload_kernel+0xdd>
lea    -0x60(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <cc_up_is_valid_system_return@plt>
cmp    $0x0,%rax
jge    1216 <cc_up_reload_kernel+0xd6>
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <cc_up_reload_kernel+0xdd>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cc_up_reload_kernel>:
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%rbx
lea    0xeb1(%rip),%rdx
mov    %rsp,%rdi
mov    $0x40,%esi
mov    %rbx,%rcx
call   1060 <snprintf@plt>
test   %rax,%rax
js     11b5 <cc_up_reload_kernel+0x75>
mov    %rsp,%rdi
call   1050 <system@plt>
mov    %eax,%edi
call   1030 <cc_up_is_valid_system_return@plt>
test   %rax,%rax
jns    1184 <cc_up_reload_kernel+0x44>
lea    0xe94(%rip),%rdi
call   1040 <puts@plt>
lea    0xe7e(%rip),%rdx
mov    %rsp,%rdi
mov    $0x40,%esi
mov    %rbx,%rcx
call   1060 <snprintf@plt>
test   %rax,%rax
js     11b5 <cc_up_reload_kernel+0x75>
mov    %rsp,%rdi
call   1050 <system@plt>
mov    %eax,%edi
call   1030 <cc_up_is_valid_system_return@plt>
sar    $0x3f,%rax
jmp    11c6 <cc_up_reload_kernel+0x86>
lea    0xe85(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"rmmod %s\00"
@.str.1 = [31 x i8] c"system command joint failed. \0A\00"
@.str.2 = [47 x i8] c"insert kernel failed, maybe no module exist. \0A\00"
@.str.3 = [10 x i8] c"insmod %s\00"
define i32 @cc_up_reload_kernel(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [64 x i8]
store i8* %0, i8** %3
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%7 = load i8*, i8** %3
%8 = call i64 @snprintf(i8* %6, i32 64, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %35
12: ; preds = %1
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%14 = call i32 @system(i8* %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = call i64 @cc_up_is_valid_system_return(i32 %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %12
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%22 = load i8*, i8** %3
%23 = call i64 @snprintf(i8* %21, i32 64, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %35
27: ; preds = %20
%28 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%29 = call i32 @system(i8* %28)
store i32 %29, i32* %4
%30 = load i32, i32* %4
%31 = call i64 @cc_up_is_valid_system_return(i32 %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27
store i32 -1, i32* %2
br label %35
34: ; preds = %27
store i32 0, i32* %2
br label %35
35: ; preds = %34, %33, %25, %10
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@.str = [9 x i8] c"rmmod %s\00"
@.str.3 = [10 x i8] c"insmod %s\00"
@str.4 = [46 x i8] c"insert kernel failed, maybe no module exist. \00"
@str.5 = [30 x i8] c"system command joint failed. \00"
define i32 @cc_up_reload_kernel(i8* %0) {
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%4 = call i64 @snprintf(i8* %3, i32 64, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.5, i64 0, i64 0))
br label %24
8: ; preds = %1
%9 = call i32 @system(i8* %3)
%10 = call i64 @cc_up_is_valid_system_return(i32 %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.4, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = call i64 @snprintf(i8* %3, i32 64, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.5, i64 0, i64 0))
br label %24
19: ; preds = %14
%20 = call i32 @system(i8* %3)
%21 = call i64 @cc_up_is_valid_system_return(i32 %20)
%22 = ashr i64 %21, 63
%23 = trunc i64 %22 to i32
br label %24
24: ; preds = %19, %17, %6
%25 = phi i32 [ -1, %6 ], [ -1, %17 ], [ %23, %19 ]
ret i32 %25
}