#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 */
struct timeval {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int rs232_read(int, char *, int);
int rs232_send(int, char *, int);
int sscanf(char *, char *, int *, int *);
int update_oven(int fd, int lamp, int fan, int *t1, int *t2,
                struct timeval *tv) {
  char buf = '0' + (lamp ? 1 : 0) + (fan ? 2 : 0);
  char rxbuf[16];
  int i;
  int res = rs232_send(fd, &buf, 1);
  gettimeofday(tv, NULL);
  res = rs232_read(fd, rxbuf, 9);
  rxbuf[9] = 0;
  res = sscanf(rxbuf, "%3d %3d", t1, t2);
  if (res < 2)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<update_oven>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0xc(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    $0x30,%eax
mov    -0x10(%rbp),%esi
xor    %ecx,%ecx
mov    $0x2,%edx
cmp    $0x0,%esi
cmovne %edx,%ecx
add    %ecx,%eax
mov    %al,-0x29(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
call   1030 <rs232_send@plt>
mov    %eax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x9,%edx
call   1050 <rs232_read@plt>
mov    %eax,-0x48(%rbp)
movb   $0x0,-0x37(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe2f(%rip),%rsi
call   1060 <sscanf@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x2,-0x48(%rbp)
jge    11ef <update_oven+0xaf>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <update_oven+0xb6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_oven>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %r9,%rbx
mov    %r8,%r14
mov    %rcx,%r15
mov    %edi,%ebp
test   %edx,%edx
setne  %al
add    %al,%al
cmp    $0x1,%esi
sbb    $0x0,%al
add    $0x31,%al
mov    %al,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1030 <rs232_send@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0x10(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x9,%edx
call   1050 <rs232_read@plt>
movb   $0x0,0x19(%rsp)
lea    0xe60(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1060 <sscanf@plt>
xor    %ecx,%ecx
cmp    $0x2,%eax
setl   %cl
neg    %ecx
mov    %ecx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@.str = [8 x i8] c"%3d %3d\00"
define i32 @update_oven(i32 %0, i32 %1, i32 %2, i32* %3, i32* %4, %struct.timeval* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca %struct.timeval*
%14 = alloca i8
%15 = alloca [16 x i8]
%16 = alloca i32
%17 = alloca i32
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32* %3, i32** %11
store i32* %4, i32** %12
store %struct.timeval* %5, %struct.timeval** %13
%18 = load i32, i32* %9
%19 = icmp ne i32 %18, 0
%20 = zext i1 %19 to i64
%21 = select i1 %19, i32 1, i32 0
%22 = add nsw i32 48, %21
%23 = load i32, i32* %10
%24 = icmp ne i32 %23, 0
%25 = zext i1 %24 to i64
%26 = select i1 %24, i32 2, i32 0
%27 = add nsw i32 %22, %26
%28 = trunc i32 %27 to i8
store i8 %28, i8* %14
%29 = load i32, i32* %8
%30 = call i32 @rs232_send(i32 %29, i8* %14, i32 1)
store i32 %30, i32* %17
%31 = load %struct.timeval*, %struct.timeval** %13
%32 = call i32 @gettimeofday(%struct.timeval* %31, i32* null)
%33 = load i32, i32* %8
%34 = getelementptr inbounds [16 x i8], [16 x i8]* %15, i64 0, i64 0
%35 = call i32 @rs232_read(i32 %33, i8* %34, i32 9)
store i32 %35, i32* %17
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %15, i64 0, i64 9
store i8 0, i8* %36
%37 = getelementptr inbounds [16 x i8], [16 x i8]* %15, i64 0, i64 0
%38 = load i32*, i32** %11
%39 = load i32*, i32** %12
%40 = call i32 @sscanf(i8* %37, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %38, i32* %39)
store i32 %40, i32* %17
%41 = load i32, i32* %17
%42 = icmp slt i32 %41, 2
br i1 %42, label %43, label %44
43: ; preds = %6
store i32 -1, i32* %7
br label %45
44: ; preds = %6
store i32 0, i32* %7
br label %45
45: ; preds = %44, %43
%46 = load i32, i32* %7
ret i32 %46
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@.str = [8 x i8] c"%3d %3d\00"
define i32 @update_oven(i32 %0, i32 %1, i32 %2, i32* %3, i32* %4, %struct.timeval* nocapture %5) {
%7 = alloca i8
%8 = alloca [16 x i8]
%9 = icmp eq i32 %1, 0
%10 = select i1 %9, i8 48, i8 49
%11 = icmp eq i32 %2, 0
%12 = select i1 %11, i8 0, i8 2
%13 = or i8 %12, %10
store i8 %13, i8* %7
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%15 = call i32 @rs232_send(i32 %0, i8* %7, i32 1)
%16 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%17 = call i32 @rs232_read(i32 %0, i8* %14, i32 9)
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 9
store i8 0, i8* %18
%19 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4)
%20 = icmp slt i32 %19, 2
%21 = sext i1 %20 to i32
ret i32 %21
}