#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 */
typedef char uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int write(int, char *, int);
int transfer_8bit(int fd) {
  int ret = 0;
  uint8_t tx[] = {'D', 'E', 'A', 'D', 'B', 'E', 'F', 'F'};
  int i;
  ret = write(fd, tx, 8);
  if (ret < 0) {
    printf("Failed to write massage!\n");
    return -1;
  }
  printf("Transmit:\n");
  for (i = 0; i < ret; i++) {
    printf("0x%02X ", tx[i]);
    if (i % 8 == 7)
      printf("\n");
  }
  return ret;
}


x86 assembly (clang, -O0):
<transfer_8bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1175 <transfer_8bit+0x55>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e8 <transfer_8bit+0xc8>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e2 <transfer_8bit+0xc2>
movslq -0x18(%rbp),%rax
movsbl -0x14(%rbp,%rax,1),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x7,%edx
jne    11cf <transfer_8bit+0xaf>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d4 <transfer_8bit+0xb4>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118a <transfer_8bit+0x6a>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transfer_8bit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movabs $0x4646454244414544,%rax
45 46 46
mov    %rax,(%rsp)
mov    %rsp,%rsi
mov    $0x8,%edx
call   1050 <write@plt>
test   %eax,%eax
js     11bb <transfer_8bit+0x7b>
mov    %eax,%r14d
lea    0xe98(%rip),%rdi
call   1040 <puts@plt>
test   %r14d,%r14d
je     11cf <transfer_8bit+0x8f>
mov    %r14d,%ebp
lea    0xe7c(%rip),%r15
xor    %ebx,%ebx
jmp    1199 <transfer_8bit+0x59>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11d2 <transfer_8bit+0x92>
movsbl (%rsp,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%eax
not    %eax
test   $0x7,%al
jne    1190 <transfer_8bit+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1190 <transfer_8bit+0x50>
lea    0xe50(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%r14d
jmp    11d2 <transfer_8bit+0x92>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.transfer_8bit.tx = [8 x i8] c"DEADBEFF"
@.str = [26 x i8] c"Failed to write massage!\0A\00"
@.str.1 = [11 x i8] c"Transmit:\0A\00"
@.str.2 = [8 x i8] c"0x%02X \00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @transfer_8bit(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [8 x i8]
%6 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
%7 = bitcast [8 x i8]* %5 to i8*
%8 = load i32, i32* %3
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%10 = call i32 @write(i32 %8, i8* %9, i32 8)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %39
15: ; preds = %1
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %6
br label %17
17: ; preds = %34, %15
%18 = load i32, i32* %6
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %37
21: ; preds = %17
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %6
%29 = srem i32 %28, 8
%30 = icmp eq i32 %29, 7
br i1 %30, label %31, label %33
31: ; preds = %21
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %21
br label %34
34: ; preds = %33
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %17
37: ; preds = %17
%38 = load i32, i32* %4
store i32 %38, i32* %2
br label %39
39: ; preds = %37, %13
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@.str.2 = [8 x i8] c"0x%02X \00"
@str = [10 x i8] c"Transmit:\00"
@str.4 = [25 x i8] c"Failed to write massage!\00"
define i32 @transfer_8bit(i32 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to [8 x i8]*
%4 = bitcast i64* %2 to i8*
store i64 5063810981939987780, i64* %2
%5 = call i32 @write(i32 %0, i8* %4, i32 8)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.4, i64 0, i64 0))
br label %27
9: ; preds = %1
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%11 = icmp eq i32 %5, 0
br i1 %11, label %27, label %12
12: ; preds = %9
%13 = zext i32 %5 to i64
br label %14
14: ; preds = %12, %24
%15 = phi i64 [ 0, %12 ], [ %25, %24 ]
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = and i64 %15, 7
%21 = icmp eq i64 %20, 7
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = tail call i32 @putchar(i32 10)
br label %24
24: ; preds = %14, %22
%25 = add nuw nsw i64 %15, 1
%26 = icmp eq i64 %25, %13
br i1 %26, label %27, label %14
27: ; preds = %24, %9, %7
%28 = phi i32 [ -1, %7 ], [ 0, %9 ], [ %5, %24 ]
ret i32 %28
}