#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;
};
struct in_addr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ server;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ herror(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
char *inet_ntoa(struct in_addr);
char *malloc(scalar_t__);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pinMode(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
scalar_t__ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *strstr(char *, char *);
int /*<<< orphan*/ turnOff(int);
int /*<<< orphan*/ turnOn(int);
int main(int argc, char *argv[]) {
  char *ip;
  char *host;
  int sock;
  struct sockaddr_in server;
  char server_reply[2000];
  printf("OpenWRT smart home v1.00a\n");
  printf("http://smarthome.russemotto.com\n\n");
  if (argc < 2) {
    printf("\nI need a hostname\n");
    return 0;
  }
  host = argv[1];
  struct hostent *h;
  if ((h = gethostbyname(host)) == NULL) {
    herror("gethostbyname");
    return 0;
  }
  ip = inet_ntoa(*((struct in_addr *)h->h_addr));
  pinMode(29, 0);
  while (1) {
    sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock == -1) {
      printf("Could not create socket");
    }
    server.sin_addr.s_addr = inet_addr(ip);
    server.sin_family = AF_INET;
    server.sin_port = htons(80);
    if (connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0) {
      perror(" Error: connection failed.");
    }
    printf("Connected\n");
    char *message = malloc(26 + strlen(host) + 28);
    strcpy(message, "GET /LP HTTP/1.0\r\nHost: ");
    strcat(message, host);
    strcat(message, "\r\nUser-Agent: smarthome\r\n\r\n");
    if (send(sock, message, strlen(message), 0) < 0) {
      printf("Error: Send failed");
    }
    if (recv(sock, server_reply, 2000, 0) >= 0) {
      puts("Server reply :");
      puts(server_reply);
      int htmlstart = 0;
      char *htmlcontent;
      if (htmlstart == 0) {
        htmlcontent = strstr(server_reply, "\r\n\r\n");
        if (htmlcontent != NULL) {
          htmlstart = 1;
          htmlcontent += 4;
        }
      }
      if (strncmp(htmlcontent, "on", 2) == 0) {
        printf("Turning on");
        turnOn(2);
      }
      if (strncmp(htmlcontent, "off", 3) == 0) {
        printf("Turning off");
        turnOff(2);
      }
    }
    close(sock);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xd80(%rip),%rdi
call   10c0 <printf@plt>
lea    0xd8f(%rip),%rdi
call   10c0 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
jge    12b3 <main+0x53>
lea    0xd9b(%rip),%rdi
call   10c0 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1559 <main+0x2f9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   10f0 <gethostbyname@plt>
mov    %rax,-0x808(%rbp)
cmp    $0x0,%rax
jne    12f1 <main+0x91>
lea    0xd71(%rip),%rdi
call   1120 <herror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1559 <main+0x2f9>
mov    -0x808(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1080 <inet_ntoa@plt>
mov    %rax,-0x18(%rbp)
mov    $0x1d,%edi
xor    %esi,%esi
call   1130 <pinMode@plt>
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
mov    0x2cb6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1344 <main+0xe4>
lea    0xd20(%rip),%rdi
call   10c0 <printf@plt>
mov    -0x18(%rbp),%rdi
call   10e0 <inet_addr@plt>
mov    %eax,-0x28(%rbp)
mov    0x2c91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x50,%edi
call   10a0 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   1160 <connect@plt>
cmp    $0x0,%rax
jge    1390 <main+0x130>
lea    0xcec(%rip),%rdi
call   1140 <perror@plt>
lea    0xcfb(%rip),%rdi
call   10c0 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1090 <strlen@plt>
add    $0x1a,%eax
add    $0x1c,%eax
movslq %eax,%rdi
call   1100 <malloc@plt>
mov    %rax,-0x810(%rbp)
mov    -0x810(%rbp),%rdi
lea    0xcd5(%rip),%rsi
call   1060 <strcpy@plt>
mov    -0x810(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1150 <strcat@plt>
mov    -0x810(%rbp),%rdi
lea    0xccb(%rip),%rsi
call   1150 <strcat@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x82c(%rbp)
mov    -0x810(%rbp),%rax
mov    %rax,-0x828(%rbp)
mov    -0x810(%rbp),%rdi
call   1090 <strlen@plt>
mov    -0x82c(%rbp),%edi
mov    -0x828(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   10b0 <send@plt>
cmp    $0x0,%rax
jge    143f <main+0x1df>
lea    0xc98(%rip),%rdi
call   10c0 <printf@plt>
mov    -0x24(%rbp),%edi
lea    -0x800(%rbp),%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
jl     154c <main+0x2ec>
lea    0xc7f(%rip),%rdi
call   1070 <puts@plt>
lea    -0x800(%rbp),%rdi
call   1070 <puts@plt>
movl   $0x0,-0x814(%rbp)
cmpl   $0x0,-0x814(%rbp)
jne    14d7 <main+0x277>
lea    -0x800(%rbp),%rdi
lea    0xc31(%rip),%rsi
call   1170 <strstr@plt>
mov    %rax,-0x820(%rbp)
cmpq   $0x0,-0x820(%rbp)
je     14d2 <main+0x272>
movl   $0x1,-0x814(%rbp)
mov    -0x820(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x820(%rbp)
jmp    14d7 <main+0x277>
mov    -0x820(%rbp),%rdi
lea    0xc17(%rip),%rsi
mov    $0x2,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    150f <main+0x2af>
lea    0xbf4(%rip),%rdi
call   10c0 <printf@plt>
mov    $0x2,%edi
call   1040 <turnOn@plt>
mov    -0x820(%rbp),%rdi
lea    0xbea(%rip),%rsi
mov    $0x3,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    1547 <main+0x2e7>
lea    0xbc7(%rip),%rdi
call   10c0 <printf@plt>
mov    $0x2,%edi
call   1110 <turnOff@plt>
jmp    154c <main+0x2ec>
mov    -0x24(%rbp),%edi
call   10d0 <close@plt>
jmp    1312 <main+0xb2>
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7f8,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe32(%rip),%rdi
call   1070 <puts@plt>
lea    0xe40(%rip),%rdi
call   1070 <puts@plt>
cmp    $0x1,%ebp
jg     12a4 <main+0x44>
lea    0xe5a(%rip),%rdi
call   1070 <puts@plt>
jmp    1498 <main+0x238>
mov    0x8(%rbx),%r15
mov    %r15,%rdi
call   10f0 <gethostbyname@plt>
test   %rax,%rax
je     148c <main+0x22c>
mov    (%rax),%rax
mov    (%rax),%edi
call   1080 <inet_ntoa@plt>
mov    %rax,0x18(%rsp)
mov    $0x1d,%edi
xor    %esi,%esi
call   1130 <pinMode@plt>
mov    0x2d0d(%rip),%r14
lea    0x20(%rsp),%r12
jmp    12f7 <main+0x97>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
call   10d0 <close@plt>
mov    (%r14),%edi
mov    0x2cd7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    131d <main+0xbd>
lea    0xcf6(%rip),%rdi
call   10c0 <printf@plt>
mov    0x18(%rsp),%rdi
call   10e0 <inet_addr@plt>
mov    %eax,0x10(%rsp)
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
mov    $0x50,%edi
call   10a0 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
lea    0x8(%rsp),%rsi
mov    $0xc,%edx
call   1160 <connect@plt>
test   %rax,%rax
js     147b <main+0x21b>
lea    0xd89(%rip),%rdi
call   1070 <puts@plt>
mov    %r15,%rdi
call   1090 <strlen@plt>
add    $0x36,%eax
movslq %eax,%rdi
call   1100 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
lea    0xcbb(%rip),%rsi
call   1060 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1150 <strcat@plt>
mov    %rbx,%rdi
lea    0xcba(%rip),%rsi
call   1150 <strcat@plt>
mov    %rbx,%rdi
call   1090 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   10b0 <send@plt>
test   %rax,%rax
jns    13cc <main+0x16c>
lea    0xcaf(%rip),%rdi
call   10c0 <printf@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
js     12f0 <main+0x90>
lea    0xc9c(%rip),%rdi
call   1070 <puts@plt>
mov    %r12,%rdi
call   1070 <puts@plt>
mov    %r12,%rdi
lea    0xc6d(%rip),%rsi
call   1170 <strstr@plt>
lea    0x4(%rax),%r13
test   %rax,%rax
cmove  %rax,%r13
mov    %r13,%rdi
lea    0xc82(%rip),%rsi
mov    $0x2,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
jne    1443 <main+0x1e3>
lea    0xc64(%rip),%rdi
call   10c0 <printf@plt>
mov    $0x2,%edi
call   1040 <turnOn@plt>
mov    %r13,%rdi
lea    0xc5e(%rip),%rsi
mov    $0x3,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
jne    12f0 <main+0x90>
lea    0xc3c(%rip),%rdi
call   10c0 <printf@plt>
mov    $0x2,%edi
call   1110 <turnOff@plt>
jmp    12f0 <main+0x90>
lea    0xba4(%rip),%rdi
call   1140 <perror@plt>
jmp    135a <main+0xfa>
lea    0xb6d(%rip),%rdi
call   1120 <herror@plt>
xor    %eax,%eax
add    $0x7f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i64 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [27 x i8] c"OpenWRT smart home v1.00a\0A\00"
@.str.1 = [34 x i8] c"http://smarthome.russemotto.com\0A\0A\00"
@.str.2 = [20 x i8] c"\0AI need a hostname\0A\00"
@.str.3 = [14 x i8] c"gethostbyname\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [24 x i8] c"Could not create socket\00"
@.str.5 = [27 x i8] c" Error: connection failed.\00"
@.str.6 = [11 x i8] c"Connected\0A\00"
@.str.7 = [25 x i8] c"GET /LP HTTP/1.0\0D\0AHost: \00"
@.str.8 = [28 x i8] c"\0D\0AUser-Agent: smarthome\0D\0A\0D\0A\00"
@.str.9 = [19 x i8] c"Error: Send failed\00"
@.str.10 = [15 x i8] c"Server reply :\00"
@.str.11 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.12 = [3 x i8] c"on\00"
@.str.13 = [11 x i8] c"Turning on\00"
@.str.14 = [4 x i8] c"off\00"
@.str.15 = [12 x i8] c"Turning off\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca [2000 x i8]
%11 = alloca %struct.hostent*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 2
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %123
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = call %struct.hostent* @gethostbyname(i8* %25)
store %struct.hostent* %26, %struct.hostent** %11
%27 = icmp eq %struct.hostent* %26, null
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = call i32 @herror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %123
30: ; preds = %21
%31 = load %struct.hostent*, %struct.hostent** %11
%32 = getelementptr inbounds %struct.hostent, %struct.hostent* %31, i32 0, i32 0
%33 = load i64, i64* %32
%34 = inttoptr i64 %33 to %struct.in_addr*
%35 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i8* @inet_ntoa(i32 %36)
store i8* %37, i8** %6
%38 = call i32 @pinMode(i32 29, i32 0)
br label %39
39: ; preds = %30, %120
%40 = load i32, i32* @AF_INET
%41 = load i32, i32* @SOCK_STREAM
%42 = call i32 @socket(i32 %40, i32 %41, i32 0)
store i32 %42, i32* %8
%43 = load i32, i32* %8
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %47
45: ; preds = %39
%46 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %47
47: ; preds = %45, %39
%48 = load i8*, i8** %6
%49 = call i32 @inet_addr(i8* %48)
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
%51 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %50, i32 0, i32 0
store i32 %49, i32* %51
%52 = load i32, i32* @AF_INET
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %52, i32* %53
%54 = call i32 @htons(i32 80)
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %54, i32* %55
%56 = load i32, i32* %8
%57 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%58 = call i64 @connect(i32 %56, %struct.sockaddr* %57, i32 12)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %47
%61 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %62
62: ; preds = %60, %47
%63 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%64 = load i8*, i8** %7
%65 = call i32 @strlen(i8* %64)
%66 = add nsw i32 26, %65
%67 = add nsw i32 %66, 28
%68 = sext i32 %67 to i64
%69 = call i8* @malloc(i64 %68)
store i8* %69, i8** %12
%70 = load i8*, i8** %12
%71 = call i32 @strcpy(i8* %70, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
%72 = load i8*, i8** %12
%73 = load i8*, i8** %7
%74 = call i32 @strcat(i8* %72, i8* %73)
%75 = load i8*, i8** %12
%76 = call i32 @strcat(i8* %75, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%77 = load i32, i32* %8
%78 = load i8*, i8** %12
%79 = load i8*, i8** %12
%80 = call i32 @strlen(i8* %79)
%81 = call i64 @send(i32 %77, i8* %78, i32 %80, i32 0)
%82 = icmp slt i64 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %62
%84 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
br label %85
85: ; preds = %83, %62
%86 = load i32, i32* %8
%87 = getelementptr inbounds [2000 x i8], [2000 x i8]* %10, i64 0, i64 0
%88 = call i64 @recv(i32 %86, i8* %87, i32 2000, i32 0)
%89 = icmp sge i64 %88, 0
br i1 %89, label %90, label %120
90: ; preds = %85
%91 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
%92 = getelementptr inbounds [2000 x i8], [2000 x i8]* %10, i64 0, i64 0
%93 = call i32 @puts(i8* %92)
store i32 0, i32* %13
%94 = load i32, i32* %13
%95 = icmp eq i32 %94, 0
br i1 %95, label %96, label %105
96: ; preds = %90
%97 = getelementptr inbounds [2000 x i8], [2000 x i8]* %10, i64 0, i64 0
%98 = call i8* @strstr(i8* %97, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
store i8* %98, i8** %14
%99 = load i8*, i8** %14
%100 = icmp ne i8* %99, null
br i1 %100, label %101, label %104
101: ; preds = %96
store i32 1, i32* %13
%102 = load i8*, i8** %14
%103 = getelementptr inbounds i8, i8* %102, i64 4
store i8* %103, i8** %14
br label %104
104: ; preds = %101, %96
br label %105
105: ; preds = %104, %90
%106 = load i8*, i8** %14
%107 = call i64 @strncmp(i8* %106, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i32 2)
%108 = icmp eq i64 %107, 0
br i1 %108, label %109, label %112
109: ; preds = %105
%110 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.13, i64 0, i64 0))
%111 = call i32 @turnOn(i32 2)
br label %112
112: ; preds = %109, %105
%113 = load i8*, i8** %14
%114 = call i64 @strncmp(i8* %113, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0), i32 3)
%115 = icmp eq i64 %114, 0
br i1 %115, label %116, label %119
116: ; preds = %112
%117 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0))
%118 = call i32 @turnOff(i32 2)
br label %119
119: ; preds = %116, %112
br label %120
120: ; preds = %119, %85
%121 = load i32, i32* %8
%122 = call i32 @close(i32 %121)
br label %39
123: ; preds = %28, %19
%124 = load i32, i32* %3
ret i32 %124
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i64 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@.str.3 = [14 x i8] c"gethostbyname\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [24 x i8] c"Could not create socket\00"
@.str.5 = [27 x i8] c" Error: connection failed.\00"
@.str.7 = [25 x i8] c"GET /LP HTTP/1.0\0D\0AHost: \00"
@.str.8 = [28 x i8] c"\0D\0AUser-Agent: smarthome\0D\0A\0D\0A\00"
@.str.9 = [19 x i8] c"Error: Send failed\00"
@.str.10 = [15 x i8] c"Server reply :\00"
@.str.11 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.12 = [3 x i8] c"on\00"
@.str.13 = [11 x i8] c"Turning on\00"
@.str.14 = [4 x i8] c"off\00"
@.str.15 = [12 x i8] c"Turning off\00"
@str = [26 x i8] c"OpenWRT smart home v1.00a\00"
@str.16 = [33 x i8] c"http://smarthome.russemotto.com\0A\00"
@str.17 = [10 x i8] c"Connected\00"
@str.18 = [19 x i8] c"\0AI need a hostname\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [2000 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [2000 x i8], [2000 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.16, i64 0, i64 0))
%9 = icmp slt i32 %0, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.18, i64 0, i64 0))
br label %83
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call %struct.hostent* @gethostbyname(i8* %14)
%16 = icmp eq %struct.hostent* %15, null
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i32 @herror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %83
19: ; preds = %12
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i64 0, i32 0
%21 = load i64, i64* %20
%22 = inttoptr i64 %21 to %struct.in_addr*
%23 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %22, i64 0, i32 0
%24 = load i32, i32* %23
%25 = tail call i8* @inet_ntoa(i32 %24)
%26 = tail call i32 @pinMode(i32 29, i32 0)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2, i32 0
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%30 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %31
31: ; preds = %81, %19
%32 = load i32, i32* @AF_INET
%33 = load i32, i32* @SOCK_STREAM
%34 = call i32 @socket(i32 %32, i32 %33, i32 0)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %36, %31
%39 = call i32 @inet_addr(i8* %25)
store i32 %39, i32* %27
%40 = load i32, i32* @AF_INET
store i32 %40, i32* %28
%41 = call i32 @htons(i32 80)
store i32 %41, i32* %29
%42 = call i64 @connect(i32 %34, %struct.sockaddr* %30, i32 12)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %38
%45 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %46
46: ; preds = %44, %38
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.17, i64 0, i64 0))
%48 = call i32 @strlen(i8* %14)
%49 = add nsw i32 %48, 54
%50 = sext i32 %49 to i64
%51 = call i8* @malloc(i64 %50)
%52 = call i32 @strcpy(i8* %51, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
%53 = call i32 @strcat(i8* %51, i8* %14)
%54 = call i32 @strcat(i8* %51, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%55 = call i32 @strlen(i8* %51)
%56 = call i64 @send(i32 %34, i8* %51, i32 %55, i32 0)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %46
%59 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
br label %60
60: ; preds = %58, %46
%61 = call i64 @recv(i32 %34, i8* %6, i32 2000, i32 0)
%62 = icmp sgt i64 %61, -1
br i1 %62, label %63, label %81
63: ; preds = %60
%64 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
%65 = call i32 @puts(i8* %6)
%66 = call i8* @strstr(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
%67 = icmp eq i8* %66, null
%68 = getelementptr inbounds i8, i8* %66, i64 4
%69 = select i1 %67, i8* null, i8* %68
%70 = call i64 @strncmp(i8* %69, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i32 2)
%71 = icmp eq i64 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %63
%73 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.13, i64 0, i64 0))
%74 = call i32 @turnOn(i32 2)
br label %75
75: ; preds = %72, %63
%76 = call i64 @strncmp(i8* %69, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0), i32 3)
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %75
%79 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0))
%80 = call i32 @turnOff(i32 2)
br label %81
81: ; preds = %75, %78, %60
%82 = call i32 @close(i32 %34)
br label %31
83: ; preds = %17, %10
ret i32 0
}