#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*/ TCIOFLUSH;
int slowWrite(int, char *, int);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int writeDeg(int fd, int deg) {
  char buf[14] = {'W', 0, 0, 0, '0', 1, 0, 0, 0, 0, 0, 0x2F, 0x20};
  buf[1] = ((deg / 100) % 10) + '0';
  buf[2] = ((deg / 10) % 10) + '0';
  buf[3] = (deg % 10) + '0';
  tcflush(fd, TCIOFLUSH);
  int res = slowWrite(fd, buf, 13);
  return res == 13;
}


x86 assembly (clang, -O0):
<writeDeg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0xecb(%rip),%rax
mov    %rax,-0x16(%rbp)
mov    0xec9(%rip),%eax
mov    %eax,-0xe(%rbp)
mov    0xec3(%rip),%ax
mov    %ax,-0xa(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%al
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%al
mov    %al,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%al
mov    %al,-0x13(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x4(%rbp),%edi
lea    -0x16(%rbp),%rsi
mov    $0xd,%edx
call   1030 <slowWrite@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xd,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeDeg>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movabs $0x13000000057,%rax
mov    %rax,(%rsp)
movabs $0x202f0000000000,%rax
mov    %rax,0x6(%rsp)
movslq %esi,%rax
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
movslq %ecx,%rcx
imul   $0x66666667,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rdx
add    %esi,%edx
add    %edx,%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%ecx
add    $0x30,%cl
mov    %cl,0x1(%rsp)
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
movslq %ecx,%rcx
imul   $0x66666667,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rdx
add    %esi,%edx
add    %edx,%edx
lea    (%rdx,%rdx,4),%edx
mov    %ecx,%esi
sub    %edx,%esi
add    $0x30,%sil
mov    %sil,0x2(%rsp)
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
add    $0x30,%al
mov    %al,0x3(%rsp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xd,%edx
call   1030 <slowWrite@plt>
xor    %ecx,%ecx
cmp    $0xd,%eax
sete   %cl
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.writeDeg.buf = [14 x i8] c"W\00\00\000\01\00\00\00\00\00/ \00"
@TCIOFLUSH = global i32 0
define i32 @writeDeg(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [14 x i8]
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = bitcast [14 x i8]* %5 to i8*
%8 = load i32, i32* %4
%9 = sdiv i32 %8, 100
%10 = srem i32 %9, 10
%11 = add nsw i32 %10, 48
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 1
store i8 %12, i8* %13
%14 = load i32, i32* %4
%15 = sdiv i32 %14, 10
%16 = srem i32 %15, 10
%17 = add nsw i32 %16, 48
%18 = trunc i32 %17 to i8
%19 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 2
store i8 %18, i8* %19
%20 = load i32, i32* %4
%21 = srem i32 %20, 10
%22 = add nsw i32 %21, 48
%23 = trunc i32 %22 to i8
%24 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 3
store i8 %23, i8* %24
%25 = load i32, i32* %3
%26 = load i32, i32* @TCIOFLUSH
%27 = call i32 @tcflush(i32 %25, i32 %26)
%28 = load i32, i32* %3
%29 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 0
%30 = call i32 @slowWrite(i32 %28, i8* %29, i32 13)
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, 13
%33 = zext i1 %32 to i32
ret i32 %33
}

LLVM IR (-O2):
@__const.writeDeg.buf = [14 x i8] c"W\00\00\000\01\00\00\00\00\00/ \00"
@TCIOFLUSH = global i32 0
define i32 @writeDeg(i32 %0, i32 %1) {
%3 = alloca [14 x i8]
%4 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 0
%5 = sdiv i32 %1, 100
%6 = srem i32 %5, 10
%7 = trunc i32 %6 to i8
%8 = add nsw i8 %7, 48
%9 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 1
store i8 %8, i8* %9
%10 = sdiv i32 %1, 10
%11 = srem i32 %10, 10
%12 = trunc i32 %11 to i8
%13 = add nsw i8 %12, 48
%14 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 2
store i8 %13, i8* %14
%15 = srem i32 %1, 10
%16 = trunc i32 %15 to i8
%17 = add nsw i8 %16, 48
%18 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 3
store i8 %17, i8* %18
%19 = load i32, i32* @TCIOFLUSH
%20 = tail call i32 @tcflush(i32 %0, i32 %19)
%21 = call i32 @slowWrite(i32 %0, i8* %4, i32 13)
%22 = icmp eq i32 %21, 13
%23 = zext i1 %22 to i32
ret i32 %23
}