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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDWR;
int PATH_MAX;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ chmod(char *, int /*<<< orphan*/);
int /*<<< orphan*/ chown(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execlp(char *, char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strtol(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  switch (argc) {
  case 1: {
    int ret = 0;
    int status;
    pid_t pid;
    pid = fork();
    if (pid == 0) {
      int fd_null = open("/dev/null", O_RDWR);
      dup2(fd_null, STDOUT_FILENO);
      dup2(fd_null, STDERR_FILENO);
      close(fd_null);
      execlp("nmcli", "nmcli", "con", "reload", NULL);
      _exit(EXIT_FAILURE);
    } else if (pid < 0)
      ret = -1;
    else if (waitpid(pid, &status, 0) != pid)
      ret = -1;
    if (!((!ret) && WIFEXITED(status) && !WEXITSTATUS(status))) {
      printf("gvpngate_suid: Unable reload connections.");
      printf("\n");
      return 1;
    }
    break;
  }
  case 2: {
    char tmpstr[PATH_MAX];
    sprintf(tmpstr, "/etc/NetworkManager/system-connections/%s", argv[1]);
    if (remove(tmpstr)) {
      printf("gvpngate_suid: Unable to delete system connection file.");
      printf("\n");
      return 1;
    }
    break;
  }
  case 3: {
    FILE *src;
    FILE *dst;
    char tmpstr[PATH_MAX];
    sprintf(tmpstr, "/etc/NetworkManager/system-connections/%s", argv[2]);
    src = fopen(argv[1], "r");
    dst = fopen(tmpstr, "w");
    if ((src != NULL) && (dst != NULL)) {
      char *line;
      size_t len = 0;
      while (getline(&line, &len, src) != -1)
        fprintf(dst, "%s", line);
      fclose(src);
      fclose(dst);
      if (chown(tmpstr, 0, 0)) {
        printf("gvpngate_suid: Unable to set ownership of system connection "
               "file.");
        printf("\n");
        return 1;
      }
      if (chmod(tmpstr, strtol("0600", 0, 8))) {
        printf("gvpngate_suid: Unable to set permissions of system connection "
               "file.");
        printf("\n");
        return 1;
      }
    } else {
      printf("gvpngate_suid: Unable to create system connection file.");
      printf("\n");
      return 1;
    }
    break;
  }
  default: {
    printf("gvpngate_suid: Incorrect number of arguments.");
    printf("\n");
    return 1;
  }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x6c(%rbp)
sub    $0x1,%eax
je     127f <main+0x4f>
jmp    125d <main+0x2d>
mov    -0x6c(%rbp),%eax
sub    $0x2,%eax
je     139f <main+0x16f>
jmp    126e <main+0x3e>
mov    -0x6c(%rbp),%eax
sub    $0x3,%eax
je     1440 <main+0x210>
jmp    15f6 <main+0x3c6>
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1150 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    130c <main+0xdc>
mov    0x2d37(%rip),%rax
mov    (%rax),%esi
lea    0xd56(%rip),%rdi
call   10f0 <open@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2d2c(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
mov    -0x20(%rbp),%edi
mov    0x2cfb(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
lea    0xd27(%rip),%rsi
lea    0xd26(%rip),%rdx
lea    0xd23(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   1140 <execlp@plt>
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
call   1040 <_exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jge    1322 <main+0xf2>
movl   $0xffffffff,-0x14(%rbp)
jmp    1345 <main+0x115>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   10e0 <waitpid@plt>
cmp    -0x1c(%rbp),%eax
je     1340 <main+0x110>
movl   $0xffffffff,-0x14(%rbp)
jmp    1345 <main+0x115>
jmp    134a <main+0x11a>
cmpl   $0x0,-0x14(%rbp)
jne    1376 <main+0x146>
mov    -0x18(%rbp),%edi
call   1120 <WIFEXITED@plt>
cmp    $0x0,%eax
je     1376 <main+0x146>
mov    -0x18(%rbp),%edi
call   10d0 <WEXITSTATUS@plt>
cmp    $0x0,%eax
je     139a <main+0x16a>
lea    0xc9e(%rip),%rdi
call   1070 <printf@plt>
lea    0xcbc(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1621 <main+0x3f1>
jmp    161a <main+0x3ea>
mov    0x2c4a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x78(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xc6d(%rip),%rsi
call   1130 <sprintf@plt>
mov    -0x78(%rbp),%rdi
call   1030 <remove@plt>
cmp    $0x0,%eax
je     141c <main+0x1ec>
lea    0xc79(%rip),%rdi
call   1070 <printf@plt>
lea    0xc41(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1423 <main+0x1f3>
movl   $0x2,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
je     1621 <main+0x3f1>
jmp    143b <main+0x20b>
jmp    161a <main+0x3ea>
mov    0x2ba9(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x80(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xbcc(%rip),%rsi
call   1130 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xc1a(%rip),%rsi
call   1100 <fopen@plt>
mov    -0x80(%rbp),%rdi
mov    %rax,-0x40(%rbp)
lea    0xc08(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     15a7 <main+0x377>
cmpq   $0x0,-0x48(%rbp)
je     15a7 <main+0x377>
movq   $0x0,-0x68(%rbp)
mov    -0x40(%rbp),%rdx
lea    -0x60(%rbp),%rdi
lea    -0x68(%rbp),%rsi
call   1110 <getline@plt>
cmp    $0xffffffff,%eax
je     14fd <main+0x2cd>
mov    -0x48(%rbp),%rdi
mov    -0x60(%rbp),%rdx
lea    0xb7b(%rip),%rsi
call   1090 <fprintf@plt>
jmp    14ca <main+0x29a>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x48(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x80(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10b0 <chown@plt>
cmp    $0x0,%eax
je     1550 <main+0x320>
lea    0xb81(%rip),%rdi
call   1070 <printf@plt>
lea    0xb0d(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    15d9 <main+0x3a9>
lea    0xb98(%rip),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   10a0 <strtol@plt>
mov    -0x80(%rbp),%rdi
mov    %eax,%esi
call   10c0 <chmod@plt>
cmp    $0x0,%eax
je     15a2 <main+0x372>
lea    0xb76(%rip),%rdi
call   1070 <printf@plt>
lea    0xabb(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    15d9 <main+0x3a9>
jmp    15d2 <main+0x3a2>
lea    0xb8a(%rip),%rdi
call   1070 <printf@plt>
lea    0xa8b(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    15d9 <main+0x3a9>
movl   $0x2,-0x34(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,%rsp
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
je     1621 <main+0x3f1>
jmp    15f1 <main+0x3c1>
jmp    161a <main+0x3ea>
lea    0xb73(%rip),%rdi
call   1070 <printf@plt>
lea    0xa3c(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1621 <main+0x3f1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
cmp    $0x3,%edi
je     12b7 <main+0x77>
cmp    $0x2,%edi
je     13a0 <main+0x160>
cmp    $0x1,%edi
jne    13fc <main+0x1bc>
xor    %eax,%eax
call   1160 <fork@plt>
test   %eax,%eax
je     1482 <main+0x242>
js     12ab <main+0x6b>
mov    %eax,%ebx
lea    -0x30(%rbp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   10f0 <waitpid@plt>
cmp    %ebx,%eax
jne    12ab <main+0x6b>
mov    -0x30(%rbp),%edi
call   1130 <WIFEXITED@plt>
test   %eax,%eax
je     12ab <main+0x6b>
mov    -0x30(%rbp),%edi
call   10e0 <WEXITSTATUS@plt>
test   %eax,%eax
je     143c <main+0x1fc>
lea    0xd69(%rip),%rdi
jmp    1403 <main+0x1c3>
mov    %rsp,%r12
mov    0x2d2f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    0x10(%r15),%rdx
lea    0xd66(%rip),%rsi
mov    %r14,%rdi
call   1140 <sprintf@plt>
mov    0x8(%r15),%rdi
lea    0xdb5(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,%rbx
lea    0xda8(%rip),%rsi
mov    %r14,%rdi
call   1110 <fopen@plt>
test   %rbx,%rbx
je     1419 <main+0x1d9>
mov    %rax,%r15
test   %rax,%rax
je     1419 <main+0x1d9>
mov    %r12,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    %rbx,%rdx
call   1120 <getline@plt>
cmp    $0xffffffff,%eax
je     136f <main+0x12f>
lea    -0x30(%rbp),%r12
lea    -0x40(%rbp),%r13
nopw   0x0(%rax,%rax,1)
mov    -0x30(%rbp),%rdi
mov    %r15,%rsi
call   1090 <fputs@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1120 <getline@plt>
cmp    $0xffffffff,%eax
jne    1350 <main+0x110>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <chown@plt>
test   %eax,%eax
je     144f <main+0x20f>
lea    0xd11(%rip),%rdi
mov    -0x38(%rbp),%r14
jmp    13e3 <main+0x1a3>
mov    %rsp,%r14
mov    0x2c46(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x8(%r15),%rdx
lea    0xc7d(%rip),%rsi
mov    %rbx,%rdi
call   1140 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <remove@plt>
test   %eax,%eax
je     1439 <main+0x1f9>
lea    0xc8c(%rip),%rdi
call   1080 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%ebx
mov    %r14,%rsp
jmp    143e <main+0x1fe>
lea    0xd6b(%rip),%rdi
call   1080 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%ebx
jmp    143e <main+0x1fe>
lea    0xd16(%rip),%rdi
call   1080 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%ebx
mov    %r12,%rsp
jmp    143e <main+0x1fe>
mov    %r14,%rsp
xor    %ebx,%ebx
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc97(%rip),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x8,%edx
call   10b0 <strtol@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   10d0 <chmod@plt>
test   %eax,%eax
mov    -0x38(%rbp),%r14
je     13f7 <main+0x1b7>
lea    0xc75(%rip),%rdi
jmp    13e3 <main+0x1a3>
mov    0x2b4f(%rip),%rax
mov    (%rax),%esi
lea    0xb6e(%rip),%rdi
call   1100 <open@plt>
mov    %eax,%ebx
mov    0x2b48(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1070 <dup2@plt>
mov    0x2b18(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1070 <dup2@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
lea    0xb43(%rip),%rdi
lea    0xb42(%rip),%rdx
lea    0xb3f(%rip),%rcx
mov    %rdi,%rsi
xor    %r8d,%r8d
call   1150 <execlp@plt>
mov    0x2ad9(%rip),%rax
mov    (%rax),%edi
call   1050 <_exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.1 = [6 x i8] c"nmcli\00"
@.str.2 = [4 x i8] c"con\00"
@.str.3 = [7 x i8] c"reload\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [42 x i8] c"gvpngate_suid: Unable reload connections.\00"
@.str.5 = [2 x i8] c"\0A\00"
@PATH_MAX = global i32 0
@.str.6 = [42 x i8] c"/etc/NetworkManager/system-connections/%s\00"
@.str.7 = [56 x i8] c"gvpngate_suid: Unable to delete system connection file.\00"
@.str.8 = [2 x i8] c"r\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [3 x i8] c"%s\00"
@.str.11 = [66 x i8] c"gvpngate_suid: Unable to set ownership of system connection file.\00"
@.str.12 = [5 x i8] c"0600\00"
@.str.13 = [68 x i8] c"gvpngate_suid: Unable to set permissions of system connection file.\00"
@.str.14 = [56 x i8] c"gvpngate_suid: Unable to create system connection file.\00"
@.str.15 = [46 x i8] c"gvpngate_suid: Incorrect number of arguments.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i8*
%18 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
switch i32 %19, label %136 [
i32 1, label %20
i32 2, label %65
i32 3, label %83
]
20: ; preds = %2
store i32 0, i32* %6
%21 = call i32 (...) @fork()
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %38
24: ; preds = %20
%25 = load i32, i32* @O_RDWR
%26 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %25)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = load i32, i32* @STDOUT_FILENO
%29 = call i32 @dup2(i32 %27, i32 %28)
%30 = load i32, i32* %9
%31 = load i32, i32* @STDERR_FILENO
%32 = call i32 @dup2(i32 %30, i32 %31)
%33 = load i32, i32* %9
%34 = call i32 @close(i32 %33)
%35 = call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32* null)
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @_exit(i32 %36)
unreachable
38: ; preds = %20
%39 = load i32, i32* %8
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %38
store i32 -1, i32* %6
br label %49
42: ; preds = %38
%43 = load i32, i32* %8
%44 = call i32 @waitpid(i32 %43, i32* %7, i32 0)
%45 = load i32, i32* %8
%46 = icmp ne i32 %44, %45
br i1 %46, label %47, label %48
47: ; preds = %42
store i32 -1, i32* %6
br label %48
48: ; preds = %47, %42
br label %49
49: ; preds = %48, %41
br label %50
50: ; preds = %49
%51 = load i32, i32* %6
%52 = icmp ne i32 %51, 0
br i1 %52, label %61, label %53
53: ; preds = %50
%54 = load i32, i32* %7
%55 = call i32 @WIFEXITED(i32 %54)
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %53
%58 = load i32, i32* %7
%59 = call i32 @WEXITSTATUS(i32 %58)
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %57, %53, %50
%62 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
%63 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %140
64: ; preds = %57
br label %139
65: ; preds = %2
%66 = load i32, i32* @PATH_MAX
%67 = zext i32 %66 to i64
%68 = call i8* @llvm.stacksave()
store i8* %68, i8** %10
%69 = alloca i8, i64 %67
store i64 %67, i64* %11
%70 = load i8**, i8*** %5
%71 = getelementptr inbounds i8*, i8** %70, i64 1
%72 = load i8*, i8** %71
%73 = call i32 @sprintf(i8* %69, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %72)
%74 = call i32 @remove(i8* %69)
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %65
%77 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.7, i64 0, i64 0))
%78 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %12
br label %80
79: ; preds = %65
store i32 2, i32* %12
br label %80
80: ; preds = %79, %76
%81 = load i8*, i8** %10
%82 = load i32, i32* %12
switch i32 %82, label %142 [
i32 1, label %140
i32 2, label %139
]
83: ; preds = %2
%84 = load i32, i32* @PATH_MAX
%85 = zext i32 %84 to i64
%86 = call i8* @llvm.stacksave()
store i8* %86, i8** %15
%87 = alloca i8, i64 %85
store i64 %85, i64* %16
%88 = load i8**, i8*** %5
%89 = getelementptr inbounds i8*, i8** %88, i64 2
%90 = load i8*, i8** %89
%91 = call i32 @sprintf(i8* %87, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %90)
%92 = load i8**, i8*** %5
%93 = getelementptr inbounds i8*, i8** %92, i64 1
%94 = load i8*, i8** %93
%95 = call i32* @fopen(i8* %94, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %95, i32** %13
%96 = call i32* @fopen(i8* %87, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %96, i32** %14
%97 = load i32*, i32** %13
%98 = icmp ne i32* %97, null
br i1 %98, label %99, label %129
99: ; preds = %83
%100 = load i32*, i32** %14
%101 = icmp ne i32* %100, null
br i1 %101, label %102, label %129
102: ; preds = %99
store i64 0, i64* %18
br label %103
103: ; preds = %107, %102
%104 = load i32*, i32** %13
%105 = call i32 @getline(i8** %17, i64* %18, i32* %104)
%106 = icmp ne i32 %105, -1
br i1 %106, label %107, label %111
107: ; preds = %103
%108 = load i32*, i32** %14
%109 = load i8*, i8** %17
%110 = call i32 @fprintf(i32* %108, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8* %109)
br label %103
111: ; preds = %103
%112 = load i32*, i32** %13
%113 = call i32 @fclose(i32* %112)
%114 = load i32*, i32** %14
%115 = call i32 @fclose(i32* %114)
%116 = call i32 @chown(i8* %87, i32 0, i32 0)
%117 = icmp ne i32 %116, 0
br i1 %117, label %118, label %121
118: ; preds = %111
%119 = call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.11, i64 0, i64 0))
%120 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %12
br label %133
121: ; preds = %111
%122 = call i32 @strtol(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i32 0, i32 8)
%123 = call i32 @chmod(i8* %87, i32 %122)
%124 = icmp ne i32 %123, 0
br i1 %124, label %125, label %128
125: ; preds = %121
%126 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.13, i64 0, i64 0))
%127 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %12
br label %133
128: ; preds = %121
br label %132
129: ; preds = %99, %83
%130 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.14, i64 0, i64 0))
%131 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %12
br label %133
132: ; preds = %128
store i32 2, i32* %12
br label %133
133: ; preds = %132, %129, %125, %118
%134 = load i8*, i8** %15
%135 = load i32, i32* %12
switch i32 %135, label %142 [
i32 1, label %140
i32 2, label %139
]
136: ; preds = %2
%137 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.15, i64 0, i64 0))
%138 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %140
139: ; preds = %133, %80, %64
store i32 0, i32* %3
br label %140
140: ; preds = %139, %136, %133, %80, %61
%141 = load i32, i32* %3
ret i32 %141
142: ; preds = %133, %80
unreachable
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.1 = [6 x i8] c"nmcli\00"
@.str.2 = [4 x i8] c"con\00"
@.str.3 = [7 x i8] c"reload\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [42 x i8] c"gvpngate_suid: Unable reload connections.\00"
@PATH_MAX = global i32 0
@.str.6 = [42 x i8] c"/etc/NetworkManager/system-connections/%s\00"
@.str.7 = [56 x i8] c"gvpngate_suid: Unable to delete system connection file.\00"
@.str.8 = [2 x i8] c"r\00"
@.str.9 = [2 x i8] c"w\00"
@.str.11 = [66 x i8] c"gvpngate_suid: Unable to set ownership of system connection file.\00"
@.str.12 = [5 x i8] c"0600\00"
@.str.13 = [68 x i8] c"gvpngate_suid: Unable to set permissions of system connection file.\00"
@.str.14 = [56 x i8] c"gvpngate_suid: Unable to create system connection file.\00"
@.str.15 = [46 x i8] c"gvpngate_suid: Incorrect number of arguments.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
switch i32 %0, label %94 [
i32 1, label %6
i32 2, label %38
i32 3, label %52
]
6: ; preds = %2
%7 = bitcast i32* %3 to i8*
%8 = tail call i32 (...) @fork()
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %6
%11 = load i32, i32* @O_RDWR
%12 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @STDOUT_FILENO
%14 = tail call i32 @dup2(i32 %12, i32 %13)
%15 = load i32, i32* @STDERR_FILENO
%16 = tail call i32 @dup2(i32 %12, i32 %15)
%17 = tail call i32 @close(i32 %12)
%18 = tail call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32* null)
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @_exit(i32 %19)
unreachable
21: ; preds = %6
%22 = icmp slt i32 %8, 0
br i1 %22, label %34, label %23
23: ; preds = %21
%24 = call i32 @waitpid(i32 %8, i32* %3, i32 0)
%25 = icmp eq i32 %24, %8
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = load i32, i32* %3
%28 = call i32 @WIFEXITED(i32 %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = load i32, i32* %3
%32 = call i32 @WEXITSTATUS(i32 %31)
%33 = icmp eq i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %23, %26, %30, %21
%35 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 @putchar(i32 10)
br label %97
37: ; preds = %30
br label %97
38: ; preds = %2
%39 = load i32, i32* @PATH_MAX
%40 = zext i32 %39 to i64
%41 = tail call i8* @llvm.stacksave()
%42 = alloca i8, i64 %40
%43 = getelementptr inbounds i8*, i8** %1, i64 1
%44 = load i8*, i8** %43
%45 = call i32 @sprintf(i8* %42, i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %44)
%46 = call i32 @remove(i8* %42)
%47 = icmp eq i32 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %38
%49 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.7, i64 0, i64 0))
%50 = tail call i32 @putchar(i32 10)
tail call void @llvm.stackrestore(i8* %41)
br label %97
51: ; preds = %38
tail call void @llvm.stackrestore(i8* %41)
br label %97
52: ; preds = %2
%53 = load i32, i32* @PATH_MAX
%54 = zext i32 %53 to i64
%55 = tail call i8* @llvm.stacksave()
%56 = alloca i8, i64 %54
%57 = getelementptr inbounds i8*, i8** %1, i64 2
%58 = load i8*, i8** %57
%59 = call i32 @sprintf(i8* %56, i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %58)
%60 = getelementptr inbounds i8*, i8** %1, i64 1
%61 = load i8*, i8** %60
%62 = tail call i32* @fopen(i8* %61, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%63 = call i32* @fopen(i8* %56, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%64 = icmp ne i32* %62, null
%65 = icmp ne i32* %63, null
%66 = and i1 %64, %65
br i1 %66, label %67, label %86
67: ; preds = %52
%68 = bitcast i8** %4 to i8*
%69 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%70 = call i32 @getline(i8** %4, i64* %5, i32* %62)
%71 = icmp eq i32 %70, -1
br i1 %71, label %77, label %72
72: ; preds = %67, %72
%73 = load i8*, i8** %4
%74 = call i32 @fputs(i8* %73, i32* %63)
%75 = call i32 @getline(i8** %4, i64* %5, i32* %62)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %72
77: ; preds = %72, %67
%78 = call i32 @fclose(i32* %62)
%79 = call i32 @fclose(i32* %63)
%80 = call i32 @chown(i8* %56, i32 0, i32 0)
%81 = icmp eq i32 %80, 0
br i1 %81, label %82, label %89
82: ; preds = %77
%83 = call i32 @strtol(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i32 0, i32 8)
%84 = call i32 @chmod(i8* %56, i32 %83)
%85 = icmp eq i32 %84, 0
br i1 %85, label %93, label %89
86: ; preds = %52
%87 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.14, i64 0, i64 0))
%88 = tail call i32 @putchar(i32 10)
tail call void @llvm.stackrestore(i8* %55)
br label %97
89: ; preds = %82, %77
%90 = phi i8* [ getelementptr inbounds ([66 x i8], [66 x i8]* @.str.11, i64 0, i64 0), %77 ], [ getelementptr inbounds ([68 x i8], [68 x i8]* @.str.13, i64 0, i64 0), %82 ]
%91 = call i32 @printf(i8* dereferenceable(1) %90)
%92 = call i32 @putchar(i32 10)
br label %97
93: ; preds = %82
br label %97
94: ; preds = %2
%95 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.15, i64 0, i64 0))
%96 = tail call i32 @putchar(i32 10)
br label %97
97: ; preds = %37, %51, %93, %89, %86, %48, %34, %94
%98 = phi i32 [ 1, %94 ], [ 1, %34 ], [ 1, %48 ], [ 1, %86 ], [ 1, %89 ], [ 0, %93 ], [ 0, %51 ], [ 0, %37 ]
ret i32 %98
}