#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*/ sLineBuf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ osProcId();
int /*<<< orphan*/ osSystem(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
char *strstr(char *, char *);
int /*<<< orphan*/ unlink(char *);
long drvUsbAdmin(int bEnable) {
  char sCmd[128];
  char sTmpFn[32];
  FILE *pFile;
  char sLineBuf[128];
  char *pPtr;
  int iGpio;
  int iCnt;
  if (osSystem("/usr/sbin/diskmount.sh unmount-all") != (0))
    return (-1);
  sprintf(sTmpFn, "/tmp/%ld.tmp", osProcId());
  sprintf(sCmd, "cp /proc/driver/ifx_gpio/module > %s", sTmpFn);
  if (osSystem(sCmd) != (0))
    return (-1);
  if ((pFile = fopen(sTmpFn, "r")) == (0))
    return (-1);
  iCnt = 0;
  while (fgets(sLineBuf, sizeof(sLineBuf), pFile) != (0)) {
    iCnt++;
    if (!((iCnt >= 5 && iCnt <= 8) || (iCnt >= 14 && iCnt <= 17)))
      continue;
    pPtr = sLineBuf;
    while ((pPtr = strstr(pPtr + 1, "USB")) != (0)) {
      if (iCnt >= 5 && iCnt <= 8)
        iGpio = (iCnt - 5) * 16;
      else
        iGpio = (iCnt - 11) * 16 + 8;
      iGpio += (((int)(pPtr - sLineBuf) - 4) / 10);
      sprintf(sCmd, "echo dataout-%s %d > /proc/driver/ifx_gpio/setup",
              (bEnable == (0) ? "clear" : "set"), iGpio);
      if (osSystem(sCmd) != (0)) {
        fclose(pFile);
        unlink(sTmpFn);
        return (-1);
      }
    }
  }
  fclose(pFile);
  unlink(sTmpFn);
  return (0);
}


x86 assembly (clang, -O0):
<drvUsbAdmin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %edi,-0xc(%rbp)
lea    0xe6b(%rip),%rdi
call   1070 <osSystem@plt>
cmp    $0x0,%eax
je     11b0 <drvUsbAdmin+0x30>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    13fa <drvUsbAdmin+0x27a>
lea    -0xb0(%rbp),%rax
mov    %rax,-0x158(%rbp)
mov    $0x0,%al
call   1060 <osProcId@plt>
mov    -0x158(%rbp),%rdi
movslq %eax,%rdx
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x90(%rbp),%rdi
lea    -0xb0(%rbp),%rdx
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x90(%rbp),%rdi
call   1070 <osSystem@plt>
cmp    $0x0,%eax
je     121b <drvUsbAdmin+0x9b>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    13fa <drvUsbAdmin+0x27a>
lea    -0xb0(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0xb8(%rbp)
cmp    $0x0,%rax
jne    124c <drvUsbAdmin+0xcc>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    13fa <drvUsbAdmin+0x27a>
movl   $0x0,-0x150(%rbp)
lea    -0x140(%rbp),%rdi
mov    -0xb8(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%eax
je     13da <drvUsbAdmin+0x25a>
mov    -0x150(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x150(%rbp)
cmpl   $0x5,-0x150(%rbp)
jl     12a0 <drvUsbAdmin+0x120>
cmpl   $0x8,-0x150(%rbp)
jle    12bf <drvUsbAdmin+0x13f>
cmpl   $0xe,-0x150(%rbp)
jl     12ba <drvUsbAdmin+0x13a>
cmpl   $0x11,-0x150(%rbp)
jle    12bf <drvUsbAdmin+0x13f>
jmp    1256 <drvUsbAdmin+0xd6>
lea    -0x140(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x148(%rbp),%rdi
add    $0x1,%rdi
lea    0xd76(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x148(%rbp)
cmp    $0x0,%rax
je     13d5 <drvUsbAdmin+0x255>
cmpl   $0x5,-0x150(%rbp)
jl     1326 <drvUsbAdmin+0x1a6>
cmpl   $0x8,-0x150(%rbp)
jg     1326 <drvUsbAdmin+0x1a6>
mov    -0x150(%rbp),%eax
sub    $0x5,%eax
shl    $0x4,%eax
mov    %eax,-0x14c(%rbp)
jmp    133b <drvUsbAdmin+0x1bb>
mov    -0x150(%rbp),%eax
sub    $0xb,%eax
shl    $0x4,%eax
add    $0x8,%eax
mov    %eax,-0x14c(%rbp)
mov    -0x148(%rbp),%rax
lea    -0x140(%rbp),%rcx
sub    %rcx,%rax
sub    $0x4,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    -0x14c(%rbp),%eax
mov    %eax,-0x14c(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0xc(%rbp),%ecx
lea    0xd1c(%rip),%rdx
lea    0xd0f(%rip),%rax
cmp    $0x0,%ecx
cmove  %rax,%rdx
mov    -0x14c(%rbp),%ecx
lea    0xcca(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x90(%rbp),%rdi
call   1070 <osSystem@plt>
cmp    $0x0,%eax
je     13d0 <drvUsbAdmin+0x250>
mov    -0xb8(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0xb0(%rbp),%rdi
call   1030 <unlink@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    13fa <drvUsbAdmin+0x27a>
jmp    12cd <drvUsbAdmin+0x14d>
jmp    1256 <drvUsbAdmin+0xd6>
mov    -0xb8(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0xb0(%rbp),%rdi
call   1030 <unlink@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drvUsbAdmin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %edi,%r14d
lea    0xe65(%rip),%rdi
call   1070 <osSystem@plt>
mov    $0xffffffffffffffff,%rbx
test   %eax,%eax
jne    1325 <drvUsbAdmin+0x1a5>
xor    %eax,%eax
call   1060 <osProcId@plt>
movslq %eax,%rdx
lea    0xe63(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1090 <sprintf@plt>
lea    0xe5c(%rip),%rsi
lea    0xa0(%rsp),%rbp
mov    %rbp,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %rbp,%rdi
call   1070 <osSystem@plt>
test   %eax,%eax
jne    1325 <drvUsbAdmin+0x1a5>
lea    0xe8e(%rip),%rsi
mov    %rsp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1325 <drvUsbAdmin+0x1a5>
mov    %rax,%rbp
lea    0x20(%rsp),%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     1315 <drvUsbAdmin+0x195>
test   %r14d,%r14d
lea    0xe50(%rip),%rax
lea    0xe4f(%rip),%rbx
cmove  %rax,%rbx
lea    0xa0(%rsp),%r14
xor    %r12d,%r12d
jmp    1270 <drvUsbAdmin+0xf0>
add    $0x1,%r12d
lea    0x20(%rsp),%rdi
mov    $0x80,%esi
mov    %rbp,%rdx
call   1050 <fgets@plt>
test   %eax,%eax
je     133a <drvUsbAdmin+0x1ba>
mov    %r12d,%eax
and    $0x7ffffffc,%eax
cmp    $0x4,%eax
je     1287 <drvUsbAdmin+0x107>
lea    -0xd(%r12),%ecx
cmp    $0x4,%ecx
jae    1252 <drvUsbAdmin+0xd2>
mov    %r12d,%r13d
shl    $0x4,%r13d
lea    -0x98(%r13),%ecx
add    $0xffffffc0,%r13d
cmp    $0x4,%eax
cmovne %ecx,%r13d
lea    0x20(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r15
mov    %r15,%rdi
lea    0xd97(%rip),%rsi
call   10a0 <strstr@plt>
test   %rax,%rax
je     1252 <drvUsbAdmin+0xd2>
mov    %rax,%r15
lea    0x20(%rsp),%rcx
sub    %ecx,%eax
add    $0xfffffffc,%eax
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
sar    $0x22,%rcx
add    %eax,%ecx
add    %r13d,%ecx
mov    %r14,%rdi
lea    0xd61(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %r14,%rdi
call   1070 <osSystem@plt>
test   %eax,%eax
je     12b0 <drvUsbAdmin+0x130>
mov    $0xffffffffffffffff,%rbx
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %rsp,%rdi
call   1030 <unlink@plt>
mov    %rbx,%rax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
jmp    1315 <drvUsbAdmin+0x195>

LLVM IR (-O0):
@.str = [35 x i8] c"/usr/sbin/diskmount.sh unmount-all\00"
@.str.1 = [13 x i8] c"/tmp/%ld.tmp\00"
@.str.2 = [37 x i8] c"cp /proc/driver/ifx_gpio/module > %s\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [4 x i8] c"USB\00"
@.str.5 = [49 x i8] c"echo dataout-%s %d > /proc/driver/ifx_gpio/setup\00"
@.str.6 = [6 x i8] c"clear\00"
@.str.7 = [4 x i8] c"set\00"
define i64 @drvUsbAdmin(i32 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca [128 x i8]
%5 = alloca [32 x i8]
%6 = alloca i32*
%7 = alloca [128 x i8]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %3
%11 = call i32 @osSystem(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %1
store i64 -1, i64* %2
br label %108
14: ; preds = %1
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%16 = call i32 (...) @osProcId()
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i8*
%19 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%22 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%24 = call i32 @osSystem(i8* %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %14
store i64 -1, i64* %2
br label %108
27: ; preds = %14
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %29, i32** %6
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %32
31: ; preds = %27
store i64 -1, i64* %2
br label %108
32: ; preds = %27
store i32 0, i32* %10
br label %33
33: ; preds = %102, %52, %32
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%35 = load i32*, i32** %6
%36 = call i32 @fgets(i8* %34, i32 128, i32* %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %103
38: ; preds = %33
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 1
store i32 %40, i32* %10
%41 = load i32, i32* %10
%42 = icmp sge i32 %41, 5
br i1 %42, label %43, label %46
43: ; preds = %38
%44 = load i32, i32* %10
%45 = icmp sle i32 %44, 8
br i1 %45, label %53, label %46
46: ; preds = %43, %38
%47 = load i32, i32* %10
%48 = icmp sge i32 %47, 14
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i32, i32* %10
%51 = icmp sle i32 %50, 17
br i1 %51, label %53, label %52
52: ; preds = %49, %46
br label %33
53: ; preds = %49, %43
%54 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
store i8* %54, i8** %8
br label %55
55: ; preds = %101, %53
%56 = load i8*, i8** %8
%57 = getelementptr inbounds i8, i8* %56, i64 1
%58 = call i8* @strstr(i8* %57, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
store i8* %58, i8** %8
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %102
60: ; preds = %55
%61 = load i32, i32* %10
%62 = icmp sge i32 %61, 5
br i1 %62, label %63, label %70
63: ; preds = %60
%64 = load i32, i32* %10
%65 = icmp sle i32 %64, 8
br i1 %65, label %66, label %70
66: ; preds = %63
%67 = load i32, i32* %10
%68 = sub nsw i32 %67, 5
%69 = mul nsw i32 %68, 16
store i32 %69, i32* %9
br label %75
70: ; preds = %63, %60
%71 = load i32, i32* %10
%72 = sub nsw i32 %71, 11
%73 = mul nsw i32 %72, 16
%74 = add nsw i32 %73, 8
store i32 %74, i32* %9
br label %75
75: ; preds = %70, %66
%76 = load i8*, i8** %8
%77 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%78 = ptrtoint i8* %76 to i64
%79 = ptrtoint i8* %77 to i64
%80 = sub i64 %78, %79
%81 = trunc i64 %80 to i32
%82 = sub nsw i32 %81, 4
%83 = sdiv i32 %82, 10
%84 = load i32, i32* %9
%85 = add nsw i32 %84, %83
store i32 %85, i32* %9
%86 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%87 = load i32, i32* %3
%88 = icmp eq i32 %87, 0
%89 = zext i1 %88 to i64
%90 = select i1 %88, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0)
%91 = load i32, i32* %9
%92 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %86, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i8* %90, i32 %91)
%93 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%94 = call i32 @osSystem(i8* %93)
%95 = icmp ne i32 %94, 0
br i1 %95, label %96, label %101
96: ; preds = %75
%97 = load i32*, i32** %6
%98 = call i32 @fclose(i32* %97)
%99 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%100 = call i32 @unlink(i8* %99)
store i64 -1, i64* %2
br label %108
101: ; preds = %75
br label %55
102: ; preds = %55
br label %33
103: ; preds = %33
%104 = load i32*, i32** %6
%105 = call i32 @fclose(i32* %104)
%106 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%107 = call i32 @unlink(i8* %106)
store i64 0, i64* %2
br label %108
108: ; preds = %103, %96, %31, %26, %13
%109 = load i64, i64* %2
ret i64 %109
}

LLVM IR (-O2):
@.str = [35 x i8] c"/usr/sbin/diskmount.sh unmount-all\00"
@.str.1 = [13 x i8] c"/tmp/%ld.tmp\00"
@.str.2 = [37 x i8] c"cp /proc/driver/ifx_gpio/module > %s\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [4 x i8] c"USB\00"
@.str.5 = [49 x i8] c"echo dataout-%s %d > /proc/driver/ifx_gpio/setup\00"
@.str.6 = [6 x i8] c"clear\00"
@.str.7 = [4 x i8] c"set\00"
define i64 @drvUsbAdmin(i32 %0) {
%2 = alloca [128 x i8]
%3 = alloca [32 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = tail call i32 @osSystem(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %62
10: ; preds = %1
%11 = tail call i32 (...) @osProcId()
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i8*
%14 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%16 = call i32 @osSystem(i8* %5)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %62
18: ; preds = %10
%19 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %62, label %21
21: ; preds = %18
%22 = call i32 @fgets(i8* %7, i32 128, i32* %19)
%23 = icmp eq i32 %22, 0
br i1 %23, label %58, label %24
24: ; preds = %21
%25 = ptrtoint [128 x i8]* %4 to i64
%26 = icmp eq i32 %0, 0
%27 = select i1 %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0)
br label %28
28: ; preds = %24, %36
%29 = phi i32 [ 0, %24 ], [ %30, %36 ]
%30 = add nuw nsw i32 %29, 1
%31 = and i32 %29, 2147483644
%32 = icmp eq i32 %31, 4
%33 = add nsw i32 %29, -13
%34 = icmp ult i32 %33, 4
%35 = or i1 %32, %34
br i1 %35, label %39, label %36
36: ; preds = %43, %28
%37 = call i32 @fgets(i8* %7, i32 128, i32* %19)
%38 = icmp eq i32 %37, 0
br i1 %38, label %58, label %28
39: ; preds = %28
%40 = shl i32 %29, 4
%41 = select i1 %32, i32 -64, i32 -152
%42 = add i32 %41, %40
br label %43
43: ; preds = %39, %48
%44 = phi i8* [ %46, %48 ], [ %7, %39 ]
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = call i8* @strstr(i8* %45, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%47 = icmp eq i8* %46, null
br i1 %47, label %36, label %48
48: ; preds = %43
%49 = ptrtoint i8* %46 to i64
%50 = sub i64 %49, %25
%51 = trunc i64 %50 to i32
%52 = add nsw i32 %51, -4
%53 = sdiv i32 %52, 10
%54 = add nsw i32 %42, %53
%55 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i8* %27, i32 %54)
%56 = call i32 @osSystem(i8* %5)
%57 = icmp eq i32 %56, 0
br i1 %57, label %43, label %58
58: ; preds = %36, %48, %21
%59 = phi i64 [ 0, %21 ], [ -1, %48 ], [ 0, %36 ]
%60 = call i32 @fclose(i32* %19)
%61 = call i32 @unlink(i8* %6)
br label %62
62: ; preds = %58, %18, %10, %1
%63 = phi i64 [ -1, %1 ], [ -1, %10 ], [ -1, %18 ], [ %59, %58 ]
ret i64 %63
}