#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 */
scalar_t__ EAGAIN;
int O_EXCL;
int O_NONBLOCK;
int delete_module(char const *, int);
scalar_t__ errno;
int /*<<< orphan*/ printf(char *, char const *, char *);
char *strerror(scalar_t__);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  const char *modname = argv[1];
  int ret = -1;
  int maxtry = 10;
  while (maxtry-- > 0) {
    ret = delete_module(modname, O_NONBLOCK | O_EXCL);
    if (ret < 0 && errno == EAGAIN)
      usleep(500000);
    else
      break;
  }
  if (ret != 0)
    printf("Unable to unload driver module \"%s\": %s\n", modname,
           strerror(errno));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0xa,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x20(%rbp)
cmp    $0x0,%eax
jle    11df <main+0x9f>
mov    -0x18(%rbp),%rdi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    0x2e40(%rip),%rax
or     (%rax),%esi
call   1040 <delete_module@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11d5 <main+0x95>
mov    0x2e1d(%rip),%rax
mov    (%rax),%rax
mov    0x2e03(%rip),%rcx
cmp    (%rcx),%rax
jne    11d5 <main+0x95>
mov    $0x7a120,%edi
call   1060 <usleep@plt>
jmp    11da <main+0x9a>
jmp    11df <main+0x9f>
jmp    1170 <main+0x30>
cmpl   $0x0,-0x1c(%rbp)
je     1213 <main+0xd3>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
lea    0xdf2(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x8(%rsi),%rbx
mov    $0xfffffff6,%ebp
mov    0x2e8d(%rip),%r15
mov    0x2e76(%rip),%r12
mov    0x2e67(%rip),%r14
mov    0x2e50(%rip),%r13
mov    (%r12),%esi
or     (%r15),%esi
mov    %rbx,%rdi
call   1040 <delete_module@plt>
test   %eax,%eax
jns    119c <main+0x5c>
mov    (%r14),%rax
cmp    0x0(%r13),%rax
jne    119e <main+0x5e>
mov    $0x7a120,%edi
call   1060 <usleep@plt>
inc    %ebp
jne    1170 <main+0x30>
jmp    119e <main+0x5e>
je     11b8 <main+0x78>
mov    (%r14),%rdi
call   1050 <strerror@plt>
lea    0xe53(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_NONBLOCK = global i32 0
@O_EXCL = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@.str = [41 x i8] c"Unable to unload driver module \22%s\22: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
store i8* %11, i8** %6
store i32 -1, i32* %7
store i32 10, i32* %8
br label %12
12: ; preds = %31, %2
%13 = load i32, i32* %8
%14 = add nsw i32 %13, -1
store i32 %14, i32* %8
%15 = icmp sgt i32 %13, 0
br i1 %15, label %16, label %32
16: ; preds = %12
%17 = load i8*, i8** %6
%18 = load i32, i32* @O_NONBLOCK
%19 = load i32, i32* @O_EXCL
%20 = or i32 %18, %19
%21 = call i32 @delete_module(i8* %17, i32 %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %16
%25 = load i64, i64* @errno
%26 = load i64, i64* @EAGAIN
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @usleep(i32 500000)
br label %31
30: ; preds = %24, %16
br label %32
31: ; preds = %28
br label %12
32: ; preds = %30, %12
%33 = load i32, i32* %7
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i8*, i8** %6
%37 = load i64, i64* @errno
%38 = call i8* @strerror(i64 %37)
%39 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %36, i8* %38)
br label %40
40: ; preds = %35, %32
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@O_NONBLOCK = global i32 0
@O_EXCL = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@.str = [41 x i8] c"Unable to unload driver module \22%s\22: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
br label %5
5: ; preds = %2, %16
%6 = phi i32 [ 9, %2 ], [ %18, %16 ]
%7 = load i32, i32* @O_NONBLOCK
%8 = load i32, i32* @O_EXCL
%9 = or i32 %8, %7
%10 = tail call i32 @delete_module(i8* %4, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %5
%13 = load i64, i64* @errno
%14 = load i64, i64* @EAGAIN
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = tail call i32 @usleep(i32 500000)
%18 = add nsw i32 %6, -1
%19 = icmp eq i32 %6, 0
br i1 %19, label %22, label %5
20: ; preds = %5
%21 = icmp eq i32 %10, 0
br i1 %21, label %26, label %22
22: ; preds = %16, %12, %20
%23 = load i64, i64* @errno
%24 = tail call i8* @strerror(i64 %23)
%25 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %4, i8* %24)
br label %26
26: ; preds = %22, %20
ret i32 0
}