#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*/ I2C_SLAVE_FORCE;
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int, char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int checkSlave(int fd, char *fn, int adr) {
  ioctl(fd, I2C_SLAVE_FORCE, adr);
  float data;
  char regCHECK[1] = {0x04};
  char bufferCHECK[1] = {0};
  write(fd, regCHECK, 1);
  read(fd, bufferCHECK, 1);
  if (!((int)bufferCHECK[0] == 0))
    printf("Detected PlainDAC+/DSP with address 0x%02x at %s!\n", adr, fn);
  else
    printf("No PlainDAC+/DSP with address 0x%02x at %s!\n", adr, fn);
  return (int)bufferCHECK[0];
}


x86 assembly (clang, -O0):
<checkSlave>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
call   1060 <ioctl@plt>
mov    0xe84(%rip),%al
mov    %al,-0x19(%rbp)
lea    -0x1a(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0x1a(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
movsbl -0x1a(%rbp),%eax
cmp    $0x0,%eax
je     11d6 <checkSlave+0x86>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xe35(%rip),%rdi
call   1040 <printf@plt>
jmp    11e9 <checkSlave+0x99>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
movsbl -0x1a(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkSlave>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
call   1050 <ioctl@plt>
movb   $0x4,0xf(%rsp)
movb   $0x0,0xe(%rsp)
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
lea    0xe(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <read@plt>
movsbl 0xe(%rsp),%ebx
test   %ebx,%ebx
lea    0xe9c(%rip),%rax
lea    0xe62(%rip),%rdi
cmove  %rax,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@I2C_SLAVE_FORCE = global i32 0
@__const.checkSlave.regCHECK = [1 x i8] c"\04"
@.str = [51 x i8] c"Detected PlainDAC+/DSP with address 0x%02x at %s!\0A\00"
@.str.1 = [45 x i8] c"No PlainDAC+/DSP with address 0x%02x at %s!\0A\00"
define i32 @checkSlave(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca float
%8 = alloca [1 x i8]
%9 = alloca [1 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i32, i32* %4
%11 = load i32, i32* @I2C_SLAVE_FORCE
%12 = load i32, i32* %6
%13 = call i32 @ioctl(i32 %10, i32 %11, i32 %12)
%14 = bitcast [1 x i8]* %8 to i8*
%15 = bitcast [1 x i8]* %9 to i8*
%16 = load i32, i32* %4
%17 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%18 = call i32 @write(i32 %16, i8* %17, i32 1)
%19 = load i32, i32* %4
%20 = getelementptr inbounds [1 x i8], [1 x i8]* %9, i64 0, i64 0
%21 = call i32 @read(i32 %19, i8* %20, i32 1)
%22 = getelementptr inbounds [1 x i8], [1 x i8]* %9, i64 0, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %3
%27 = load i32, i32* %6
%28 = load i8*, i8** %5
%29 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %27, i8* %28)
br label %34
30: ; preds = %3
%31 = load i32, i32* %6
%32 = load i8*, i8** %5
%33 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %31, i8* %32)
br label %34
34: ; preds = %30, %26
%35 = getelementptr inbounds [1 x i8], [1 x i8]* %9, i64 0, i64 0
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
ret i32 %37
}

LLVM IR (-O2):
@I2C_SLAVE_FORCE = global i32 0
@.str = [51 x i8] c"Detected PlainDAC+/DSP with address 0x%02x at %s!\0A\00"
@.str.1 = [45 x i8] c"No PlainDAC+/DSP with address 0x%02x at %s!\0A\00"
define i32 @checkSlave(i32 %0, i8* %1, i32 %2) {
%4 = alloca [1 x i8]
%5 = alloca [1 x i8]
%6 = load i32, i32* @I2C_SLAVE_FORCE
%7 = tail call i32 @ioctl(i32 %0, i32 %6, i32 %2)
%8 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
store i8 4, i8* %8
%9 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
store i8 0, i8* %9
%10 = call i32 @write(i32 %0, i8* %8, i32 1)
%11 = call i32 @read(i32 %0, i8* %9, i32 1)
%12 = load i8, i8* %9
%13 = icmp eq i8 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0)
%15 = tail call i32 @printf(i8* %14, i32 %2, i8* %1)
%16 = sext i8 %12 to i32
ret i32 %16
}