#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*/ siginfo_t;

/* Variables and functions */
int open_port(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read_port(char *, int);
void receiveData(int n, siginfo_t *info, void *unused) {
  char buffer[25];
  int port = 0;
  int res;
  res = open_port("/dev/iodriver", port);
  if (res != 0) {
    perror("open_port: Unable to open port - ");
    return;
  }
  res = read_port(buffer, port);
  if (res != 0) {
    perror("read_port: Unable to read port - ");
  }
  printf("%s \n", buffer);
}


x86 assembly (clang, -O0):
<receiveData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%esi
lea    0xe9c(%rip),%rdi
call   1060 <open_port@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
je     1187 <receiveData+0x47>
lea    0xe91(%rip),%rdi
call   1050 <perror@plt>
jmp    11bc <receiveData+0x7c>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1030 <read_port@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
je     11ac <receiveData+0x6c>
lea    0xe89(%rip),%rdi
call   1050 <perror@plt>
lea    -0x40(%rbp),%rsi
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receiveData>:
sub    $0x28,%rsp
lea    0xeb5(%rip),%rdi
xor    %esi,%esi
call   1060 <open_port@plt>
test   %eax,%eax
jne    1178 <receiveData+0x38>
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <read_port@plt>
test   %eax,%eax
jne    1188 <receiveData+0x48>
lea    0xee7(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
add    $0x28,%rsp
ret
lea    0xe8f(%rip),%rdi
add    $0x28,%rsp
jmp    1050 <perror@plt>
lea    0xea1(%rip),%rdi
call   1050 <perror@plt>
jmp    1164 <receiveData+0x24>

LLVM IR (-O0):
@.str = [14 x i8] c"/dev/iodriver\00"
@.str.1 = [34 x i8] c"open_port: Unable to open port - \00"
@.str.2 = [34 x i8] c"read_port: Unable to read port - \00"
@.str.3 = [5 x i8] c"%s \0A\00"
define void @receiveData(i32 %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca [25 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i8* %2, i8** %6
store i32 0, i32* %8
%10 = load i32, i32* %8
%11 = call i32 @open_port(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %9
%12 = load i32, i32* %9
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %27
16: ; preds = %3
%17 = getelementptr inbounds [25 x i8], [25 x i8]* %7, i64 0, i64 0
%18 = load i32, i32* %8
%19 = call i32 @read_port(i8* %17, i32 %18)
store i32 %19, i32* %9
%20 = load i32, i32* %9
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %16
%25 = getelementptr inbounds [25 x i8], [25 x i8]* %7, i64 0, i64 0
%26 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %24, %14
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"/dev/iodriver\00"
@.str.1 = [34 x i8] c"open_port: Unable to open port - \00"
@.str.2 = [34 x i8] c"read_port: Unable to read port - \00"
@.str.3 = [5 x i8] c"%s \0A\00"
define void @receiveData(i32 %0, i32* nocapture readnone %1, i8* nocapture readnone %2) {
%4 = alloca [25 x i8]
%5 = getelementptr inbounds [25 x i8], [25 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @open_port(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %17
10: ; preds = %3
%11 = call i32 @read_port(i8* %5, i32 0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %5)
br label %17
17: ; preds = %15, %8
ret void
}