#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 EINVAL;
char *getenv(char *);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *, int *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ usb_umount();
int usb_hotplug(void) {
  char *device, *interface;
  char *action, *product;
  char *type, *devfs;
  int class, subclass, protocol;
  char cmd[512];
  if (!(action = getenv("ACTION")) || !(type = getenv("TYPE")) ||
      !(device = getenv("DEVICE")) || !(devfs = getenv("DEVFS")) ||
      !(interface = getenv("INTERFACE")) || !(product = getenv("PRODUCT"))) {
    return EINVAL;
  }
  sscanf(type, "%d/%d/%d", &class, &subclass, &protocol);
  if (class == 0) {
    sscanf(interface, "%d/%d/%d", &class, &subclass, &protocol);
  }
  if (class == 8 && subclass == 6 && !strcmp(action, "add")) {
    usb_umount();
  } else if (class == 8 && subclass == 6 && !strcmp(action, "remove")) {
    usb_umount();
  }
  system("/usr/bin/setsmbftpconf");
  return 0;
}


x86 assembly (clang, -O0):
<usb_hotplug>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
lea    0xe9e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11f7 <usb_hotplug+0xa7>
lea    0xe8b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11f7 <usb_hotplug+0xa7>
lea    0xe76(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11f7 <usb_hotplug+0xa7>
lea    0xe63(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     11f7 <usb_hotplug+0xa7>
lea    0xe4f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11f7 <usb_hotplug+0xa7>
lea    0xe3f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1208 <usb_hotplug+0xb8>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12cf <usb_hotplug+0x17f>
mov    -0x30(%rbp),%rdi
lea    0xe18(%rip),%rsi
lea    -0x3c(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x44(%rbp),%r8
call   1070 <sscanf@plt>
cmpl   $0x0,-0x3c(%rbp)
jne    124a <usb_hotplug+0xfa>
mov    -0x18(%rbp),%rdi
lea    0xdf2(%rip),%rsi
lea    -0x3c(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x44(%rbp),%r8
call   1070 <sscanf@plt>
cmpl   $0x8,-0x3c(%rbp)
jne    1283 <usb_hotplug+0x133>
cmpl   $0x6,-0x40(%rbp)
jne    1283 <usb_hotplug+0x133>
mov    -0x20(%rbp),%rdi
lea    0xdcb(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1283 <usb_hotplug+0x133>
mov    $0x0,%al
call   1040 <usb_umount@plt>
jmp    12bc <usb_hotplug+0x16c>
cmpl   $0x8,-0x3c(%rbp)
jne    12b7 <usb_hotplug+0x167>
cmpl   $0x6,-0x40(%rbp)
jne    12b7 <usb_hotplug+0x167>
mov    -0x20(%rbp),%rdi
lea    0xd96(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    12b7 <usb_hotplug+0x167>
mov    $0x0,%al
call   1040 <usb_umount@plt>
jmp    12bc <usb_hotplug+0x16c>
lea    0xd7c(%rip),%rdi
call   1050 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<usb_hotplug>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xea0(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1271 <usb_hotplug+0x121>
mov    %rax,%r14
lea    0xe8f(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1271 <usb_hotplug+0x121>
mov    %rax,%rbx
lea    0xe7c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1271 <usb_hotplug+0x121>
lea    0xe6e(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1271 <usb_hotplug+0x121>
lea    0xe5f(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1271 <usb_hotplug+0x121>
mov    %rax,%r15
lea    0xe51(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1271 <usb_hotplug+0x121>
lea    0xe44(%rip),%rsi
lea    0x4(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %rbx,%rdi
call   1070 <sscanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
jne    1228 <usb_hotplug+0xd8>
lea    0xe1e(%rip),%rsi
lea    0x4(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %r15,%rdi
call   1070 <sscanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x8,%eax
jne    1261 <usb_hotplug+0x111>
cmpl   $0x6,0x8(%rsp)
jne    1261 <usb_hotplug+0x111>
lea    0xdf9(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     125a <usb_hotplug+0x10a>
lea    0xdea(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    1261 <usb_hotplug+0x111>
xor    %eax,%eax
call   1040 <usb_umount@plt>
lea    0xdd7(%rip),%rdi
call   1050 <system@plt>
xor    %eax,%eax
jmp    127a <usb_hotplug+0x12a>
mov    0x2d68(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"ACTION\00"
@.str.1 = [5 x i8] c"TYPE\00"
@.str.2 = [7 x i8] c"DEVICE\00"
@.str.3 = [6 x i8] c"DEVFS\00"
@.str.4 = [10 x i8] c"INTERFACE\00"
@.str.5 = [8 x i8] c"PRODUCT\00"
@EINVAL = global i32 0
@.str.6 = [9 x i8] c"%d/%d/%d\00"
@.str.7 = [4 x i8] c"add\00"
@.str.8 = [7 x i8] c"remove\00"
@.str.9 = [23 x i8] c"/usr/bin/setsmbftpconf\00"
define i32 @usb_hotplug() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [512 x i8]
%12 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %29
14: ; preds = %0
%15 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %15, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %29
17: ; preds = %14
%18 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i8* %18, i8** %2
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %29
20: ; preds = %17
%21 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i8* %21, i8** %7
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i8* %24, i8** %3
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
store i8* %27, i8** %5
%28 = icmp ne i8* %27, null
br i1 %28, label %31, label %29
29: ; preds = %26, %23, %20, %17, %14, %0
%30 = load i32, i32* @EINVAL
store i32 %30, i32* %1
br label %66
31: ; preds = %26
%32 = load i8*, i8** %6
%33 = call i32 @sscanf(i8* %32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32* %8, i32* %9, i32* %10)
%34 = load i32, i32* %8
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load i8*, i8** %3
%38 = call i32 @sscanf(i8* %37, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32* %8, i32* %9, i32* %10)
br label %39
39: ; preds = %36, %31
%40 = load i32, i32* %8
%41 = icmp eq i32 %40, 8
br i1 %41, label %42, label %51
42: ; preds = %39
%43 = load i32, i32* %9
%44 = icmp eq i32 %43, 6
br i1 %44, label %45, label %51
45: ; preds = %42
%46 = load i8*, i8** %4
%47 = call i32 @strcmp(i8* %46, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%48 = icmp ne i32 %47, 0
br i1 %48, label %51, label %49
49: ; preds = %45
%50 = call i32 (...) @usb_umount()
br label %64
51: ; preds = %45, %42, %39
%52 = load i32, i32* %8
%53 = icmp eq i32 %52, 8
br i1 %53, label %54, label %63
54: ; preds = %51
%55 = load i32, i32* %9
%56 = icmp eq i32 %55, 6
br i1 %56, label %57, label %63
57: ; preds = %54
%58 = load i8*, i8** %4
%59 = call i32 @strcmp(i8* %58, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%60 = icmp ne i32 %59, 0
br i1 %60, label %63, label %61
61: ; preds = %57
%62 = call i32 (...) @usb_umount()
br label %63
63: ; preds = %61, %57, %54, %51
br label %64
64: ; preds = %63, %49
%65 = call i32 @system(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %1
br label %66
66: ; preds = %64, %29
%67 = load i32, i32* %1
ret i32 %67
}

LLVM IR (-O2):
@.str = [7 x i8] c"ACTION\00"
@.str.1 = [5 x i8] c"TYPE\00"
@.str.2 = [7 x i8] c"DEVICE\00"
@.str.3 = [6 x i8] c"DEVFS\00"
@.str.4 = [10 x i8] c"INTERFACE\00"
@.str.5 = [8 x i8] c"PRODUCT\00"
@EINVAL = global i32 0
@.str.6 = [9 x i8] c"%d/%d/%d\00"
@.str.7 = [4 x i8] c"add\00"
@.str.8 = [7 x i8] c"remove\00"
@.str.9 = [23 x i8] c"/usr/bin/setsmbftpconf\00"
define i32 @usb_hotplug() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %24, label %9
9: ; preds = %0
%10 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %24, label %12
12: ; preds = %9
%13 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %24, label %15
15: ; preds = %12
%16 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %24, label %18
18: ; preds = %15
%19 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %26
24: ; preds = %21, %18, %15, %12, %9, %0
%25 = load i32, i32* @EINVAL
br label %49
26: ; preds = %21
%27 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%28 = load i32, i32* %1
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%32 = load i32, i32* %1
br label %33
33: ; preds = %30, %26
%34 = phi i32 [ %32, %30 ], [ %28, %26 ]
%35 = icmp eq i32 %34, 8
%36 = load i32, i32* %2
%37 = icmp eq i32 %36, 6
%38 = select i1 %35, i1 %37, i1 false
br i1 %38, label %39, label %47
39: ; preds = %33
%40 = call i32 @strcmp(i8* %7, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%41 = icmp eq i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = call i32 @strcmp(i8* %7, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42, %39
%46 = call i32 (...) @usb_umount()
br label %47
47: ; preds = %45, %33, %42
%48 = call i32 @system(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
br label %49
49: ; preds = %47, %24
%50 = phi i32 [ 0, %47 ], [ %25, %24 ]
ret i32 %50
}