#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*/ close(int);
int /*<<< orphan*/ exit(int);
int ioctl(int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, unsigned char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char **argv) {
  int cmd;
  int ret;
  int fd;
  unsigned char buf[2];
  float result;
  fd = open("/dev/car0", 0);
  if (fd < 0) {
    fd = open("/dev/car", 0);
  }
  if (fd < 0) {
    perror("open device car");
    exit(1);
  }
  printf("input cmds:\n");
  while (1) {
    scanf("%c", &cmd);
    if (cmd == 'q')
      break;
    else if (cmd == 't') {
      read(fd, buf, 1);
      result = (float)buf[0];
      result /= 16;
      result += ((float)buf[1] * 16);
      printf("Current temperature %.1f `C\r\n", result);
    } else {
      ret = ioctl(fd, cmd);
      printf("ret=%d\n", ret);
    }
  };
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe67(%rip),%rdi
xor    %esi,%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11c2 <main+0x42>
lea    0xe56(%rip),%rdi
xor    %esi,%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11e2 <main+0x62>
lea    0xe44(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe3d(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <scanf@plt>
cmpl   $0x71,-0x14(%rbp)
jne    120f <main+0x8f>
jmp    12b4 <main+0x134>
cmpl   $0x74,-0x14(%rbp)
jne    128b <main+0x10b>
mov    -0x1c(%rbp),%edi
lea    -0x1e(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
movzbl -0x1e(%rbp),%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
movss  0xdbc(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movzbl -0x1d(%rbp),%eax
cvtsi2ss %eax,%xmm0
movss  -0x24(%rbp),%xmm1
movss  0xd9e(%rip),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdb8(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12aa <main+0x12a>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <ioctl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12af <main+0x12f>
jmp    11f0 <main+0x70>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe66(%rip),%rdi
xor    %esi,%esi
call   1090 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11c7 <main+0x37>
lea    0xe5c(%rip),%rdi
xor    %esi,%esi
call   1090 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1292 <main+0x102>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
lea    0xe51(%rip),%r14
lea    0x4(%rsp),%r15
lea    0x2(%rsp),%r12
lea    0xe43(%rip),%r13
lea    0xe5a(%rip),%rbp
jmp    124c <main+0xbc>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
movzbl 0x2(%rsp),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movzbl 0x3(%rsp),%eax
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
mulss  0xdd1(%rip),%xmm0
mulss  0xdcd(%rip),%xmm1
addss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
mov    %r13,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%esi
cmp    $0x74,%esi
je     1200 <main+0x70>
cmp    $0x71,%esi
je     127a <main+0xea>
mov    %ebx,%edi
call   1050 <ioctl@plt>
mov    %rbp,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    124c <main+0xbc>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd82(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/car0\00"
@.str.1 = [9 x i8] c"/dev/car\00"
@.str.2 = [16 x i8] c"open device car\00"
@.str.3 = [13 x i8] c"input cmds:\0A\00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [30 x i8] c"Current temperature %.1f `C\0D\0A\00"
@.str.6 = [8 x i8] c"ret=%d\0A\00"
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 [2 x i8]
%10 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32 %15, i32* %8
br label %16
16: ; preds = %14, %2
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %16
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %56
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %6)
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, 113
br i1 %27, label %28, label %29
28: ; preds = %24
br label %57
29: ; preds = %24
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, 116
br i1 %31, label %32, label %49
32: ; preds = %29
%33 = load i32, i32* %8
%34 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%35 = call i32 @read(i32 %33, i8* %34, i32 1)
%36 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%37 = load i8, i8* %36
%38 = uitofp i8 %37 to float
store float %38, float* %10
%39 = load float, float* %10
%40 = fdiv float %39, 1.600000e+01
store float %40, float* %10
%41 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 1
%42 = load i8, i8* %41
%43 = uitofp i8 %42 to float
%44 = load float, float* %10
%45 = call float @llvm.fmuladd.f32(float %43, float 1.600000e+01, float %44)
store float %45, float* %10
%46 = load float, float* %10
%47 = fpext float %46 to double
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), double %47)
br label %55
49: ; preds = %29
%50 = load i32, i32* %8
%51 = load i32, i32* %6
%52 = call i32 @ioctl(i32 %50, i32 %51)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %49, %32
br label %56
56: ; preds = %55
br label %24
57: ; preds = %28
%58 = load i32, i32* %8
%59 = call i32 @close(i32 %58)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/car0\00"
@.str.1 = [9 x i8] c"/dev/car\00"
@.str.2 = [16 x i8] c"open device car\00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [30 x i8] c"Current temperature %.1f `C\0D\0A\00"
@.str.6 = [8 x i8] c"ret=%d\0A\00"
@str = [12 x i8] c"input cmds:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [2 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 0)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2, %9
%16 = phi i32 [ %10, %9 ], [ %7, %2 ]
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
br label %19
19: ; preds = %32, %15
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%21 = load i32, i32* %3
switch i32 %21, label %33 [
i32 113, label %36
i32 116, label %22
]
22: ; preds = %19
%23 = call i32 @read(i32 %16, i8* %6, i32 1)
%24 = load i8, i8* %6
%25 = uitofp i8 %24 to float
%26 = fmul float %25, 6.250000e-02
%27 = load i8, i8* %18
%28 = uitofp i8 %27 to float
%29 = call float @llvm.fmuladd.f32(float %28, float 1.600000e+01, float %26)
%30 = fpext float %29 to double
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), double %30)
br label %32
32: ; preds = %22, %33
br label %19
33: ; preds = %19
%34 = call i32 @ioctl(i32 %16, i32 %21)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %34)
br label %32
36: ; preds = %19
%37 = call i32 @close(i32 %16)
ret i32 0
}