#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 statfs {
  int dummy;
};
struct mntent {
  int /*<<< orphan*/ mnt_dir;
  int /*<<< orphan*/ mnt_fsname;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ bzero(struct statfs *, int);
scalar_t__ config_match(char *, char *);
int /*<<< orphan*/ endmntent(int /*<<< orphan*/ *);
struct mntent *getmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ *setmntent(char *, char *);
int /*<<< orphan*/ sleep(int);
int statfs(int /*<<< orphan*/, struct statfs *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int system(char *);
void reload_services(void) {
  int ret;
  int has_usb_storage = 0;
  struct mntent *ent;
  struct statfs stat;
  FILE *fp = setmntent("/proc/mounts", "r");
  while ((ent = getmntent(fp))) {
    if (strncmp(ent->mnt_fsname, "/dev/sd", strlen("/dev/sd")))
      continue;
    bzero(&stat, sizeof(struct statfs));
    if (-1 == statfs(ent->mnt_dir, &stat)) {
      continue;
    }
    has_usb_storage = 1;
    break;
  }
  endmntent(fp);
  if (!has_usb_storage) {
    system("/usr/bin/killall smbd > /dev/null 2>&1");
    system("/usr/bin/killall nmbd > /dev/null 2>&1");
    system("/usr/sbin/taskset -p 3 `/bin/pidof usb-storage` > /dev/null 2>&1");
    system("/sbin/cmdftp stop");
    goto outer;
  }
  if (config_match("usb_enableNet", "1"))
    goto outer;
  sleep(1);
  ret = system("/bin/pidof smbd > /dev/zero 2>&1");
  if (ret == 0) {
    system("/usr/bin/killall -SIGHUP smbd");
    system("/usr/sbin/taskset -p 3 `/bin/pidof usb-storage` > /dev/null 2>&1");
  } else {
    system("/usr/sbin/taskset -c 1 /usr/sbin/smbd -D > /dev/null 2>&1");
    system("/usr/sbin/taskset -p 1 `/bin/pidof usb-storage` > /dev/null 2>&1");
    system("/bin/sleep 5");
    system("/bin/chmod 0666 /tmp/samba/smbpasswd");
    system("/usr/sbin/update_user > /dev/null 2>&1");
  }
  system("/usr/bin/killall nmbd > /dev/null 2>&1");
  system("/usr/sbin/nmbd -D");
outer:
  return;
}


x86 assembly (clang, -O0):
<reload_services>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x8(%rbp)
lea    0xe4a(%rip),%rdi
lea    0xe50(%rip),%rsi
call   1090 <setmntent@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <getmntent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     124b <reload_services+0xab>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x24(%rbp)
lea    0xe21(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%edx
lea    0xe10(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1213 <reload_services+0x73>
jmp    11c6 <reload_services+0x26>
lea    -0x18(%rbp),%rdi
mov    $0x4,%esi
call   10a0 <bzero@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1070 <statfs@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1244 <reload_services+0xa4>
jmp    11c6 <reload_services+0x26>
movl   $0x1,-0x8(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <endmntent@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1293 <reload_services+0xf3>
lea    0xdb2(%rip),%rdi
call   1060 <system@plt>
lea    0xdcd(%rip),%rdi
call   1060 <system@plt>
lea    0xde8(%rip),%rdi
call   1060 <system@plt>
lea    0xe1d(%rip),%rdi
call   1060 <system@plt>
jmp    1349 <reload_services+0x1a9>
lea    0xe1e(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   10b0 <config_match@plt>
cmp    $0x0,%rax
je     12b5 <reload_services+0x115>
jmp    1349 <reload_services+0x1a9>
mov    $0x1,%edi
call   10c0 <sleep@plt>
lea    0xe00(%rip),%rdi
call   1060 <system@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    12f5 <reload_services+0x155>
lea    0xe08(%rip),%rdi
call   1060 <system@plt>
lea    0xd7a(%rip),%rdi
call   1060 <system@plt>
jmp    1331 <reload_services+0x191>
lea    0xe09(%rip),%rdi
call   1060 <system@plt>
lea    0xe37(%rip),%rdi
call   1060 <system@plt>
lea    0xe6c(%rip),%rdi
call   1060 <system@plt>
lea    0xe6d(%rip),%rdi
call   1060 <system@plt>
lea    0xe86(%rip),%rdi
call   1060 <system@plt>
lea    0xd06(%rip),%rdi
call   1060 <system@plt>
lea    0xe95(%rip),%rdi
call   1060 <system@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reload_services>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe4d(%rip),%rdi
lea    0xe53(%rip),%rsi
call   1090 <setmntent@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1080 <getmntent@plt>
test   %rax,%rax
je     12c0 <reload_services+0x120>
mov    %rax,%rbx
lea    0xe32(%rip),%r12
lea    0x8(%rsp),%r15
jmp    1204 <reload_services+0x64>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1080 <getmntent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12c0 <reload_services+0x120>
mov    0x4(%rbx),%ebp
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    11f0 <reload_services+0x50>
mov    %r15,%rdi
mov    $0x4,%esi
call   10a0 <bzero@plt>
mov    (%rbx),%edi
mov    %r15,%rsi
call   1070 <statfs@plt>
cmp    $0xffffffff,%eax
je     11f0 <reload_services+0x50>
mov    %r14,%rdi
call   1030 <endmntent@plt>
lea    0xe6d(%rip),%rdi
lea    0xeeb(%rip),%rsi
call   10b0 <config_match@plt>
test   %rax,%rax
jne    1301 <reload_services+0x161>
mov    $0x1,%edi
call   10c0 <sleep@plt>
lea    0xe55(%rip),%rdi
call   1060 <system@plt>
lea    0xf5c(%rip),%r14
lea    0xdba(%rip),%r15
test   %eax,%eax
je     130e <reload_services+0x16e>
lea    0xe72(%rip),%rdi
call   1060 <system@plt>
lea    0xea0(%rip),%rdi
call   1060 <system@plt>
lea    0xed5(%rip),%rdi
call   1060 <system@plt>
lea    0xefb(%rip),%rbx
lea    0xecf(%rip),%rdi
jmp    12e4 <reload_services+0x144>
mov    %r14,%rdi
call   1030 <endmntent@plt>
lea    0xdd7(%rip),%r14
lea    0xd8f(%rip),%r15
lea    0xd61(%rip),%rbx
lea    0xd33(%rip),%rdi
call   1060 <system@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
mov    %r15,%rdi
call   1060 <system@plt>
mov    %r14,%rdi
call   1060 <system@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd50(%rip),%rbx
lea    0xdcb(%rip),%rdi
jmp    12e4 <reload_services+0x144>

LLVM IR (-O0):
%struct.mntent = type { i32, i32 }
%struct.statfs = type { i32 }
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"/dev/sd\00"
@.str.3 = [39 x i8] c"/usr/bin/killall smbd > /dev/null 2>&1\00"
@.str.4 = [39 x i8] c"/usr/bin/killall nmbd > /dev/null 2>&1\00"
@.str.5 = [65 x i8] c"/usr/sbin/taskset -p 3 `/bin/pidof usb-storage` > /dev/null 2>&1\00"
@.str.6 = [18 x i8] c"/sbin/cmdftp stop\00"
@.str.7 = [14 x i8] c"usb_enableNet\00"
@.str.8 = [2 x i8] c"1\00"
@.str.9 = [33 x i8] c"/bin/pidof smbd > /dev/zero 2>&1\00"
@.str.10 = [30 x i8] c"/usr/bin/killall -SIGHUP smbd\00"
@.str.11 = [58 x i8] c"/usr/sbin/taskset -c 1 /usr/sbin/smbd -D > /dev/null 2>&1\00"
@.str.12 = [65 x i8] c"/usr/sbin/taskset -p 1 `/bin/pidof usb-storage` > /dev/null 2>&1\00"
@.str.13 = [13 x i8] c"/bin/sleep 5\00"
@.str.14 = [37 x i8] c"/bin/chmod 0666 /tmp/samba/smbpasswd\00"
@.str.15 = [39 x i8] c"/usr/sbin/update_user > /dev/null 2>&1\00"
@.str.16 = [18 x i8] c"/usr/sbin/nmbd -D\00"
define void @reload_services() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.mntent*
%4 = alloca %struct.statfs
%5 = alloca i32*
store i32 0, i32* %2
%6 = call i32* @setmntent(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
br label %7
7: ; preds = %26, %18, %0
%8 = load i32*, i32** %5
%9 = call %struct.mntent* @getmntent(i32* %8)
store %struct.mntent* %9, %struct.mntent** %3
%10 = icmp ne %struct.mntent* %9, null
br i1 %10, label %11, label %28
11: ; preds = %7
%12 = load %struct.mntent*, %struct.mntent** %3
%13 = getelementptr inbounds %struct.mntent, %struct.mntent* %12, i32 0, i32 1
%14 = load i32, i32* %13
%15 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%16 = call i64 @strncmp(i32 %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %11
br label %7
19: ; preds = %11
%20 = call i32 @bzero(%struct.statfs* %4, i32 4)
%21 = load %struct.mntent*, %struct.mntent** %3
%22 = getelementptr inbounds %struct.mntent, %struct.mntent* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @statfs(i32 %23, %struct.statfs* %4)
%25 = icmp eq i32 -1, %24
br i1 %25, label %26, label %27
26: ; preds = %19
br label %7
27: ; preds = %19
store i32 1, i32* %2
br label %28
28: ; preds = %27, %7
%29 = load i32*, i32** %5
%30 = call i32 @endmntent(i32* %29)
%31 = load i32, i32* %2
%32 = icmp ne i32 %31, 0
br i1 %32, label %38, label %33
33: ; preds = %28
%34 = call i32 @system(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @system(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 @system(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.5, i64 0, i64 0))
%37 = call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %59
38: ; preds = %28
%39 = call i64 @config_match(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %38
br label %59
42: ; preds = %38
%43 = call i32 @sleep(i32 1)
%44 = call i32 @system(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0))
store i32 %44, i32* %1
%45 = load i32, i32* %1
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = call i32 @system(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0))
%49 = call i32 @system(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.5, i64 0, i64 0))
br label %56
50: ; preds = %42
%51 = call i32 @system(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.11, i64 0, i64 0))
%52 = call i32 @system(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.12, i64 0, i64 0))
%53 = call i32 @system(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i64 0, i64 0))
%54 = call i32 @system(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.14, i64 0, i64 0))
%55 = call i32 @system(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.15, i64 0, i64 0))
br label %56
56: ; preds = %50, %47
%57 = call i32 @system(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%58 = call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.16, i64 0, i64 0))
br label %59
59: ; preds = %56, %41, %33
ret void
}

