#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*/ exit(int);
int /*<<< orphan*/ printf(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;
  if ((size = read(infd, uip.inbuf, 2000)) == -1) {
    printf("tun_to_serial: read");
    exit(1);
  }
  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   1040 <read@plt>
mov    %eax,-0x7dc(%rbp)
cmp    $0xffffffff,%eax
jne    118a <tun_to_serial+0x4a>
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x7d8(%rbp),%rsi
mov    -0x7dc(%rbp),%edx
call   1050 <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   1040 <read@plt>
cmp    $0xffffffff,%eax
je     117b <tun_to_serial+0x3b>
mov    %eax,%ebp
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1050 <write_to_serial@plt>
mov    %ebp,%eax
add    $0x7d8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %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 %10
7: ; preds = %2
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = call i32 @write_to_serial(i32 %1, i8* %4, i32 %5)
ret i32 %5
}