#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*/ XFS_FrameInfo(unsigned char *, int);
int /*<<< orphan*/ close(int);
int open_port(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int set_opt(int, int, int, char, int);
int test(void) {
  int fd;
  int nread, i;
  unsigned char buff[50] = "[h0]hello [h0]world";
  if ((fd = open_port(fd, 1)) < 0) {
    perror("open_port error");
    return 0;
  }
  if ((i = set_opt(fd, 9600, 8, 'N', 1)) < 0) {
    perror("set_opt error");
    return 0;
  }
  printf("fd=%d\n", fd);
  XFS_FrameInfo(buff, fd);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x50(%rbp),%rdi
lea    0xe7d(%rip),%rsi
mov    $0x32,%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1090 <open_port@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11be <test+0x4e>
lea    0xe85(%rip),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1229 <test+0xb9>
mov    -0x8(%rbp),%edi
mov    $0x2580,%esi
mov    $0x8,%edx
mov    $0x4e,%ecx
mov    $0x1,%r8d
call   1060 <set_opt@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    11ff <test+0x8f>
lea    0xe54(%rip),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1229 <test+0xb9>
mov    -0x8(%rbp),%esi
lea    0xe47(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1080 <XFS_FrameInfo@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbx
sub    $0x40,%rsp
movaps 0xeb4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe98(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe7c(%rip),%xmm0
movaps %xmm0,(%rsp)
movw   $0x0,0x30(%rsp)
mov    $0x1,%esi
call   1080 <open_port@plt>
test   %eax,%eax
js     11e6 <test+0x86>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x2580,%esi
mov    $0x8,%edx
mov    $0x4e,%ecx
mov    $0x1,%r8d
call   1050 <set_opt@plt>
test   %eax,%eax
js     11f4 <test+0x94>
lea    0xe8a(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %rsp,%rdi
mov    %ebx,%esi
call   1070 <XFS_FrameInfo@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret
lea    0xe45(%rip),%rdi
call   1060 <perror@plt>
jmp    11de <test+0x7e>
lea    0xe47(%rip),%rdi
call   1060 <perror@plt>
jmp    11de <test+0x7e>

LLVM IR (-O0):
@__const.test.buff = [50 x i8] c"[h0]hello [h0]world\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [16 x i8] c"open_port error\00"
@.str.1 = [14 x i8] c"set_opt error\00"
@.str.2 = [7 x i8] c"fd=%d\0A\00"
define i32 @test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [50 x i8]
%6 = bitcast [50 x i8]* %5 to i8*
%7 = load i32, i32* %2
%8 = call i32 @open_port(i32 %7, i32 1)
store i32 %8, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %26
12: ; preds = %0
%13 = load i32, i32* %2
%14 = call i32 @set_opt(i32 %13, i32 9600, i32 8, i8 signext 78, i32 1)
store i32 %14, i32* %4
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %26
18: ; preds = %12
%19 = load i32, i32* %2
%20 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%22 = load i32, i32* %2
%23 = call i32 @XFS_FrameInfo(i8* %21, i32 %22)
%24 = load i32, i32* %2
%25 = call i32 @close(i32 %24)
store i32 0, i32* %1
br label %26
26: ; preds = %18, %16, %10
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@__const.test.buff = [50 x i8] c"[h0]hello [h0]world\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [16 x i8] c"open_port error\00"
@.str.1 = [14 x i8] c"set_opt error\00"
@.str.2 = [7 x i8] c"fd=%d\0A\00"
define i32 @test() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @open_port(i32 undef, i32 1)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %16
7: ; preds = %0
%8 = tail call i32 @set_opt(i32 %3, i32 9600, i32 8, i8 signext 78, i32 1)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %16
12: ; preds = %7
%13 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%14 = call i32 @XFS_FrameInfo(i8* %2, i32 %3)
%15 = call i32 @close(i32 %3)
br label %16
16: ; preds = %12, %10, %5
ret i32 0
}