LLVM IR (-O2):
%struct.statfs = type { i32 }
%struct.mntent = type { i32, i32 }
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"/dev/sd\00"
@.str.3 = [39 x i8] c"/usr/bin/killall smbd > /dev/null 2>&1\00"
@.str.4 = [39 x i8] c"/usr/bin/killall nmbd > /dev/null 2>&1\00"
@.str.5 = [65 x i8] c"/usr/sbin/taskset -p 3 `/bin/pidof usb-storage` > /dev/null 2>&1\00"
@.str.6 = [18 x i8] c"/sbin/cmdftp stop\00"
@.str.7 = [14 x i8] c"usb_enableNet\00"
@.str.8 = [2 x i8] c"1\00"
@.str.9 = [33 x i8] c"/bin/pidof smbd > /dev/zero 2>&1\00"
@.str.10 = [30 x i8] c"/usr/bin/killall -SIGHUP smbd\00"
@.str.11 = [58 x i8] c"/usr/sbin/taskset -c 1 /usr/sbin/smbd -D > /dev/null 2>&1\00"
@.str.12 = [65 x i8] c"/usr/sbin/taskset -p 1 `/bin/pidof usb-storage` > /dev/null 2>&1\00"
@.str.13 = [13 x i8] c"/bin/sleep 5\00"
@.str.14 = [37 x i8] c"/bin/chmod 0666 /tmp/samba/smbpasswd\00"
@.str.15 = [39 x i8] c"/usr/sbin/update_user > /dev/null 2>&1\00"
@.str.16 = [18 x i8] c"/usr/sbin/nmbd -D\00"
define void @reload_services() {
%1 = alloca %struct.statfs
%2 = bitcast %struct.statfs* %1 to i8*
%3 = tail call i32* @setmntent(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = call %struct.mntent* @getmntent(i32* %3)
%5 = icmp eq %struct.mntent* %4, null
br i1 %5, label %22, label %6
6: ; preds = %0, %13
%7 = phi %struct.mntent* [ %14, %13 ], [ %4, %0 ]
%8 = getelementptr inbounds %struct.mntent, %struct.mntent* %7, i64 0, i32 1
%9 = load i32, i32* %8
%10 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%11 = call i64 @strncmp(i32 %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %6, %16
%14 = call %struct.mntent* @getmntent(i32* %3)
%15 = icmp eq %struct.mntent* %14, null
br i1 %15, label %22, label %6
16: ; preds = %6
%17 = call i32 @bzero(%struct.statfs* %1, i32 4)
%18 = getelementptr inbounds %struct.mntent, %struct.mntent* %7, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @statfs(i32 %19, %struct.statfs* %1)
%21 = icmp eq i32 %20, -1
br i1 %21, label %13, label %24
22: ; preds = %13, %0
%23 = call i32 @endmntent(i32* %3)
br label %36
24: ; preds = %16
%25 = call i32 @endmntent(i32* %3)
%26 = call i64 @config_match(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %45
28: ; preds = %24
%29 = call i32 @sleep(i32 1)
%30 = call i32 @system(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0))
%31 = icmp eq i32 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = call i32 @system(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.11, i64 0, i64 0))
%34 = call i32 @system(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.12, i64 0, i64 0))
%35 = call i32 @system(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i64 0, i64 0))
br label %36
36: ; preds = %32, %28, %22
%37 = phi i8* [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), %22 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.14, i64 0, i64 0), %32 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0), %28 ]
%38 = phi i8* [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), %22 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.15, i64 0, i64 0), %32 ], [ getelementptr inbounds ([65 x i8], [65 x i8]* @.str.5, i64 0, i64 0), %28 ]
%39 = phi i8* [ getelementptr inbounds ([65 x i8], [65 x i8]* @.str.5, i64 0, i64 0), %22 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), %32 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), %28 ]
%40 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), %22 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.16, i64 0, i64 0), %32 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.16, i64 0, i64 0), %28 ]
%41 = call i32 @system(i8* %37)
%42 = call i32 @system(i8* %38)
%43 = call i32 @system(i8* %39)
%44 = call i32 @system(i8* %40)
br label %45
45: ; preds = %36, %24
ret void
}