#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*/ close(int);
int open_port(char *);
int /*<<< orphan*/ write(int, char *, int);
int SetOrigin(void) {
  char term[] = "/dev/ttyd2";
  int SerialPort;
  char c = 13;
  SerialPort = open_port(term);
  if (!SerialPort)
    return 0;
  write(SerialPort, "o", 1);
  write(SerialPort, &c, 1);
  close(SerialPort);
  return 0;
}


x86 assembly (clang, -O0):
<SetOrigin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0xf(%rbp)
mov    0xebe(%rip),%ax
mov    %ax,-0x7(%rbp)
mov    0xeb6(%rip),%al
mov    %al,-0x5(%rbp)
movb   $0xd,-0x15(%rbp)
lea    -0xf(%rbp),%rdi
call   1050 <open_port@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    117d <SetOrigin+0x4d>
movl   $0x0,-0x4(%rbp)
jmp    11b1 <SetOrigin+0x81>
mov    -0x14(%rbp),%edi
lea    0xe84(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetOrigin>:
push   %rbx
sub    $0x20,%rsp
movabs $0x7974742f7665642f,%rax
74 74 79
mov    %rax,0x10(%rsp)
movl   $0x326479,0x17(%rsp)
movb   $0xd,0xf(%rsp)
lea    0x10(%rsp),%rdi
call   1050 <open_port@plt>
test   %eax,%eax
je     118c <SetOrigin+0x5c>
mov    %eax,%ebx
lea    0xea3(%rip),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1030 <write@plt>
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.SetOrigin.term = [11 x i8] c"/dev/ttyd2\00"
@.str = [2 x i8] c"o\00"
define i32 @SetOrigin() {
%1 = alloca i32
%2 = alloca [11 x i8]
%3 = alloca i32
%4 = alloca i8
%5 = bitcast [11 x i8]* %2 to i8*
store i8 13, i8* %4
%6 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%7 = call i32 @open_port(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %0
store i32 0, i32* %1
br label %18
11: ; preds = %0
%12 = load i32, i32* %3
%13 = call i32 @write(i32 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%14 = load i32, i32* %3
%15 = call i32 @write(i32 %14, i8* %4, i32 1)
%16 = load i32, i32* %3
%17 = call i32 @close(i32 %16)
store i32 0, i32* %1
br label %18
18: ; preds = %11, %10
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@__const.SetOrigin.term = [11 x i8] c"/dev/ttyd2\00"
@.str = [2 x i8] c"o\00"
define i32 @SetOrigin() {
%1 = alloca [11 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 0
store i8 13, i8* %2
%4 = call i32 @open_port(i8* %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %0
%7 = call i32 @write(i32 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%8 = call i32 @write(i32 %4, i8* %2, i32 1)
%9 = call i32 @close(i32 %4)
br label %10
10: ; preds = %0, %6
ret i32 0
}