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

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int serialport_init(char *, int);
int /*<<< orphan*/ serialport_read_until(int, char *, char, int, int);
int /*<<< orphan*/ sscanf(char *, char *, float *, unsigned int *, float *);
unsigned int strlen(char *);
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  int fd = 0;
  char eolchar = '\n';
  int timeout = 6000;
  char buf[256];
  unsigned int counter = 0;
  unsigned int len = 0;
  float light = 0;
  float temperature = 0;
  unsigned int rain;
  fd = serialport_init(argv[1], 9600);
  if (fd != -1) {
    while (1) {
      serialport_read_until(fd, buf, eolchar, 256, timeout);
      len = strlen(buf);
      if (len > 1) {
        sscanf(buf, "[%f,%i,%f]", &temperature, &rain, &light);
        printf("=====%i time(s)=====\n", counter++);
        printf("TEMPERATURE > %2.1f\n", temperature);
        printf("RAIN        > %s\n", (rain ? "NO" : "YES"));
        printf("LIGHT (LUX) > %f\n", light);
        memset(buf, 0, 256);
      }
      usleep(100);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0xa,-0x15(%rbp)
movl   $0x1770,-0x1c(%rbp)
movl   $0x0,-0x124(%rbp)
movl   $0x0,-0x128(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x12c(%rbp)
ff
xorps  %xmm0,%xmm0
movss  %xmm0,-0x130(%rbp)
ff
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x2580,%esi
call   1030 <serialport_init@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     12ec <main+0x17c>
jmp    11e9 <main+0x79>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    -0x15(%rbp),%al
mov    -0x1c(%rbp),%r8d
mov    $0x100,%ecx
movsbl %al,%edx
call   1040 <serialport_read_until@plt>
lea    -0x120(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x128(%rbp)
cmpl   $0x1,-0x128(%rbp)
jbe    12dd <main+0x16d>
lea    -0x120(%rbp),%rdi
lea    0xdcc(%rip),%rsi
lea    -0x130(%rbp),%rdx
lea    -0x134(%rbp),%rcx
lea    -0x12c(%rbp),%r8
call   1080 <sscanf@plt>
mov    -0x124(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movss  -0x130(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
lea    0xda1(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x134(%rbp),%ecx
lea    0xdb7(%rip),%rsi
lea    0xdad(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movss  -0x12c(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
lea    0xd8c(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    $0x64,%edi
call   1090 <usleep@plt>
jmp    11e9 <main+0x79>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
mov    0x8(%rsi),%rdi
mov    $0x2580,%esi
call   1030 <serialport_init@plt>
cmp    $0xffffffff,%eax
je     1298 <main+0x128>
mov    %eax,%ebp
lea    0x10(%rsp),%rbx
lea    0xe80(%rip),%r12
lea    0xe92(%rip),%r13
xor    %r14d,%r14d
jmp    11da <main+0x6a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x64,%edi
call   1090 <usleep@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xa,%edx
mov    $0x100,%ecx
mov    $0x1770,%r8d
call   1040 <serialport_read_until@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jb     11d0 <main+0x60>
mov    %rbx,%rdi
lea    0xdf5(%rip),%rsi
lea    0x4(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
call   1080 <sscanf@plt>
lea    0x1(%r14),%r15d
lea    0xde1(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xddc(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
cmpl   $0x0,0xc(%rsp)
lea    0xdf0(%rip),%rsi
lea    0xdec(%rip),%rax
cmove  %rax,%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r13,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    %r15d,%r14d
jmp    11d0 <main+0x60>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"[%f,%i,%f]\00"
@.str.1 = [22 x i8] c"=====%i time(s)=====\0A\00"
@.str.2 = [21 x i8] c"TEMPERATURE > %2.1f\0A\00"
@.str.3 = [18 x i8] c"RAIN > %s\0A\00"
@.str.4 = [3 x i8] c"NO\00"
@.str.5 = [4 x i8] c"YES\00"
@.str.6 = [18 x i8] c"LIGHT (LUX) > %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
%9 = alloca [256 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca float
%13 = alloca float
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i8 10, i8* %7
store i32 6000, i32* %8
store i32 0, i32* %10
store i32 0, i32* %11
store float 0.000000e+00, float* %12
store float 0.000000e+00, float* %13
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @serialport_init(i8* %17, i32 9600)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %53
21: ; preds = %2
br label %22
22: ; preds = %21, %51
%23 = load i32, i32* %6
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%25 = load i8, i8* %7
%26 = load i32, i32* %8
%27 = call i32 @serialport_read_until(i32 %23, i8* %24, i8 signext %25, i32 256, i32 %26)
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
store i32 %29, i32* %11
%30 = load i32, i32* %11
%31 = icmp ugt i32 %30, 1
br i1 %31, label %32, label %51
32: ; preds = %22
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%34 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), float* %13, i32* %14, float* %12)
%35 = load i32, i32* %10
%36 = add i32 %35, 1
store i32 %36, i32* %10
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%38 = load float, float* %13
%39 = fpext float %38 to double
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), double %39)
%41 = load i32, i32* %14
%42 = icmp ne i32 %41, 0
%43 = zext i1 %42 to i64
%44 = select i1 %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %44)
%46 = load float, float* %12
%47 = fpext float %46 to double
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), double %47)
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%50 = call i32 @memset(i8* %49, i32 0, i32 256)
br label %51
51: ; preds = %32, %22
%52 = call i32 @usleep(i32 100)
br label %22
53: ; preds = %2
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"[%f,%i,%f]\00"
@.str.1 = [22 x i8] c"=====%i time(s)=====\0A\00"
@.str.2 = [21 x i8] c"TEMPERATURE > %2.1f\0A\00"
@.str.3 = [18 x i8] c"RAIN > %s\0A\00"
@.str.4 = [3 x i8] c"NO\00"
@.str.5 = [4 x i8] c"YES\00"
@.str.6 = [18 x i8] c"LIGHT (LUX) > %f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca float
%5 = alloca float
%6 = alloca i32
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = bitcast float* %4 to i8*
store float 0.000000e+00, float* %4
%9 = bitcast float* %5 to i8*
store float 0.000000e+00, float* %5
%10 = bitcast i32* %6 to i8*
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @serialport_init(i8* %12, i32 9600)
%14 = icmp eq i32 %13, -1
br i1 %14, label %38, label %15
15: ; preds = %2, %35
%16 = phi i32 [ %36, %35 ], [ 0, %2 ]
%17 = call i32 @serialport_read_until(i32 %13, i8* %7, i8 signext 10, i32 256, i32 6000)
%18 = call i32 @strlen(i8* %7)
%19 = icmp ugt i32 %18, 1
br i1 %19, label %20, label %35
20: ; preds = %15
%21 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), float* %5, i32* %6, float* %4)
%22 = add i32 %16, 1
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%24 = load float, float* %5
%25 = fpext float %24 to double
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), double %25)
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, 0
%29 = select i1 %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = load float, float* %4
%32 = fpext float %31 to double
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), double %32)
%34 = call i32 @memset(i8* %7, i32 0, i32 256)
br label %35
35: ; preds = %20, %15
%36 = phi i32 [ %22, %20 ], [ %16, %15 ]
%37 = call i32 @usleep(i32 100)
br label %15
38: ; preds = %2
ret i32 0
}