#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*/ err(int, char *);
int read(int, unsigned char *, int);
int /*<<< orphan*/ write_to_serial(int, unsigned char *, int);
void tun_to_serial(int infd, int outfd) {
  struct {
    unsigned char inbuf[2000];
  } uip;
  int size;
  if ((size = read(infd, uip.inbuf, 2000)) == -1) {
    err(1, "tun_to_serial: read");
  }
  write_to_serial(outfd, uip.inbuf, size);
}


x86 assembly (clang, -O0):
<tun_to_serial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7e0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x7d8(%rbp),%rsi
mov    $0x7d0,%edx
call   1030 <read@plt>
mov    %eax,-0x7dc(%rbp)
cmp    $0xffffffff,%eax
jne    1175 <tun_to_serial+0x45>
mov    $0x1,%edi
lea    0xe90(%rip),%rsi
call   1050 <err@plt>
mov    -0x8(%rbp),%edi
lea    -0x7d8(%rbp),%rsi
mov    -0x7dc(%rbp),%edx
call   1040 <write_to_serial@plt>
add    $0x7e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tun_to_serial>:
push   %rbp
push   %rbx
sub    $0x7d8,%rsp
mov    %esi,%ebx
lea    0x8(%rsp),%rsi
mov    $0x7d0,%edx
call   1030 <read@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1162 <tun_to_serial+0x32>
lea    0xea8(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
call   1040 <write_to_serial@plt>
add    $0x7d8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.anon = type { [2000 x i8] }
@.str = [20 x i8] c"tun_to_serial: read\00"
define void @tun_to_serial(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.anon
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = getelementptr inbounds %struct.anon, %struct.anon* %5, i32 0, i32 0
%9 = getelementptr inbounds [2000 x i8], [2000 x i8]* %8, i64 0, i64 0
%10 = call i32 @read(i32 %7, i8* %9, i32 2000)
store i32 %10, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @err(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = load i32, i32* %4
%16 = getelementptr inbounds %struct.anon, %struct.anon* %5, i32 0, i32 0
%17 = getelementptr inbounds [2000 x i8], [2000 x i8]* %16, i64 0, i64 0
%18 = load i32, i32* %6
%19 = call i32 @write_to_serial(i32 %15, i8* %17, i32 %18)
ret void
}

LLVM IR (-O2):
%struct.anon = type { [2000 x i8] }
@.str = [20 x i8] c"tun_to_serial: read\00"
define void @tun_to_serial(i32 %0, i32 %1) {
%3 = alloca %struct.anon
%4 = getelementptr inbounds %struct.anon, %struct.anon* %3, i64 0, i32 0, i64 0
%5 = call i32 @read(i32 %0, i8* %4, i32 2000)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = call i32 @write_to_serial(i32 %1, i8* %4, i32 %5)
ret void
}