#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ client;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ shutdown(int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    puts("usage: novastar-brightness <ipaddr>");
    return 0;
  }
  int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (sock == -1) {
    perror("socket error");
    return 1;
  } else {
    printf("socket ok\n");
  }
  struct sockaddr_in client = {.sin_addr.s_addr = inet_addr(argv[1]),
                               .sin_family = AF_INET,
                               .sin_port = htons(5200)};
  if (connect(sock, (struct sockaddr *)&client, sizeof(client)) == -1) {
    perror("connect error");
    close(sock);
    return 1;
  } else {
    printf("connect ok\n");
  }
  char payload[] = {0x55, 0xAA, 0x00, 0x00, 0xFE, 0xFF, 0x01,
                    0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x01, 0x00,
                    0x00, 0x02, 0x01, 0x00, 0x80, 0xD5, 0x5A};
  int numwrite = send(sock, payload, 21, 0);
  if (numwrite == -1) {
    perror("send error");
  } else {
    printf("send %d bytes ok\n", numwrite);
  }
  shutdown(sock, 2);
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d8 <main+0x38>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    1322 <main+0x182>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
mov    0x2def(%rip),%rax
mov    (%rax),%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    121d <main+0x7d>
lea    0xe18(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1322 <main+0x182>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1450,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
cmp    $0xffffffff,%eax
jne    128e <main+0xee>
lea    0xdc7(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1322 <main+0x182>
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0xddd(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xdda(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xdd8(%rip),%eax
mov    %eax,-0x30(%rbp)
mov    0xdd3(%rip),%al
mov    %al,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x15,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    12f5 <main+0x155>
lea    0xd6b(%rip),%rdi
call   10a0 <perror@plt>
jmp    1306 <main+0x166>
mov    -0x44(%rbp),%esi
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0x2,%esi
call   1040 <shutdown@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
cmp    $0x2,%edi
jne    1289 <main+0xe9>
mov    %rsi,%rbx
mov    0x2e2d(%rip),%r14
mov    (%r14),%edi
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
call   10c0 <socket@plt>
cmp    $0xffffffff,%eax
je     12a0 <main+0x100>
mov    %eax,%ebp
lea    0xe75(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1450,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
mov    (%r14),%eax
mov    %eax,0x4(%rsp)
mov    0x8(%rbx),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10b0 <connect@plt>
cmp    $0xffffffff,%eax
je     12b3 <main+0x113>
lea    0xe3a(%rip),%rdi
call   1030 <puts@plt>
movaps 0xe48(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0x5ad5800001020000,%rax
80 d5 5a
mov    %rax,0x1d(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x15,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0xffffffff,%eax
je     12cd <main+0x12d>
lea    0xddf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
mov    $0x2,%esi
call   1040 <shutdown@plt>
mov    %ebp,%edi
call   1080 <close@plt>
jmp    1295 <main+0xf5>
lea    0xd70(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd7d(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%eax
jmp    1297 <main+0xf7>
lea    0xd77(%rip),%rdi
call   10a0 <perror@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    $0x1,%eax
jmp    1297 <main+0xf7>
lea    0xd6b(%rip),%rdi
call   10a0 <perror@plt>
jmp    1274 <main+0xd4>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [36 x i8] c"usage: novastar-brightness <ipaddr>\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.1 = [13 x i8] c"socket error\00"
@.str.2 = [11 x i8] c"socket ok\0A\00"
@.str.3 = [14 x i8] c"connect error\00"
@.str.4 = [12 x i8] c"connect ok\0A\00"
@__const.main.payload = [21 x i8] c"U\AA\00\00\FE\FF\01\FF\FF\FF\01\00\01\00\00\02\01\00\80\D5Z"
@.str.5 = [11 x i8] c"send error\00"
@.str.6 = [18 x i8] c"send %d bytes ok\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca [21 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %63
14: ; preds = %2
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = load i32, i32* @IPPROTO_TCP
%18 = call i32 @socket(i32 %15, i32 %16, i32 %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %63
23: ; preds = %14
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%27 = call i32 @htons(i32 5200)
store i32 %27, i32* %26
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%29 = load i32, i32* @AF_INET
store i32 %29, i32* %28
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i32 0, i32 0
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @inet_addr(i8* %34)
store i32 %35, i32* %31
%36 = load i32, i32* %6
%37 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%38 = call i32 @connect(i32 %36, %struct.sockaddr* %37, i32 12)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %44
40: ; preds = %25
%41 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%42 = load i32, i32* %6
%43 = call i32 @close(i32 %42)
store i32 1, i32* %3
br label %63
44: ; preds = %25
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %44
%47 = bitcast [21 x i8]* %8 to i8*
%48 = load i32, i32* %6
%49 = getelementptr inbounds [21 x i8], [21 x i8]* %8, i64 0, i64 0
%50 = call i32 @send(i32 %48, i8* %49, i32 21, i32 0)
store i32 %50, i32* %9
%51 = load i32, i32* %9
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %55
53: ; preds = %46
%54 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %58
55: ; preds = %46
%56 = load i32, i32* %9
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %55, %53
%59 = load i32, i32* %6
%60 = call i32 @shutdown(i32 %59, i32 2)
%61 = load i32, i32* %6
%62 = call i32 @close(i32 %61)
store i32 0, i32* %3
br label %63
63: ; preds = %58, %40, %21, %12
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [36 x i8] c"usage: novastar-brightness <ipaddr>\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.1 = [13 x i8] c"socket error\00"
@.str.3 = [14 x i8] c"connect error\00"
@__const.main.payload = [21 x i8] c"U\AA\00\00\FE\FF\01\FF\FF\FF\01\00\01\00\00\02\01\00\80\D5Z"
@.str.5 = [11 x i8] c"send error\00"
@.str.6 = [18 x i8] c"send %d bytes ok\0A\00"
@str = [10 x i8] c"socket ok\00"
@str.7 = [11 x i8] c"connect ok\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [21 x i8]
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %47
8: ; preds = %2
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = load i32, i32* @IPPROTO_TCP
%12 = tail call i32 @socket(i32 %9, i32 %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %47
16: ; preds = %8
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%18 = bitcast %struct.sockaddr_in* %3 to i8*
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%20 = tail call i32 @htons(i32 5200)
store i32 %20, i32* %19
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%22 = load i32, i32* @AF_INET
store i32 %22, i32* %21
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2, i32 0
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = tail call i32 @inet_addr(i8* %25)
store i32 %26, i32* %23
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i32 @connect(i32 %12, %struct.sockaddr* %27, i32 12)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %16
%31 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @close(i32 %12)
br label %45
33: ; preds = %16
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.7, i64 0, i64 0))
%35 = getelementptr inbounds [21 x i8], [21 x i8]* %4, i64 0, i64 0
%36 = call i32 @send(i32 %12, i8* %35, i32 21, i32 0)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %42
40: ; preds = %33
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %36)
br label %42
42: ; preds = %40, %38
%43 = call i32 @shutdown(i32 %12, i32 2)
%44 = call i32 @close(i32 %12)
br label %45
45: ; preds = %42, %30
%46 = phi i32 [ 1, %30 ], [ 0, %42 ]
br label %47
47: ; preds = %14, %45, %6
%48 = phi i32 [ 0, %6 ], [ 1, %14 ], [ %46, %45 ]
ret i32 %48
}