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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int http_request(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ udp_send(char *);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Usage ./main MD1AC44200003128\n");
    return EXIT_FAILURE;
  }
  int prev_value = 100;
  int recent_value = 1;
  FILE *stream;
  char request[1024], buf[1024], json[1024];
  stream = fopen("config.ini", "r");
  fread(buf, sizeof(char), sizeof(buf), stream);
  fclose(stream);
  printf("Bulb: %s\n", argv[1]);
  while (1) {
    sprintf(request, "https://io.adafruit.com/api/feeds/qstation?x-aio-key=%s",
            buf);
    recent_value = http_request(request);
    if (prev_value != 100 && recent_value != prev_value) {
      if (recent_value == 2) {
        printf("Turn bulb off.\n");
        sprintf(json,
                "{\"iswitch\":\"0\",\"r\":\"255\",\"g\":\"255\",\"b\":\"255\","
                "\"bright\":\"20\",\"cmd\":\"light_ctrl\",\"effect\":\"9\","
                "\"sn_list\":[{\"sn\":\"%s\"}]}",
                argv[1]);
        udp_send(json);
      } else if (recent_value == 3) {
        printf("Turn bulb on.\n");
        sprintf(json,
                "{\"iswitch\":\"1\",\"r\":\"255\",\"g\":\"255\",\"b\":\"255\","
                "\"bright\":\"20\",\"cmd\":\"light_ctrl\",\"effect\":\"9\","
                "\"sn_list\":[{\"sn\":\"%s\"}]}",
                argv[1]);
        udp_send(json);
      } else
        printf("ERROR: Unknown value.\n");
    }
    prev_value = recent_value;
    sleep(10);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c3 <main+0x43>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
add    $0xc20,%rsp
pop    %rbp
ret
movl   $0x64,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
lea    0xe47(%rip),%rdi
lea    0xe4b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x420(%rbp),%rdi
lea    -0x820(%rbp),%rdx
lea    0xe00(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x420(%rbp),%rdi
call   1060 <http_request@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x64,-0x14(%rbp)
je     1300 <main+0x180>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     1300 <main+0x180>
cmpl   $0x2,-0x18(%rbp)
jne    12a4 <main+0x124>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdf0(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0xc20(%rbp),%rdi
call   1080 <udp_send@plt>
jmp    12fb <main+0x17b>
cmpl   $0x3,-0x18(%rbp)
jne    12e8 <main+0x168>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe2f(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0xc20(%rbp),%rdi
call   1080 <udp_send@plt>
jmp    12f6 <main+0x176>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12fb <main+0x17b>
jmp    1300 <main+0x180>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0xa,%edi
call   10a0 <sleep@plt>
jmp    1221 <main+0xa1>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc18,%rsp
cmp    $0x1,%edi
jg     11cd <main+0x3d>
lea    0xfbd(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
add    $0xc18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsi,%rbp
lea    0xe29(%rip),%rdi
lea    0xe2d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0x410(%rsp),%r15
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %rbp,0x8(%rsp)
mov    0x8(%rbp),%rsi
lea    0xdf2(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x64,%ebp
lea    0xde9(%rip),%r12
lea    0x810(%rsp),%rbx
lea    0x10(%rsp),%r13
jmp    125d <main+0xcd>
lea    0xef3(%rip),%rdi
call   1030 <puts@plt>
nopl   0x0(%rax)
mov    $0xa,%edi
call   10b0 <sleep@plt>
mov    %r14d,%ebp
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <http_request@plt>
mov    %eax,%r14d
cmp    $0x64,%ebp
je     1250 <main+0xc0>
cmp    %ebp,%r14d
je     1250 <main+0xc0>
cmp    $0x3,%r14d
je     12ad <main+0x11d>
cmp    $0x2,%r14d
jne    123d <main+0xad>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rax
mov    0x8(%rax),%rdx
mov    %r13,%rdi
lea    0xda4(%rip),%rsi
jmp    12cc <main+0x13c>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rax
mov    0x8(%rax),%rdx
mov    %r13,%rdi
lea    0xdf7(%rip),%rsi
call   10a0 <sprintf@plt>
mov    %r13,%rdi
call   1090 <udp_send@plt>
jmp    1250 <main+0xc0>

LLVM IR (-O0):
@.str = [31 x i8] c"Usage ./main MD1AC44200003128\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [11 x i8] c"config.ini\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [10 x i8] c"Bulb: %s\0A\00"
@.str.4 = [56 x i8] c"https://io.adafruit.com/api/feeds/qstation?x-aio-key=%s\00"
@.str.5 = [16 x i8] c"Turn bulb off.\0A\00"
@.str.6 = [116 x i8] c"{\22iswitch\22:\220\22,\22r\22:\22255\22,\22g\22:\22255\22,\22b\22:\22255\22,\22bright\22:\2220\22,\22cmd\22:\22light_ctrl\22,\22effect\22:\229\22,\22sn_list\22:[{\22sn\22:\22%s\22}]}\00"
@.str.7 = [15 x i8] c"Turn bulb on.\0A\00"
@.str.8 = [116 x i8] c"{\22iswitch\22:\221\22,\22r\22:\22255\22,\22g\22:\22255\22,\22b\22:\22255\22,\22bright\22:\2220\22,\22cmd\22:\22light_ctrl\22,\22effect\22:\229\22,\22sn_list\22:[{\22sn\22:\22%s\22}]}\00"
@.str.9 = [23 x i8] c"ERROR: Unknown value.\0A\00"
@EXIT_SUCCESS = global i32 0
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 [1024 x i8]
%10 = alloca [1024 x i8]
%11 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
ret i32 %16
17: ; preds = %2
store i32 100, i32* %6
store i32 1, i32* %7
%18 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %8
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%20 = load i32*, i32** %8
%21 = call i32 @fread(i8* %19, i32 1, i32 1024, i32* %20)
%22 = load i32*, i32** %8
%23 = call i32 @fclose(i32* %22)
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %17, %68
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%33 = call i32 @http_request(i8* %32)
store i32 %33, i32* %7
%34 = load i32, i32* %6
%35 = icmp ne i32 %34, 100
br i1 %35, label %36, label %68
36: ; preds = %28
%37 = load i32, i32* %7
%38 = load i32, i32* %6
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %68
40: ; preds = %36
%41 = load i32, i32* %7
%42 = icmp eq i32 %41, 2
br i1 %42, label %43, label %52
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i32 @sprintf(i8* %45, i8* getelementptr inbounds ([116 x i8], [116 x i8]* @.str.6, i64 0, i64 0), i8* %48)
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%51 = call i32 @udp_send(i8* %50)
br label %67
52: ; preds = %40
%53 = load i32, i32* %7
%54 = icmp eq i32 %53, 3
br i1 %54, label %55, label %64
55: ; preds = %52
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 1
%60 = load i8*, i8** %59
%61 = call i32 @sprintf(i8* %57, i8* getelementptr inbounds ([116 x i8], [116 x i8]* @.str.8, i64 0, i64 0), i8* %60)
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%63 = call i32 @udp_send(i8* %62)
br label %66
64: ; preds = %52
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
br label %66
66: ; preds = %64, %55
br label %67
67: ; preds = %66, %43
br label %68
68: ; preds = %67, %36, %28
%69 = load i32, i32* %7
store i32 %69, i32* %6
%70 = call i32 @sleep(i32 10)
br label %28
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [11 x i8] c"config.ini\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [10 x i8] c"Bulb: %s\0A\00"
@.str.4 = [56 x i8] c"https://io.adafruit.com/api/feeds/qstation?x-aio-key=%s\00"
@.str.6 = [116 x i8] c"{\22iswitch\22:\220\22,\22r\22:\22255\22,\22g\22:\22255\22,\22b\22:\22255\22,\22bright\22:\2220\22,\22cmd\22:\22light_ctrl\22,\22effect\22:\229\22,\22sn_list\22:[{\22sn\22:\22%s\22}]}\00"
@.str.8 = [116 x i8] c"{\22iswitch\22:\221\22,\22r\22:\22255\22,\22g\22:\22255\22,\22b\22:\22255\22,\22bright\22:\2220\22,\22cmd\22:\22light_ctrl\22,\22effect\22:\229\22,\22sn_list\22:[{\22sn\22:\22%s\22}]}\00"
@EXIT_SUCCESS = global i32 0
@str = [22 x i8] c"ERROR: Unknown value.\00"
@str.10 = [14 x i8] c"Turn bulb on.\00"
@str.11 = [15 x i8] c"Turn bulb off.\00"
@str.12 = [30 x i8] c"Usage ./main MD1AC44200003128\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.12, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
ret i32 %9
10: ; preds = %2
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @fread(i8* %12, i32 1, i32 1024, i32* %14)
%16 = tail call i32 @fclose(i32* %14)
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %40, %10
%21 = phi i32 [ 100, %10 ], [ %23, %40 ]
%22 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i8* %12)
%23 = call i32 @http_request(i8* %11)
%24 = icmp eq i32 %21, 100
%25 = icmp eq i32 %23, %21
%26 = select i1 %24, i1 true, i1 %25
br i1 %26, label %40, label %27
27: ; preds = %20
switch i32 %23, label %38 [
i32 2, label %28
i32 3, label %33
]
28: ; preds = %27
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.11, i64 0, i64 0))
%30 = load i8*, i8** %17
%31 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([116 x i8], [116 x i8]* @.str.6, i64 0, i64 0), i8* %30)
%32 = call i32 @udp_send(i8* %13)
br label %40
33: ; preds = %27
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.10, i64 0, i64 0))
%35 = load i8*, i8** %17
%36 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([116 x i8], [116 x i8]* @.str.8, i64 0, i64 0), i8* %35)
%37 = call i32 @udp_send(i8* %13)
br label %40
38: ; preds = %27
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %40
40: ; preds = %28, %38, %33, %20
%41 = call i32 @sleep(i32 10)
br label %20
}