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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ close(int);
int getopt(int, char **, char *);
char *optarg;
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int send_cmd(char *, char *);
int /*<<< orphan*/ usage(int, char **, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd;
  int n;
  int opt;
  char buf[4096];
  char *sockpath = "/var/run/l2tpctrl";
  while ((opt = getopt(argc, argv, "s:h")) != -1) {
    switch (opt) {
    case 's':
      sockpath = optarg;
      break;
    default:
      usage(argc, argv, (opt == 'h') ? EXIT_SUCCESS : EXIT_FAILURE);
    }
  }
  if (optind >= argc) {
    usage(argc, argv, EXIT_FAILURE);
  }
  fd = send_cmd(argv[optind], sockpath);
  if (fd < 0) {
    return 1;
  }
  for (;;) {
    n = read(fd, buf, sizeof(buf));
    if (n < 0) {
      perror("read");
      printf("\n");
      close(fd);
      return 1;
    }
    if (n == 0) {
      printf("\n");
      close(fd);
      return 0;
    }
    write(1, buf, n);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe60(%rip),%rax
mov    %rax,-0x1028(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe5d(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     124b <main+0xcb>
mov    -0x1c(%rbp),%eax
sub    $0x73,%eax
jne    11ed <main+0x6d>
jmp    11d7 <main+0x57>
mov    0x2e1a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x1028(%rbp)
jmp    1246 <main+0xc6>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1034(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x1030(%rbp)
cmpl   $0x68,-0x1c(%rbp)
jne    121f <main+0x9f>
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1038(%rbp)
jmp    122e <main+0xae>
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1038(%rbp)
mov    -0x1030(%rbp),%rsi
mov    -0x1034(%rbp),%edi
mov    -0x1038(%rbp),%edx
call   1070 <usage@plt>
jmp    11a7 <main+0x27>
mov    0x2d8e(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     1272 <main+0xf2>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2d65(%rip),%rax
mov    (%rax),%edx
call   1070 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x2d63(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x1028(%rbp),%rsi
call   10a0 <send_cmd@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12a9 <main+0x129>
movl   $0x1,-0x4(%rbp)
jmp    133e <main+0x1be>
jmp    12ae <main+0x12e>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12fb <main+0x17b>
lea    0xd40(%rip),%rdi
call   1080 <perror@plt>
lea    0xd39(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    133e <main+0x1be>
cmpl   $0x0,-0x18(%rbp)
jne    1325 <main+0x1a5>
lea    0xd0f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    133e <main+0x1be>
lea    -0x1020(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    12ae <main+0x12e>
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe63(%rip),%r14
lea    0xe6e(%rip),%r15
mov    0x2e25(%rip),%r13
mov    0x2e16(%rip),%r12
jmp    11cc <main+0x4c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rcx),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <usage@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
je     11fc <main+0x7c>
cmp    $0x73,%eax
je     11f0 <main+0x70>
mov    %r13,%rcx
cmp    $0x68,%eax
jne    11c0 <main+0x40>
mov    %r12,%rcx
jmp    11c0 <main+0x40>
mov    0x2e01(%rip),%rax
mov    (%rax),%r14
jmp    11cc <main+0x4c>
mov    0x2ddd(%rip),%r15
mov    (%r15),%eax
cmp    %ebp,%eax
jl     1220 <main+0xa0>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <usage@plt>
mov    (%r15),%eax
cltq
mov    (%rbx,%rax,8),%rdi
mov    %r14,%rsi
call   10a0 <send_cmd@plt>
test   %eax,%eax
js     129e <main+0x11e>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x1000,%edx
call   1060 <read@plt>
test   %eax,%eax
js     1276 <main+0xf6>
mov    %rsp,%rbp
nopw   0x0(%rax,%rax,1)
test   %eax,%eax
je     1289 <main+0x109>
mov    $0x1,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
test   %eax,%eax
jns    1250 <main+0xd0>
lea    0xd99(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%ebp
jmp    128b <main+0x10b>
xor    %ebp,%ebp
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%edi
call   1050 <close@plt>
jmp    12a3 <main+0x123>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"/var/run/l2tpctrl\00"
@.str.1 = [4 x i8] c"s:h\00"
@optarg = global i8* null
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@optind = global i32 0
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [2 x i8] c"\0A\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 [4096 x i8]
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %10
br label %11
11: ; preds = %32, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32 %14, i32* %8
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %33
16: ; preds = %11
%17 = load i32, i32* %8
switch i32 %17, label %20 [
i32 115, label %18
]
18: ; preds = %16
%19 = load i8*, i8** @optarg
store i8* %19, i8** %10
br label %32
20: ; preds = %16
%21 = load i32, i32* %4
%22 = load i8**, i8*** %5
%23 = load i32, i32* %8
%24 = icmp eq i32 %23, 104
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = load i32, i32* @EXIT_SUCCESS
br label %29
27: ; preds = %20
%28 = load i32, i32* @EXIT_FAILURE
br label %29
29: ; preds = %27, %25
%30 = phi i32 [ %26, %25 ], [ %28, %27 ]
%31 = call i32 @usage(i32 %21, i8** %22, i32 %30)
br label %32
32: ; preds = %29, %18
br label %11
33: ; preds = %11
%34 = load i32, i32* @optind
%35 = load i32, i32* %4
%36 = icmp sge i32 %34, %35
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i32, i32* %4
%39 = load i8**, i8*** %5
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @usage(i32 %38, i8** %39, i32 %40)
br label %42
42: ; preds = %37, %33
%43 = load i8**, i8*** %5
%44 = load i32, i32* @optind
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = load i8*, i8** %10
%49 = call i32 @send_cmd(i8* %47, i8* %48)
store i32 %49, i32* %6
%50 = load i32, i32* %6
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %42
store i32 1, i32* %3
br label %76
53: ; preds = %42
br label %54
54: ; preds = %72, %53
%55 = load i32, i32* %6
%56 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%57 = call i32 @read(i32 %55, i8* %56, i32 4096)
store i32 %57, i32* %7
%58 = load i32, i32* %7
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %54
%61 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%62 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%63 = load i32, i32* %6
%64 = call i32 @close(i32 %63)
store i32 1, i32* %3
br label %76
65: ; preds = %54
%66 = load i32, i32* %7
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %65
%69 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%70 = load i32, i32* %6
%71 = call i32 @close(i32 %70)
store i32 0, i32* %3
br label %76
72: ; preds = %65
%73 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%74 = load i32, i32* %7
%75 = call i32 @write(i32 1, i8* %73, i32 %74)
br label %54
76: ; preds = %68, %60, %52
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@.str = [18 x i8] c"/var/run/l2tpctrl\00"
@.str.1 = [4 x i8] c"s:h\00"
@optarg = global i8* null
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@optind = global i32 0
@.str.2 = [5 x i8] c"read\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %9, %2
%6 = phi i8* [ %10, %9 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %2 ]
br label %7
7: ; preds = %5, %11
%8 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
switch i32 %8, label %11 [
i32 -1, label %17
i32 115, label %9
]
9: ; preds = %7
%10 = load i8*, i8** @optarg
br label %5
11: ; preds = %7
%12 = icmp eq i32 %8, 104
%13 = load i32, i32* @EXIT_SUCCESS
%14 = load i32, i32* @EXIT_FAILURE
%15 = select i1 %12, i32 %13, i32 %14
%16 = tail call i32 @usage(i32 %0, i8** %1, i32 %15)
br label %7
17: ; preds = %7
%18 = load i32, i32* @optind
%19 = icmp slt i32 %18, %0
br i1 %19, label %24, label %20
20: ; preds = %17
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @usage(i32 %0, i8** %1, i32 %21)
%23 = load i32, i32* @optind
br label %24
24: ; preds = %20, %17
%25 = phi i32 [ %23, %20 ], [ %18, %17 ]
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %1, i64 %26
%28 = load i8*, i8** %27
%29 = tail call i32 @send_cmd(i8* %28, i8* %6)
%30 = icmp slt i32 %29, 0
br i1 %30, label %47, label %31
31: ; preds = %24
%32 = call i32 @read(i32 %29, i8* %4, i32 4096)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %39, %31
%35 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %43
36: ; preds = %31, %39
%37 = phi i32 [ %41, %39 ], [ %32, %31 ]
%38 = icmp eq i32 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %36
%40 = call i32 @write(i32 1, i8* %4, i32 %37)
%41 = call i32 @read(i32 %29, i8* %4, i32 4096)
%42 = icmp slt i32 %41, 0
br i1 %42, label %34, label %36
43: ; preds = %36, %34
%44 = phi i32 [ 1, %34 ], [ 0, %36 ]
%45 = tail call i32 @putchar(i32 10)
%46 = tail call i32 @close(i32 %29)
br label %47
47: ; preds = %43, %24
%48 = phi i32 [ 1, %24 ], [ %44, %43 ]
ret i32 %48
}