#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 */
struct msg_t {
  int dummy;
};

/* Variables and functions */
int uart_receive(int, struct msg_t *, unsigned int);
scalar_t__ uart_send(int, struct msg_t *);
int uart_send_and_receive(int fd, struct msg_t *msg, unsigned int timeout_ms) {
  int retval;
  if (uart_send(fd, msg)) {
    ;
    return -1;
  }
  retval = uart_receive(fd, msg, timeout_ms);
  if (retval == -1) {
    ;
  }
  if (retval == -2) {
    ;
  }
  return retval;
}


x86 assembly (clang, -O0):
<uart_send_and_receive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <uart_send@plt>
cmp    $0x0,%rax
je     1154 <uart_send_and_receive+0x34>
movl   $0xffffffff,-0x4(%rbp)
jmp    118a <uart_send_and_receive+0x6a>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <uart_receive@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1175 <uart_send_and_receive+0x55>
jmp    1175 <uart_send_and_receive+0x55>
cmpl   $0xfffffffe,-0x18(%rbp)
jne    1184 <uart_send_and_receive+0x64>
jmp    1184 <uart_send_and_receive+0x64>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uart_send_and_receive>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
call   1030 <uart_send@plt>
test   %rax,%rax
je     1140 <uart_send_and_receive+0x20>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <uart_receive@plt>

LLVM IR (-O0):
%struct.msg_t = type { i32 }
define i32 @uart_send_and_receive(i32 %0, %struct.msg_t* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.msg_t*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store %struct.msg_t* %1, %struct.msg_t** %6
store i32 %2, i32* %7
%9 = load i32, i32* %5
%10 = load %struct.msg_t*, %struct.msg_t** %6
%11 = call i64 @uart_send(i32 %9, %struct.msg_t* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %28
14: ; preds = %3
%15 = load i32, i32* %5
%16 = load %struct.msg_t*, %struct.msg_t** %6
%17 = load i32, i32* %7
%18 = call i32 @uart_receive(i32 %15, %struct.msg_t* %16, i32 %17)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %14
br label %22
22: ; preds = %21, %14
%23 = load i32, i32* %8
%24 = icmp eq i32 %23, -2
br i1 %24, label %25, label %26
25: ; preds = %22
br label %26
26: ; preds = %25, %22
%27 = load i32, i32* %8
store i32 %27, i32* %4
br label %28
28: ; preds = %26, %13
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
%struct.msg_t = type { i32 }
define i32 @uart_send_and_receive(i32 %0, %struct.msg_t* %1, i32 %2) {
%4 = tail call i64 @uart_send(i32 %0, %struct.msg_t* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @uart_receive(i32 %0, %struct.msg_t* %1, i32 %2)
br label %8
8: ; preds = %3, %6
%9 = phi i32 [ %7, %6 ], [ -1, %3 ]
ret i32 %9
}