#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 */
typedef int /*<<< orphan*/ key;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int main() {
  int fd;
  fd = open("/dev/adc", O_RDWR, S_IRUSR | S_IWUSR);
  if (fd < 0) {
    perror("open");
    exit(1);
  }
  int key;
  while (1) {
    read(fd, (char *)&key, sizeof(key));
    printf("V = %dmv\n", key);
    sleep(1);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
mov    0x2e51(%rip),%rax
mov    (%rax),%edx
mov    0x2e58(%rip),%rax
or     (%rax),%edx
lea    0xe6f(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11b9 <main+0x59>
lea    0xe5f(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11be <main+0x5e>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
mov    -0xc(%rbp),%esi
lea    0xe35(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
jmp    11be <main+0x5e>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
mov    0x2e57(%rip),%rax
mov    0x2e60(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe75(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     11d7 <main+0x77>
mov    %eax,%ebx
lea    0xc(%rsp),%r14
lea    0xe6c(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <read@plt>
mov    0xc(%rsp),%esi
mov    %r15,%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
jmp    11b0 <main+0x50>
lea    0xe2b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/adc\00"
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [10 x i8] c"V = %dmv\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @S_IRUSR
%6 = load i32, i32* @S_IWUSR
%7 = or i32 %5, %6
%8 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
br label %15
15: ; preds = %14, %15
%16 = load i32, i32* %2
%17 = bitcast i32* %3 to i8*
%18 = call i32 @read(i32 %16, i8* %17, i32 4)
%19 = load i32, i32* %3
%20 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = call i32 @sleep(i32 1)
br label %15
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/adc\00"
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [10 x i8] c"V = %dmv\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @S_IRUSR
%4 = load i32, i32* @S_IWUSR
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = bitcast i32* %1 to i8*
br label %13
13: ; preds = %13, %11
%14 = call i32 @read(i32 %6, i8* %12, i32 4)
%15 = load i32, i32* %1
%16 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = tail call i32 @sleep(i32 1)
br label %13
}