#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);
int tun_to_serial(int infd, int outfd) {
  struct {
    unsigned char inbuf[2000];
  } uip;
  int size = read(infd, uip.inbuf, 2000);
  if (size == -1) {
    err(1, "tun_to_serial: read");
  }
  write_to_serial(outfd, uip.inbuf, size);
  return 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)
cmpl   $0xffffffff,-0x7dc(%rbp)
jne    1179 <tun_to_serial+0x49>
mov    $0x1,%edi
lea    0xe8c(%rip),%rsi
call   1050 <err@plt>
mov    -0x8(%rbp),%edi
lea    -0x7d8(%rbp),%rsi
mov    -0x7dc(%rbp),%edx
call   1040 <write_to_serial@plt>
mov    -0x7dc(%rbp),%eax
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>
mov    %ebp,%eax
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 i32 @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 = load i32, i32* %6
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @err(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = load i32, i32* %4
%17 = getelementptr inbounds %struct.anon, %struct.anon* %5, i32 0, i32 0
%18 = getelementptr inbounds [2000 x i8], [2000 x i8]* %17, i64 0, i64 0
%19 = load i32, i32* %6
%20 = call i32 @write_to_serial(i32 %16, i8* %18, i32 %19)
%21 = load i32, i32* %6
ret i32 %21
}

LLVM IR (-O2):
%struct.anon = type { [2000 x i8] }
@.str = [20 x i8] c"tun_to_serial: read\00"
define i32 @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 i32 %5
}