#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*/ cmd;

/* Variables and functions */
int emc_check_fence(char const *, char const *, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *,
                            char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int system(char *);
int emc_fencer(const char *sp_name, const char *sg_name, const char *host,
               int unfence) {
  char cmd[1000];
  int host_connections = 0;
  int status;
  if (unfence == 0) {
    snprintf(cmd, sizeof(cmd),
             "echo y | /opt/Navisphere/bin/naviseccli -h %s storagegroup "
             "-disconnecthost -host %s -gname %s",
             sp_name, host, sg_name);
    fprintf(stdout, "I/O Fencing command [%s]\n", cmd);
    status = system(cmd);
    if (status != 0) {
      fprintf(stderr, "Failed disconnect on storage processor, proceeding.\n");
    }
    host_connections = emc_check_fence(sp_name, sg_name, host);
    if (host_connections != 0) {
      fprintf(stderr, "I/O fenced, but %s is still connected to %s\n", host,
              sg_name);
    }
    return 0;
  }
  host_connections = emc_check_fence(sp_name, sg_name, host);
  if (host_connections > 0) {
    fprintf(stdout,
            "I/O Unfencing unnecessary, %s is already connected to "
            "storage-group %s\n",
            host, sg_name);
    return 0;
  }
  snprintf(cmd, sizeof(cmd),
           "echo y | /opt/Navisphere/bin/naviseccli -h %s storagegroup "
           "-connecthost -host %s -gname %s",
           sp_name, host, sg_name);
  fprintf(stdout, "I/O Unfencing command [%s]\n", cmd);
  status = system(cmd);
  if (status != 0) {
    fprintf(stderr, "Failed disconnect on storage processor, proceeding.\n");
  }
  host_connections = emc_check_fence(sp_name, sg_name, host);
  if (host_connections > 0) {
    fprintf(stdout,
            "I/O Unfencing complete, %s is connected to storage-group %s\n",
            host, sg_name);
  }
  return 0;
}


x86 assembly (clang, -O0):
<emc_fencer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x414(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1235 <emc_fencer+0xf5>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    $0x3e8,%esi
lea    0xe73(%rip),%rdx
call   1040 <snprintf@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xeb5(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    -0x410(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0x418(%rbp)
cmpl   $0x0,-0x418(%rbp)
je     11e6 <emc_fencer+0xa6>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <emc_check_fence@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
je     1229 <emc_fencer+0xe9>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe8b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1346 <emc_fencer+0x206>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <emc_check_fence@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jle    1284 <emc_fencer+0x144>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1346 <emc_fencer+0x206>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    $0x3e8,%esi
lea    0xe7f(%rip),%rdx
call   1040 <snprintf@plt>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xebe(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    -0x410(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0x418(%rbp)
cmpl   $0x0,-0x418(%rbp)
je     12fc <emc_fencer+0x1bc>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
lea    0xd83(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <emc_check_fence@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jle    133f <emc_fencer+0x1ff>
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emc_fencer>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f0,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
test   %ecx,%ecx
je     1188 <emc_fencer+0x48>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <emc_check_fence@plt>
test   %eax,%eax
jle    120d <emc_fencer+0xcd>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xf57(%rip),%rsi
jmp    1289 <emc_fencer+0x149>
lea    0xe71(%rip),%rdx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x3e8,%esi
mov    %rbx,%rcx
mov    %r15,%r8
mov    %r14,%r9
call   1040 <snprintf@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xea6(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r12,%rdi
call   1030 <system@plt>
test   %eax,%eax
je     11e5 <emc_fencer+0xa5>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe9a(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <emc_check_fence@plt>
test   %eax,%eax
je     1296 <emc_fencer+0x156>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xea2(%rip),%rsi
jmp    1289 <emc_fencer+0x149>
lea    0xf0e(%rip),%rdx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x3e8,%esi
mov    %rbx,%rcx
mov    %r15,%r8
mov    %r14,%r9
call   1040 <snprintf@plt>
mov    0x2da4(%rip),%r13
mov    0x0(%r13),%edi
lea    0xf3e(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r12,%rdi
call   1030 <system@plt>
test   %eax,%eax
je     126c <emc_fencer+0x12c>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <emc_check_fence@plt>
test   %eax,%eax
jle    1296 <emc_fencer+0x156>
mov    0x0(%r13),%edi
lea    0xf10(%rip),%rsi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [94 x i8] c"echo y | /opt/Navisphere/bin/naviseccli -h %s storagegroup -disconnecthost -host %s -gname %s\00"
@stdout = global i32 0
@.str.1 = [26 x i8] c"I/O Fencing command [%s]\0A\00"
@stderr = global i32 0
@.str.2 = [53 x i8] c"Failed disconnect on storage processor, proceeding.\0A\00"
@.str.3 = [45 x i8] c"I/O fenced, but %s is still connected to %s\0A\00"
@.str.4 = [72 x i8] c"I/O Unfencing unnecessary, %s is already connected to storage-group %s\0A\00"
@.str.5 = [91 x i8] c"echo y | /opt/Navisphere/bin/naviseccli -h %s storagegroup -connecthost -host %s -gname %s\00"
@.str.6 = [28 x i8] c"I/O Unfencing command [%s]\0A\00"
@.str.7 = [61 x i8] c"I/O Unfencing complete, %s is connected to storage-group %s\0A\00"
define i32 @emc_fencer(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [1000 x i8]
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 0, i32* %11
%13 = load i32, i32* %9
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %44
15: ; preds = %4
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%17 = load i8*, i8** %6
%18 = load i8*, i8** %8
%19 = load i8*, i8** %7
%20 = call i32 @snprintf(i8* %16, i32 1000, i8* getelementptr inbounds ([94 x i8], [94 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %18, i8* %19)
%21 = load i32, i32* @stdout
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%25 = call i32 @system(i8* %24)
store i32 %25, i32* %12
%26 = load i32, i32* %12
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %15
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %28, %15
%32 = load i8*, i8** %6
%33 = load i8*, i8** %7
%34 = load i8*, i8** %8
%35 = call i32 @emc_check_fence(i8* %32, i8* %33, i8* %34)
store i32 %35, i32* %11
%36 = load i32, i32* %11
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = load i8*, i8** %8
%41 = load i8*, i8** %7
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %40, i8* %41)
br label %43
43: ; preds = %38, %31
store i32 0, i32* %5
br label %85
44: ; preds = %4
%45 = load i8*, i8** %6
%46 = load i8*, i8** %7
%47 = load i8*, i8** %8
%48 = call i32 @emc_check_fence(i8* %45, i8* %46, i8* %47)
store i32 %48, i32* %11
%49 = load i32, i32* %11
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %44
%52 = load i32, i32* @stdout
%53 = load i8*, i8** %8
%54 = load i8*, i8** %7
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.4, i64 0, i64 0), i8* %53, i8* %54)
store i32 0, i32* %5
br label %85
56: ; preds = %44
%57 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%58 = load i8*, i8** %6
%59 = load i8*, i8** %8
%60 = load i8*, i8** %7
%61 = call i32 @snprintf(i8* %57, i32 1000, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.5, i64 0, i64 0), i8* %58, i8* %59, i8* %60)
%62 = load i32, i32* @stdout
%63 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %63)
%65 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%66 = call i32 @system(i8* %65)
store i32 %66, i32* %12
%67 = load i32, i32* %12
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %56
%70 = load i32, i32* @stderr
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
br label %72
72: ; preds = %69, %56
%73 = load i8*, i8** %6
%74 = load i8*, i8** %7
%75 = load i8*, i8** %8
%76 = call i32 @emc_check_fence(i8* %73, i8* %74, i8* %75)
store i32 %76, i32* %11
%77 = load i32, i32* %11
%78 = icmp sgt i32 %77, 0
br i1 %78, label %79, label %84
79: ; preds = %72
%80 = load i32, i32* @stdout
%81 = load i8*, i8** %8
%82 = load i8*, i8** %7
%83 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.7, i64 0, i64 0), i8* %81, i8* %82)
br label %84
84: ; preds = %79, %72
store i32 0, i32* %5
br label %85
85: ; preds = %84, %51, %43
%86 = load i32, i32* %5
ret i32 %86
}

LLVM IR (-O2):
@.str = [94 x i8] c"echo y | /opt/Navisphere/bin/naviseccli -h %s storagegroup -disconnecthost -host %s -gname %s\00"
@stdout = global i32 0
@.str.1 = [26 x i8] c"I/O Fencing command [%s]\0A\00"
@stderr = global i32 0
@.str.2 = [53 x i8] c"Failed disconnect on storage processor, proceeding.\0A\00"
@.str.3 = [45 x i8] c"I/O fenced, but %s is still connected to %s\0A\00"
@.str.4 = [72 x i8] c"I/O Unfencing unnecessary, %s is already connected to storage-group %s\0A\00"
@.str.5 = [91 x i8] c"echo y | /opt/Navisphere/bin/naviseccli -h %s storagegroup -connecthost -host %s -gname %s\00"
@.str.6 = [28 x i8] c"I/O Unfencing command [%s]\0A\00"
@.str.7 = [61 x i8] c"I/O Unfencing complete, %s is connected to storage-group %s\0A\00"
define i32 @emc_fencer(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [1000 x i8]
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%7 = icmp eq i32 %3, 0
br i1 %7, label %8, label %23
8: ; preds = %4
%9 = call i32 @snprintf(i8* %6, i32 1000, i8* getelementptr inbounds ([94 x i8], [94 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %2, i8* %1)
%10 = load i32, i32* @stdout
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%12 = call i32 @system(i8* %6)
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %14, %8
%18 = call i32 @emc_check_fence(i8* %0, i8* %1, i8* %2)
%19 = icmp eq i32 %18, 0
br i1 %19, label %44, label %20
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %2, i8* %1)
br label %44
23: ; preds = %4
%24 = tail call i32 @emc_check_fence(i8* %0, i8* %1, i8* %2)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* @stdout
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.4, i64 0, i64 0), i8* %2, i8* %1)
br label %44
29: ; preds = %23
%30 = call i32 @snprintf(i8* %6, i32 1000, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %2, i8* %1)
%31 = load i32, i32* @stdout
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %6)
%33 = call i32 @system(i8* %6)
%34 = icmp eq i32 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %29
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %35, %29
%39 = call i32 @emc_check_fence(i8* %0, i8* %1, i8* %2)
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i32, i32* @stdout
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.7, i64 0, i64 0), i8* %2, i8* %1)
br label %44
44: ; preds = %38, %41, %17, %20, %26
ret i32 0
}