#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 atoi(char const *);
int /*<<< orphan*/ check_errors();
int /*<<< orphan*/ clear_input_stream();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char const *);
char *recv_msg(char *, int);
scalar_t__ send_msg(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
char *strchr(char const *, char);
int strlen(char *);
scalar_t__ strncmp(char const *, char *, int);
int two_sensor_read(char *sensornames, int *value1, int *value2) {
  char sendbuf[80];
  char recvbuf[80];
  const char *reply_msg;
  const char *arg;
  sprintf(sendbuf, "S %s\n", sensornames);
  if (send_msg(sendbuf, strlen(sendbuf))) {
    while (1) {
      memset(recvbuf, 0, 80);
      reply_msg = recv_msg(recvbuf, 80);
      sendbuf[strlen(sendbuf) - 1] = '\0';
      if (strncmp(reply_msg, sendbuf, strlen(sendbuf)) == 0) {
        arg = reply_msg + strlen(sendbuf) + 1;
        *value1 = atoi(arg);
        arg = strchr(arg, ' ');
        if (arg == NULL) {
          printf("got an incomplete response >>%s<<\n", reply_msg);
          return -1;
        }
        while (*arg == ' ')
          arg++;
        *value2 = atoi(arg);
        check_errors();
        return 0;
      } else if (reply_msg[0] == 'W') {
        printf("Warning: %s\n", reply_msg + 2);
      } else {
        printf("got an error >>%s<<\n", reply_msg);
        clear_input_stream();
        return -1;
      }
    }
  } else {
    return two_sensor_read(sensornames, value1, value2);
  }
}


x86 assembly (clang, -O0):
<two_sensor_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe1a(%rip),%rsi
call   10d0 <sprintf@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xd8(%rbp),%rdi
mov    %eax,%esi
call   10a0 <send_msg@plt>
cmp    $0x0,%rax
je     13da <two_sensor_read+0x21a>
jmp    121c <two_sensor_read+0x5c>
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1080 <memset@plt>
lea    -0xc0(%rbp),%rdi
mov    $0x50,%esi
call   1040 <recv_msg@plt>
mov    %rax,-0xc8(%rbp)
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x70(%rbp,%rax,1)
mov    -0xc8(%rbp),%rax
mov    %rax,-0xe8(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0xe0(%rbp)
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xe8(%rbp),%rdi
mov    -0xe0(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    137b <two_sensor_read+0x1bb>
mov    -0xc8(%rbp),%rax
mov    %rax,-0xf0(%rbp)
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0xf0(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0xd0(%rbp)
mov    -0xd0(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xd0(%rbp),%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
mov    %rax,-0xd0(%rbp)
cmpq   $0x0,-0xd0(%rbp)
jne    1325 <two_sensor_read+0x165>
mov    -0xc8(%rbp),%rsi
lea    0xcf2(%rip),%rdi
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ee <two_sensor_read+0x22e>
jmp    132a <two_sensor_read+0x16a>
mov    -0xd0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1354 <two_sensor_read+0x194>
mov    -0xd0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xd0(%rbp)
jmp    132a <two_sensor_read+0x16a>
mov    -0xd0(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x0,%al
call   10c0 <check_errors@plt>
movl   $0x0,-0x4(%rbp)
jmp    13ee <two_sensor_read+0x22e>
mov    -0xc8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x57,%eax
jne    13aa <two_sensor_read+0x1ea>
mov    -0xc8(%rbp),%rsi
add    $0x2,%rsi
lea    0xc89(%rip),%rdi
call   1070 <printf@plt>
jmp    13d0 <two_sensor_read+0x210>
mov    -0xc8(%rbp),%rsi
lea    0xc7e(%rip),%rdi
call   1070 <printf@plt>
mov    $0x0,%al
call   10e0 <clear_input_stream@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ee <two_sensor_read+0x22e>
jmp    13d5 <two_sensor_read+0x215>
jmp    121c <two_sensor_read+0x5c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1090 <two_sensor_read@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<two_sensor_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe1f(%rip),%rsi
mov    %rsp,%r12
mov    %r12,%rdi
mov    %rbx,%rdx
call   10d0 <sprintf@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   10a0 <send_msg@plt>
test   %rax,%rax
je     1283 <two_sensor_read+0xc3>
lea    0x50(%rsp),%r13
lea    0xe17(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1080 <memset@plt>
mov    %r13,%rdi
mov    $0x50,%esi
call   1040 <recv_msg@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r12,1)
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1298 <two_sensor_read+0xd8>
cmpb   $0x57,(%rbx)
jne    12f0 <two_sensor_read+0x130>
add    $0x2,%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
jmp    1220 <two_sensor_read+0x60>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1090 <two_sensor_read@plt>
mov    %eax,%ebx
jmp    131c <two_sensor_read+0x15c>
mov    %rsp,%rdi
call   1050 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rbp
add    $0x1,%rbp
mov    %rbp,%rdi
call   10b0 <atoi@plt>
mov    %eax,(%r15)
mov    %rbp,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1308 <two_sensor_read+0x148>
add    $0xffffffffffffffff,%rax
nopl   0x0(%rax,%rax,1)
cmpb   $0x20,0x1(%rax)
lea    0x1(%rax),%rax
je     12d0 <two_sensor_read+0x110>
mov    %rax,%rdi
call   10b0 <atoi@plt>
mov    %eax,(%r14)
xor    %ebx,%ebx
xor    %eax,%eax
call   10c0 <check_errors@plt>
jmp    131c <two_sensor_read+0x15c>
lea    0xd3f(%rip),%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
xor    %eax,%eax
call   10e0 <clear_input_stream@plt>
jmp    1317 <two_sensor_read+0x157>
lea    0xcf7(%rip),%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"S %s\0A\00"
@.str.1 = [35 x i8] c"got an incomplete response >>%s<<\0A\00"
@.str.2 = [13 x i8] c"Warning: %s\0A\00"
@.str.3 = [21 x i8] c"got an error >>%s<<\0A\00"
define i32 @two_sensor_read(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [80 x i8]
%9 = alloca [80 x i8]
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%13 = load i8*, i8** %5
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
%18 = call i64 @send_msg(i8* %15, i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %84
20: ; preds = %3
br label %21
21: ; preds = %20, %83
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i32 0, i32 80)
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%25 = call i8* @recv_msg(i8* %24, i32 80)
store i8* %25, i8** %10
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 %29
store i8 0, i8* %30
%31 = load i8*, i8** %10
%32 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = call i64 @strncmp(i8* %31, i8* %32, i32 %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %68
37: ; preds = %21
%38 = load i8*, i8** %10
%39 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %38, i64 %41
%43 = getelementptr inbounds i8, i8* %42, i64 1
store i8* %43, i8** %11
%44 = load i8*, i8** %11
%45 = call i32 @atoi(i8* %44)
%46 = load i32*, i32** %6
store i32 %45, i32* %46
%47 = load i8*, i8** %11
%48 = call i8* @strchr(i8* %47, i8 signext 32)
store i8* %48, i8** %11
%49 = load i8*, i8** %11
%50 = icmp eq i8* %49, null
br i1 %50, label %51, label %54
51: ; preds = %37
%52 = load i8*, i8** %10
%53 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %52)
store i32 -1, i32* %4
br label %89
54: ; preds = %37
br label %55
55: ; preds = %60, %54
%56 = load i8*, i8** %11
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 32
br i1 %59, label %60, label %63
60: ; preds = %55
%61 = load i8*, i8** %11
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %11
br label %55
63: ; preds = %55
%64 = load i8*, i8** %11
%65 = call i32 @atoi(i8* %64)
%66 = load i32*, i32** %7
store i32 %65, i32* %66
%67 = call i32 (...) @check_errors()
store i32 0, i32* %4
br label %89
68: ; preds = %21
%69 = load i8*, i8** %10
%70 = getelementptr inbounds i8, i8* %69, i64 0
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 87
br i1 %73, label %74, label %78
74: ; preds = %68
%75 = load i8*, i8** %10
%76 = getelementptr inbounds i8, i8* %75, i64 2
%77 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %76)
br label %82
78: ; preds = %68
%79 = load i8*, i8** %10
%80 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %79)
%81 = call i32 (...) @clear_input_stream()
store i32 -1, i32* %4
br label %89
82: ; preds = %74
br label %83
83: ; preds = %82
br label %21
84: ; preds = %3
%85 = load i8*, i8** %5
%86 = load i32*, i32** %6
%87 = load i32*, i32** %7
%88 = call i32 @two_sensor_read(i8* %85, i32* %86, i32* %87)
store i32 %88, i32* %4
br label %89
89: ; preds = %84, %78, %63, %51
%90 = load i32, i32* %4
ret i32 %90
}

LLVM IR (-O2):
@.str = [6 x i8] c"S %s\0A\00"
@.str.1 = [35 x i8] c"got an incomplete response >>%s<<\0A\00"
@.str.2 = [13 x i8] c"Warning: %s\0A\00"
@.str.3 = [21 x i8] c"got an error >>%s<<\0A\00"
define i32 @two_sensor_read(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca [80 x i8]
%5 = alloca [80 x i8]
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%8 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = call i32 @strlen(i8* %6)
%10 = call i64 @send_msg(i8* %6, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %49, label %12
12: ; preds = %3, %43
%13 = call i32 @memset(i8* %7, i32 0, i32 80)
%14 = call i8* @recv_msg(i8* %7, i32 80)
%15 = call i32 @strlen(i8* %6)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32 @strlen(i8* %6)
%20 = call i64 @strncmp(i8* %14, i8* %6, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %40
22: ; preds = %12
%23 = call i32 @strlen(i8* %6)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %14, i64 %24
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %1
%28 = call i8* @strchr(i8* %26, i8 signext 32)
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %32
30: ; preds = %22
%31 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %51
32: ; preds = %22, %32
%33 = phi i8* [ %36, %32 ], [ %28, %22 ]
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 32
%36 = getelementptr inbounds i8, i8* %33, i64 1
br i1 %35, label %32, label %37
37: ; preds = %32
%38 = call i32 @atoi(i8* %33)
store i32 %38, i32* %2
%39 = call i32 (...) @check_errors()
br label %51
40: ; preds = %12
%41 = load i8, i8* %14
%42 = icmp eq i8 %41, 87
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = getelementptr inbounds i8, i8* %14, i64 2
%45 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %44)
br label %12
46: ; preds = %40
%47 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %14)
%48 = call i32 (...) @clear_input_stream()
br label %51
49: ; preds = %3
%50 = call i32 @two_sensor_read(i8* %0, i32* %1, i32* %2)
br label %51
51: ; preds = %49, %46, %37, %30
%52 = phi i32 [ -1, %30 ], [ 0, %37 ], [ -1, %46 ], [ %50, %49 ]
ret i32 %52
}