#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 uint8_t;

/* Variables and functions */
int i2c_read(int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ log_message(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usleep(int);
bool rfid_pn532_read_data(uint8_t *buf, uint8_t n) {
  int rawlen = (int)n + 2;
  uint8_t raw[rawlen];
  int read = 0;
  int r = 0;
  usleep(2000);
  while (read != rawlen) {
    r = i2c_read(0, raw + read, rawlen);
    if (r == -1) {
      log_message("[DEBUG][%d-%d-%d %d:%d:%d] ",
                  "Got error while reading from the I2C bus\r\n");
      return false;
    }
    read += r;
  }
  log_message("[DEBUG][%d-%d-%d %d:%d:%d] ", "rfid_pn532_read_data: [ ");
  for (int i = 0; i < n; ++i) {
    buf[i] = raw[i + 1];
    printf("%02x ", buf[i]);
  }
  printf("]\r\n");
  return true;
}


x86 assembly (clang, -O0):
<rfid_pn532_read_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    $0x7d0,%edi
call   1060 <usleep@plt>
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     11fd <rfid_pn532_read_data+0xbd>
mov    -0x40(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
xor    %edi,%edi
call   1030 <i2c_read@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    11ef <rfid_pn532_read_data+0xaf>
lea    0xe30(%rip),%rdi
lea    0xe45(%rip),%rsi
call   1050 <log_message@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1281 <rfid_pn532_read_data+0x141>
mov    -0x30(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1197 <rfid_pn532_read_data+0x57>
lea    0xdfc(%rip),%rdi
lea    0xe3c(%rip),%rsi
call   1050 <log_message@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1265 <rfid_pn532_read_data+0x125>
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1217 <rfid_pn532_read_data+0xd7>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rfid_pn532_read_data>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x2(%r14),%r13d
mov    %rsp,%r12
lea    0xf(,%r13,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    $0x7d0,%edi
call   1070 <usleep@plt>
test   %r13d,%r13d
je     1201 <rfid_pn532_read_data+0xb1>
xor    %ebx,%ebx
xchg   %ax,%ax
movslq %ebx,%rax
lea    (%r12,%rax,4),%rsi
xor    %edi,%edi
mov    %r13d,%edx
call   1030 <i2c_read@plt>
cmp    $0xffffffff,%eax
je     1227 <rfid_pn532_read_data+0xd7>
add    %eax,%ebx
cmp    %r13d,%ebx
jne    1190 <rfid_pn532_read_data+0x40>
lea    0xe48(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1060 <log_message@plt>
test   %r14d,%r14d
jle    1214 <rfid_pn532_read_data+0xc4>
mov    %r14d,%r13d
lea    0xe8d(%rip),%r14
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x1(%rax),%rbx
mov    0x4(%r12,%rax,4),%esi
mov    %esi,(%r15,%rax,4)
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rax
cmp    %rbx,%r13
jne    11e0 <rfid_pn532_read_data+0x90>
jmp    1214 <rfid_pn532_read_data+0xc4>
lea    0xdf8(%rip),%rdi
lea    0xe38(%rip),%rsi
call   1060 <log_message@plt>
lea    0xe4b(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    123c <rfid_pn532_read_data+0xec>
lea    0xdd2(%rip),%rdi
lea    0xde7(%rip),%rsi
call   1060 <log_message@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"[DEBUG][%d-%d-%d %d:%d:%d] \00"
@.str.1 = [43 x i8] c"Got error while reading from the I2C bus\0D\0A\00"
@.str.2 = [25 x i8] c"rfid_pn532_read_data: [ \00"
@.str.3 = [6 x i8] c"%02x \00"
@.str.4 = [4 x i8] c"]\0D\0A\00"
define i32 @rfid_pn532_read_data(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%13 = load i32, i32* %5
%14 = add nsw i32 %13, 2
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %7
%18 = alloca i32, i64 %16
store i64 %16, i64* %8
store i32 0, i32* %9
store i32 0, i32* %10
%19 = call i32 @usleep(i32 2000)
br label %20
20: ; preds = %34, %2
%21 = load i32, i32* %9
%22 = load i32, i32* %6
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %38
24: ; preds = %20
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %18, i64 %26
%28 = load i32, i32* %6
%29 = call i32 @i2c_read(i32 0, i32* %27, i32 %28)
store i32 %29, i32* %10
%30 = load i32, i32* %10
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %24
%33 = call i32 @log_message(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
store i32 1, i32* %11
br label %65
34: ; preds = %24
%35 = load i32, i32* %10
%36 = load i32, i32* %9
%37 = add nsw i32 %36, %35
store i32 %37, i32* %9
br label %20
38: ; preds = %20
%39 = call i32 @log_message(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %12
br label %40
40: ; preds = %60, %38
%41 = load i32, i32* %12
%42 = load i32, i32* %5
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %63
44: ; preds = %40
%45 = load i32, i32* %12
%46 = add nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %18, i64 %47
%49 = load i32, i32* %48
%50 = load i32*, i32** %4
%51 = load i32, i32* %12
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %50, i64 %52
store i32 %49, i32* %53
%54 = load i32*, i32** %4
%55 = load i32, i32* %12
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
%58 = load i32, i32* %57
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %44
%61 = load i32, i32* %12
%62 = add nsw i32 %61, 1
store i32 %62, i32* %12
br label %40
63: ; preds = %40
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %11
br label %65
65: ; preds = %63, %32
%66 = load i8*, i8** %7
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str = [28 x i8] c"[DEBUG][%d-%d-%d %d:%d:%d] \00"
@.str.1 = [43 x i8] c"Got error while reading from the I2C bus\0D\0A\00"
@.str.2 = [25 x i8] c"rfid_pn532_read_data: [ \00"
@.str.3 = [6 x i8] c"%02x \00"
@str = [3 x i8] c"]\0D\00"
define i32 @rfid_pn532_read_data(i32* nocapture writeonly %0, i32 %1) {
%3 = add nsw i32 %1, 2
%4 = zext i32 %3 to i64
%5 = alloca i32, i64 %4
%6 = tail call i32 @usleep(i32 2000)
%7 = icmp eq i32 %3, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = call i32 @log_message(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %26
10: ; preds = %12
%11 = icmp eq i32 %18, %3
br i1 %11, label %21, label %12
12: ; preds = %2, %10
%13 = phi i32 [ %18, %10 ], [ 0, %2 ]
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %5, i64 %14
%16 = call i32 @i2c_read(i32 0, i32* %15, i32 %3)
%17 = icmp eq i32 %16, -1
%18 = add nsw i32 %16, %13
br i1 %17, label %19, label %10
19: ; preds = %12
%20 = call i32 @log_message(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %36
21: ; preds = %10
%22 = call i32 @log_message(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp sgt i32 %1, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = zext i32 %1 to i64
br label %28
26: ; preds = %28, %8, %21
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %36
28: ; preds = %24, %28
%29 = phi i64 [ 0, %24 ], [ %30, %28 ]
%30 = add nuw nsw i64 %29, 1
%31 = getelementptr inbounds i32, i32* %5, i64 %30
%32 = load i32, i32* %31
%33 = getelementptr inbounds i32, i32* %0, i64 %29
store i32 %32, i32* %33
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%35 = icmp eq i64 %30, %25
br i1 %35, label %26, label %28
36: ; preds = %26, %19
%37 = phi i32 [ 0, %19 ], [ 1, %26 ]
ret i32 %37
}