#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*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int send_cmd(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd;
  int n;
  char buf[4096];
  char *sockpath = "/var/run/l2tpctrl";
  if (argc > 2 && !strcmp(argv[1], "-s") && argv[2] && argv[2][0]) {
    sockpath = argv[2];
    argv += 2;
    argc -= 2;
  }
  if (argc != 2) {
    fprintf(stderr, "Usage: %s [-s socket] command\n", argv[0]);
    return 1;
  }
  fd = send_cmd(argv[1], 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    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe60(%rip),%rax
mov    %rax,-0x1028(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1215 <main+0x95>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe52(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1215 <main+0x95>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     1215 <main+0x95>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1215 <main+0x95>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x1028(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1247 <main+0xc7>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xddf(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1309 <main+0x189>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x1028(%rbp),%rsi
call   10a0 <send_cmd@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1274 <main+0xf4>
movl   $0x1,-0x4(%rbp)
jmp    1309 <main+0x189>
jmp    1279 <main+0xf9>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12c6 <main+0x146>
lea    0xd93(%rip),%rdi
call   1090 <perror@plt>
lea    0xd85(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1309 <main+0x189>
cmpl   $0x0,-0x18(%rbp)
jne    12f0 <main+0x170>
lea    0xd5b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1309 <main+0x189>
lea    -0x1020(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    1279 <main+0xf9>
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x3,%edi
jl     11f0 <main+0x70>
mov    0x8(%rbx),%rdi
lea    0xe72(%rip),%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
jne    11c3 <main+0x43>
mov    0x10(%rbx),%rsi
test   %rsi,%rsi
je     11c3 <main+0x43>
cmpb   $0x0,(%rsi)
je     11c3 <main+0x43>
add    $0x10,%rbx
add    $0xfffffffe,%ebp
cmp    $0x2,%ebp
je     11fc <main+0x7c>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe3f(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe09(%rip),%rsi
cmp    $0x2,%ebp
jne    11c3 <main+0x43>
mov    0x8(%rbx),%rdi
call   10a0 <send_cmd@plt>
mov    $0x1,%r14d
test   %eax,%eax
js     11e1 <main+0x61>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x1000,%edx
call   1060 <read@plt>
test   %eax,%eax
js     1256 <main+0xd6>
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
test   %eax,%eax
je     1278 <main+0xf8>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
test   %eax,%eax
jns    1230 <main+0xb0>
lea    0xdd7(%rip),%rdi
call   1090 <perror@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    11e1 <main+0x61>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %r14d,%r14d
jmp    11e1 <main+0x61>

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

LLVM IR (-O2):
@.str = [18 x i8] c"/var/run/l2tpctrl\00"
@.str.1 = [3 x i8] c"-s\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"Usage: %s [-s socket] command\0A\00"
@.str.3 = [5 x i8] c"read\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 2
br i1 %5, label %6, label %20
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strcmp(i8* dereferenceable(1) %8, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %6
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = icmp eq i8* %13, null
br i1 %14, label %25, label %15
15: ; preds = %11
%16 = load i8, i8* %13
%17 = icmp eq i8 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %15
%19 = add nsw i32 %0, -2
br label %20
20: ; preds = %18, %2
%21 = phi i8** [ %12, %18 ], [ %1, %2 ]
%22 = phi i32 [ %19, %18 ], [ %0, %2 ]
%23 = phi i8* [ %13, %18 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %2 ]
%24 = icmp eq i32 %22, 2
br i1 %24, label %30, label %25
25: ; preds = %11, %15, %6, %20
%26 = phi i8** [ %21, %20 ], [ %1, %6 ], [ %1, %15 ], [ %1, %11 ]
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %26
%29 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %52
30: ; preds = %20
%31 = getelementptr inbounds i8*, i8** %21, i64 1
%32 = load i8*, i8** %31
%33 = tail call i32 @send_cmd(i8* %32, i8* %23)
%34 = icmp slt i32 %33, 0
br i1 %34, label %52, label %35
35: ; preds = %30
%36 = call i32 @read(i32 %33, i8* %4, i32 4096)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %48, %35
%39 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%40 = tail call i32 @putchar(i32 10)
%41 = tail call i32 @close(i32 %33)
br label %52
42: ; preds = %35, %48
%43 = phi i32 [ %50, %48 ], [ %36, %35 ]
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = tail call i32 @putchar(i32 10)
%47 = tail call i32 @close(i32 %33)
br label %52
48: ; preds = %42
%49 = call i32 @write(i32 1, i8* %4, i32 %43)
%50 = call i32 @read(i32 %33, i8* %4, i32 4096)
%51 = icmp slt i32 %50, 0
br i1 %51, label %38, label %42
52: ; preds = %30, %45, %38, %25
%53 = phi i32 [ 1, %25 ], [ 1, %38 ], [ 0, %45 ], [ 1, %30 ]
ret i32 %53
}