#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 *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 = 0;
      while (reply_msg == 0) {
        reply_msg = recv_msg(recvbuf, 80);
        if (reply_msg == 0) {
          printf("two sensor read failed - retrying\n");
        }
      }
      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     141a <two_sensor_read+0x25a>
jmp    121c <two_sensor_read+0x5c>
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1080 <memset@plt>
movq   $0x0,-0xc8(%rbp)
cmpq   $0x0,-0xc8(%rbp)
jne    1281 <two_sensor_read+0xc1>
lea    -0xc0(%rbp),%rdi
mov    $0x50,%esi
call   1040 <recv_msg@plt>
mov    %rax,-0xc8(%rbp)
cmpq   $0x0,-0xc8(%rbp)
jne    127c <two_sensor_read+0xbc>
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    123a <two_sensor_read+0x7a>
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    13b7 <two_sensor_read+0x1f7>
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    1361 <two_sensor_read+0x1a1>
mov    -0xc8(%rbp),%rsi
lea    0xcdb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    142e <two_sensor_read+0x26e>
jmp    1366 <two_sensor_read+0x1a6>
mov    -0xd0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1390 <two_sensor_read+0x1d0>
mov    -0xd0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xd0(%rbp)
jmp    1366 <two_sensor_read+0x1a6>
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    142e <two_sensor_read+0x26e>
mov    -0xc8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x57,%eax
jne    13e8 <two_sensor_read+0x228>
mov    -0xc8(%rbp),%rsi
add    $0x2,%rsi
lea    0xc70(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1410 <two_sensor_read+0x250>
mov    -0xc8(%rbp),%rsi
lea    0xc63(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   10e0 <clear_input_stream@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    142e <two_sensor_read+0x26e>
jmp    1415 <two_sensor_read+0x255>
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    $0xb8,%rsp
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe0f(%rip),%rsi
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rdx
call   10e0 <sprintf@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   10b0 <send_msg@plt>
test   %rax,%rax
je     12d6 <two_sensor_read+0x106>
mov    %rbp,0x8(%rsp)
lea    0x60(%rsp),%r13
lea    0xe1e(%rip),%rbp
lea    0xdf5(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1090 <memset@plt>
mov    %r13,%rdi
mov    $0x50,%esi
call   1050 <recv_msg@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    128d <two_sensor_read+0xbd>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
mov    $0x50,%esi
call   1050 <recv_msg@plt>
test   %rax,%rax
je     1270 <two_sensor_read+0xa0>
mov    %rax,%rbx
mov    %r12,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r12,1)
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     12eb <two_sensor_read+0x11b>
cmpb   $0x57,(%rbx)
jne    1344 <two_sensor_read+0x174>
add    $0x2,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1240 <two_sensor_read+0x70>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   10a0 <two_sensor_read@plt>
mov    %eax,%ebx
jmp    1374 <two_sensor_read+0x1a4>
lea    0x10(%rsp),%rdi
call   1060 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rbp
add    $0x1,%rbp
mov    %rbp,%rdi
call   10c0 <atoi@plt>
mov    %eax,(%r15)
mov    %rbp,%rdi
mov    $0x20,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     135e <two_sensor_read+0x18e>
add    $0xffffffffffffffff,%rax
cmpb   $0x20,0x1(%rax)
lea    0x1(%rax),%rax
je     1320 <two_sensor_read+0x150>
mov    %rax,%rdi
call   10c0 <atoi@plt>
mov    0x8(%rsp),%rcx
mov    %eax,(%rcx)
xor    %ebx,%ebx
xor    %eax,%eax
call   10d0 <check_errors@plt>
jmp    1374 <two_sensor_read+0x1a4>
lea    0xceb(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
call   10f0 <clear_input_stream@plt>
jmp    136f <two_sensor_read+0x19f>
lea    0xca1(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0xb8,%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"two sensor read failed - retrying\0A\00"
@.str.2 = [35 x i8] c"got an incomplete response >>%s<<\0A\00"
@.str.3 = [13 x i8] c"Warning: %s\0A\00"
@.str.4 = [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 %94
20: ; preds = %3
br label %21
21: ; preds = %20, %93
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i32 0, i32 80)
store i8* null, i8** %10
br label %24
24: ; preds = %34, %21
%25 = load i8*, i8** %10
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %35
27: ; preds = %24
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%29 = call i8* @recv_msg(i8* %28, i32 80)
store i8* %29, i8** %10
%30 = load i8*, i8** %10
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
br label %24
35: ; preds = %24
%36 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%37 = call i32 @strlen(i8* %36)
%38 = sub nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 %39
store i8 0, i8* %40
%41 = load i8*, i8** %10
%42 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%43 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%44 = call i32 @strlen(i8* %43)
%45 = call i64 @strncmp(i8* %41, i8* %42, i32 %44)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %78
47: ; preds = %35
%48 = load i8*, i8** %10
%49 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
%53 = getelementptr inbounds i8, i8* %52, i64 1
store i8* %53, i8** %11
%54 = load i8*, i8** %11
%55 = call i32 @atoi(i8* %54)
%56 = load i32*, i32** %6
store i32 %55, i32* %56
%57 = load i8*, i8** %11
%58 = call i8* @strchr(i8* %57, i8 signext 32)
store i8* %58, i8** %11
%59 = load i8*, i8** %11
%60 = icmp eq i8* %59, null
br i1 %60, label %61, label %64
61: ; preds = %47
%62 = load i8*, i8** %10
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %62)
store i32 -1, i32* %4
br label %99
64: ; preds = %47
br label %65
65: ; preds = %70, %64
%66 = load i8*, i8** %11
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 32
br i1 %69, label %70, label %73
70: ; preds = %65
%71 = load i8*, i8** %11
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %11
br label %65
73: ; preds = %65
%74 = load i8*, i8** %11
%75 = call i32 @atoi(i8* %74)
%76 = load i32*, i32** %7
store i32 %75, i32* %76
%77 = call i32 (...) @check_errors()
store i32 0, i32* %4
br label %99
78: ; preds = %35
%79 = load i8*, i8** %10
%80 = getelementptr inbounds i8, i8* %79, i64 0
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = icmp eq i32 %82, 87
br i1 %83, label %84, label %88
84: ; preds = %78
%85 = load i8*, i8** %10
%86 = getelementptr inbounds i8, i8* %85, i64 2
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %86)
br label %92
88: ; preds = %78
%89 = load i8*, i8** %10
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %89)
%91 = call i32 (...) @clear_input_stream()
store i32 -1, i32* %4
br label %99
92: ; preds = %84
br label %93
93: ; preds = %92
br label %21
94: ; preds = %3
%95 = load i8*, i8** %5
%96 = load i32*, i32** %6
%97 = load i32*, i32** %7
%98 = call i32 @two_sensor_read(i8* %95, i32* %96, i32* %97)
store i32 %98, i32* %4
br label %99
99: ; preds = %94, %88, %73, %61
%100 = load i32, i32* %4
ret i32 %100
}

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