#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*/ perror(char *);
int write(int, char *, int);
int write_serial_long(int serial_fd, unsigned int value) {
  char out[4] = {value & 0xff, (value >> 8) & 0xff, (value >> 16) & 0xff,
                 (value >> 24) & 0xff};
  if (write(serial_fd, out, 4) != 4) {
    perror("write");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<write_serial_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x10(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,-0xf(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %al,-0xe(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x18,%eax
and    $0xff,%eax
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x4,%eax
je     1195 <write_serial_long+0x75>
lea    0xe7c(%rip),%rdi
call   1040 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    119c <write_serial_long+0x7c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_serial_long>:
push   %rax
mov    %esi,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x4,%ecx
jne    1142 <write_serial_long+0x22>
pop    %rcx
ret
lea    0xeb7(%rip),%rdi
call   1040 <perror@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"write\00"
define i32 @write_serial_long(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%8 = load i32, i32* %5
%9 = and i32 %8, 255
%10 = trunc i32 %9 to i8
store i8 %10, i8* %7
%11 = getelementptr inbounds i8, i8* %7, i64 1
%12 = load i32, i32* %5
%13 = lshr i32 %12, 8
%14 = and i32 %13, 255
%15 = trunc i32 %14 to i8
store i8 %15, i8* %11
%16 = getelementptr inbounds i8, i8* %11, i64 1
%17 = load i32, i32* %5
%18 = lshr i32 %17, 16
%19 = and i32 %18, 255
%20 = trunc i32 %19 to i8
store i8 %20, i8* %16
%21 = getelementptr inbounds i8, i8* %16, i64 1
%22 = load i32, i32* %5
%23 = lshr i32 %22, 24
%24 = and i32 %23, 255
%25 = trunc i32 %24 to i8
store i8 %25, i8* %21
%26 = load i32, i32* %4
%27 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%28 = call i32 @write(i32 %26, i8* %27, i32 4)
%29 = icmp ne i32 %28, 4
br i1 %29, label %30, label %32
30: ; preds = %2
%31 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %33
32: ; preds = %2
store i32 1, i32* %3
br label %33
33: ; preds = %32, %30
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [6 x i8] c"write\00"
define i32 @write_serial_long(i32 %0, i32 %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = trunc i32 %1 to i8
store i8 %5, i8* %4
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%7 = lshr i32 %1, 8
%8 = trunc i32 %7 to i8
store i8 %8, i8* %6
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%10 = lshr i32 %1, 16
%11 = trunc i32 %10 to i8
store i8 %11, i8* %9
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
%13 = lshr i32 %1, 24
%14 = trunc i32 %13 to i8
store i8 %14, i8* %12
%15 = call i32 @write(i32 %0, i8* %4, i32 4)
%16 = icmp eq i32 %15, 4
br i1 %16, label %19, label %17
17: ; preds = %2
%18 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %2, %17
%20 = phi i32 [ 0, %17 ], [ 1, %2 ]
ret i32 %20
}