#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*/ B9600;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdout;
int ttyS_open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ttyS_write(int, unsigned char);
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  int vt100;
  int nb = 0;
  unsigned char c = 0;
  printf("%s %s\n", argv[0], "/dev/ttyS0");
  vt100 = ttyS_open("/dev/ttyS0", O_WRONLY, B9600);
  while (1) {
    printf("entrer un octet en hexa: ");
    scanf("%x", &nb);
    c = nb & 0xff;
    printf("write %3dth : %08x\n", nb, c);
    fflush(stdout);
    ttyS_write(vt100, c);
    usleep(100000);
    nb++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe71(%rip),%rdi
lea    0xe71(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
lea    0xe51(%rip),%rdi
call   1070 <ttyS_open@plt>
mov    %eax,-0x14(%rbp)
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe59(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x24(%rbp)
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%esi
movzbl -0x19(%rbp),%edx
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    -0x14(%rbp),%edi
movzbl -0x19(%rbp),%esi
call   1040 <ttyS_write@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    %eax,-0x18(%rbp)
jmp    11be <main+0x5e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
mov    (%rsi),%rsi
lea    0xe83(%rip),%rdi
lea    0xe83(%rip),%rbx
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1070 <ttyS_open@plt>
mov    %eax,%ebx
lea    0xe7b(%rip),%r15
lea    0x4(%rsp),%r12
lea    0xe72(%rip),%r13
mov    0x2e14(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xe3b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%esi
movzbl %sil,%ebp
mov    %r13,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r14),%edi
call   1050 <fflush@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <ttyS_write@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
addl   $0x1,0x4(%rsp)
jmp    11d0 <main+0x70>

LLVM IR (-O0):
@.str = [7 x i8] c"%s %s\0A\00"
@.str.1 = [11 x i8] c"/dev/ttyS0\00"
@O_WRONLY = global i32 0
@B9600 = global i32 0
@.str.2 = [26 x i8] c"entrer un octet en hexa: \00"
@.str.3 = [3 x i8] c"%x\00"
@.str.4 = [20 x i8] c"write %3dth : %08x\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i8 0, i8* %8
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @O_WRONLY
%14 = load i32, i32* @B9600
%15 = call i32 @ttyS_open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14)
store i32 %15, i32* %6
br label %16
16: ; preds = %2, %16
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%19 = load i32, i32* %7
%20 = and i32 %19, 255
%21 = trunc i32 %20 to i8
store i8 %21, i8* %8
%22 = load i32, i32* %7
%23 = load i8, i8* %8
%24 = zext i8 %23 to i32
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %22, i32 %24)
%26 = load i32, i32* @stdout
%27 = call i32 @fflush(i32 %26)
%28 = load i32, i32* %6
%29 = load i8, i8* %8
%30 = call i32 @ttyS_write(i32 %28, i8 zeroext %29)
%31 = call i32 @usleep(i32 100000)
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %16
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s %s\0A\00"
@.str.1 = [11 x i8] c"/dev/ttyS0\00"
@O_WRONLY = global i32 0
@B9600 = global i32 0
@.str.2 = [26 x i8] c"entrer un octet en hexa: \00"
@.str.3 = [3 x i8] c"%x\00"
@.str.4 = [20 x i8] c"write %3dth : %08x\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @B9600
%9 = tail call i32 @ttyS_open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %8)
br label %10
10: ; preds = %10, %2
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%13 = load i32, i32* %3
%14 = trunc i32 %13 to i8
%15 = and i32 %13, 255
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %13, i32 %15)
%17 = load i32, i32* @stdout
%18 = call i32 @fflush(i32 %17)
%19 = call i32 @ttyS_write(i32 %9, i8 zeroext %14)
%20 = call i32 @usleep(i32 100000)
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
br label %10
}