#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*/ printf(char *, ...);
int read(int, char *, int);
void read_test(int device) {
  char buf[2];
  printf("Reading 2 bytes from slave\n");
  if (read(device, buf, 2) != 2) {
    printf("could not read from slave\n");
    return;
  }
  printf("Read buf[0]%p, buf[1]%p\n", buf[0], buf[1]);
}


x86 assembly (clang, -O0):
<read_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x6(%rbp),%rsi
mov    $0x2,%edx
call   1040 <read@plt>
cmp    $0x2,%eax
je     1166 <read_test+0x46>
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    117c <read_test+0x5c>
movsbl -0x6(%rbp),%esi
movsbl -0x5(%rbp),%edx
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_test>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xedb(%rip),%rdi
call   1030 <puts@plt>
lea    0xe(%rsp),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1050 <read@plt>
cmp    $0x2,%eax
jne    1176 <read_test+0x46>
movsbl 0xe(%rsp),%esi
movsbl 0xf(%rsp),%edx
lea    0xe96(%rip),%rdi
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
jmp    1040 <printf@plt>
lea    0xeb7(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"Reading 2 bytes from slave\0A\00"
@.str.1 = [27 x i8] c"could not read from slave\0A\00"
@.str.2 = [25 x i8] c"Read buf[0]%p, buf[1]%p\0A\00"
define void @read_test(i32 %0) {
%2 = alloca i32
%3 = alloca [2 x i8]
store i32 %0, i32* %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* %2
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%7 = call i32 @read(i32 %5, i8* %6, i32 2)
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %19
11: ; preds = %1
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %17)
br label %19
19: ; preds = %11, %9
ret void
}

LLVM IR (-O2):
@.str.2 = [25 x i8] c"Read buf[0]%p, buf[1]%p\0A\00"
@str = [27 x i8] c"Reading 2 bytes from slave\00"
@str.3 = [26 x i8] c"could not read from slave\00"
define void @read_test(i32 %0) {
%2 = alloca [2 x i8]
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%5 = call i32 @read(i32 %0, i8* %3, i32 2)
%6 = icmp eq i32 %5, 2
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.3, i64 0, i64 0))
br label %16
9: ; preds = %1
%10 = load i8, i8* %3
%11 = sext i8 %10 to i32
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %11, i32 %14)
br label %16
16: ; preds = %9, %7
ret void
}