#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 *);
int /*<<< orphan*/ printf(char *, int);
int read(int, char *, int);
int read_adc(int fd) {
  char buf[16];
  int res;
  if (fd < 0)
    return fd;
  res = read(fd, buf, 12);
  printf("%d\n", res);
  if (res < 5)
    return -1;
  buf[5] = 0;
  return atoi(buf + 2);
}


x86 assembly (clang, -O0):
<read_adc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1150 <read_adc+0x20>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119d <read_adc+0x6d>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1040 <read@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x5,-0x24(%rbp)
jge    1189 <read_adc+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    119d <read_adc+0x6d>
movb   $0x0,-0x1b(%rbp)
lea    -0x20(%rbp),%rdi
add    $0x2,%rdi
call   1050 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_adc>:
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
js     1171 <read_adc+0x41>
mov    %rsp,%rsi
mov    $0xc,%edx
call   1040 <read@plt>
mov    %eax,%ebx
lea    0xeb1(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
cmp    $0x5,%ebx
jl     1171 <read_adc+0x41>
movb   $0x0,0x5(%rsp)
lea    0x2(%rsp),%rdi
call   1050 <atoi@plt>
mov    %eax,%edi
mov    %edi,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @read_adc(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [16 x i8]
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load i32, i32* %3
store i32 %9, i32* %2
br label %24
10: ; preds = %1
%11 = load i32, i32* %3
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 5
br i1 %17, label %18, label %19
18: ; preds = %10
store i32 -1, i32* %2
br label %24
19: ; preds = %10
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 5
store i8 0, i8* %20
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%22 = getelementptr inbounds i8, i8* %21, i64 2
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %2
br label %24
24: ; preds = %19, %18, %8
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @read_adc(i32 %0) {
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%4 = icmp slt i32 %0, 0
br i1 %4, label %13, label %5
5: ; preds = %1
%6 = call i32 @read(i32 %0, i8* %3, i32 12)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp slt i32 %6, 5
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 5
store i8 0, i8* %10
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 2
%12 = call i32 @atoi(i8* %11)
br label %13
13: ; preds = %5, %1, %9
%14 = phi i32 [ %12, %9 ], [ %0, %1 ], [ -1, %5 ]
ret i32 %14
}