#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 WEXITSTATUS(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int /*<<< orphan*/ system(char *);
int os_kmod_unload(const char *module_name) {
  char sys_cmd[512];
  int ret;
  sprintf(sys_cmd, "lsmod | grep -q %s", module_name);
  ret = WEXITSTATUS(system(sys_cmd));
  if (ret == 0) {
    sprintf(sys_cmd, "modprobe -r %s", module_name);
    ret = WEXITSTATUS(system(sys_cmd));
    if (ret != 0)
      return ret;
  }
  return 0;
}


x86 assembly (clang, -O0):
<os_kmod_unload>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xeaf(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x210(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,-0x214(%rbp)
cmpl   $0x0,-0x214(%rbp)
jne    11cc <os_kmod_unload+0x9c>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe85(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x210(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,-0x214(%rbp)
cmpl   $0x0,-0x214(%rbp)
je     11c7 <os_kmod_unload+0x97>
mov    -0x214(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d3 <os_kmod_unload+0xa3>
jmp    11cc <os_kmod_unload+0x9c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_kmod_unload>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%r14
lea    0xebc(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <system@plt>
mov    %eax,%edi
call   1040 <WEXITSTATUS@plt>
test   %eax,%eax
jne    118d <os_kmod_unload+0x5d>
lea    0xea7(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <system@plt>
mov    %eax,%edi
call   1040 <WEXITSTATUS@plt>
test   %eax,%eax
jne    118f <os_kmod_unload+0x5f>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"lsmod | grep -q %s\00"
@.str.1 = [15 x i8] c"modprobe -r %s\00"
define i32 @os_kmod_unload(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [512 x i8]
%5 = alloca i32
store i8* %0, i8** %3
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = load i8*, i8** %3
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%10 = call i32 @system(i8* %9)
%11 = call i32 @WEXITSTATUS(i32 %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %26
14: ; preds = %1
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%16 = load i8*, i8** %3
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%19 = call i32 @system(i8* %18)
%20 = call i32 @WEXITSTATUS(i32 %19)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = load i32, i32* %5
store i32 %24, i32* %2
br label %27
25: ; preds = %14
br label %26
26: ; preds = %25, %1
store i32 0, i32* %2
br label %27
27: ; preds = %26, %23
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str = [19 x i8] c"lsmod | grep -q %s\00"
@.str.1 = [15 x i8] c"modprobe -r %s\00"
define i32 @os_kmod_unload(i8* %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i32 @system(i8* %3)
%6 = tail call i32 @WEXITSTATUS(i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%10 = call i32 @system(i8* %3)
%11 = tail call i32 @WEXITSTATUS(i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %8, %1
br label %14
14: ; preds = %8, %13
%15 = phi i32 [ 0, %13 ], [ %11, %8 ]
ret i32 %15
}