#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*/ printf(char *, ...);
int serial_write(int, char *, int);
int serialport();
int socket_server(int);
int main(void) {
  int fd;
  int nread, i, n = 0, datalen = 255, len = 0;
  fd = serialport();
  printf("fd=%d\n", fd);
  nread = serial_write(fd, "hello", 8);
  printf("nread=%d\n", nread);
  if (-1 == socket_server(fd)) {
    printf("Server is break down.");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0xff,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1050 <serialport@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    0xe7e(%rip),%rsi
mov    $0x8,%edx
call   1060 <serial_write@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1030 <socket_server@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11cc <main+0x8c>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1050 <serialport@plt>
mov    %eax,%ebx
lea    0xeaf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea6(%rip),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1060 <serial_write@plt>
lea    0xe99(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1030 <socket_server@plt>
cmp    $0xffffffff,%eax
jne    1197 <main+0x57>
lea    0xe87(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"fd=%d\0A\00"
@.str.1 = [6 x i8] c"hello\00"
@.str.2 = [10 x i8] c"nread=%d\0A\00"
@.str.3 = [22 x i8] c"Server is break down.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
store i32 255, i32* %6
store i32 0, i32* %7
%8 = call i32 (...) @serialport()
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %2
%12 = call i32 @serial_write(i32 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 8)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %2
%16 = call i32 @socket_server(i32 %15)
%17 = icmp eq i32 -1, %16
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %0
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [7 x i8] c"fd=%d\0A\00"
@.str.1 = [6 x i8] c"hello\00"
@.str.2 = [10 x i8] c"nread=%d\0A\00"
@.str.3 = [22 x i8] c"Server is break down.\00"
define i32 @main() {
%1 = tail call i32 (...) @serialport()
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @serial_write(i32 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 8)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%5 = tail call i32 @socket_server(i32 %1)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
ret i32 0
}