#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 */
char *get_current_time();
int /*<<< orphan*/ printf(char *, char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, char *, int);
int set_estop(int fd, int c) {
  char obuf[10];
  char bbuf[200];
  char *p;
  sprintf(obuf, "E%02X%02X", c, c);
  printf("%s : estop command = %5s (%d)", get_current_time(), obuf, c);
  obuf[5] = 10;
  obuf[6] = 0;
  obuf[7] = 0;
  p = &obuf[0];
  while (*p != 0) {
    write(fd, p, 1);
    usleep(100);
    p++;
  }
  return (0);
}


x86 assembly (clang, -O0):
<set_estop>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x12(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe8e(%rip),%rsi
call   1060 <sprintf@plt>
mov    $0x0,%al
call   1050 <get_current_time@plt>
mov    %rax,%rsi
lea    -0x12(%rbp),%rdx
mov    -0x8(%rbp),%ecx
lea    0xe7b(%rip),%rdi
call   1040 <printf@plt>
movb   $0xa,-0xd(%rbp)
movb   $0x0,-0xc(%rbp)
movb   $0x0,-0xb(%rbp)
lea    -0x12(%rbp),%rax
mov    %rax,-0xe8(%rbp)
mov    -0xe8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f3 <set_estop+0xa3>
mov    -0x4(%rbp),%edi
mov    -0xe8(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x64,%edi
call   1070 <usleep@plt>
mov    -0xe8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xe8(%rbp)
jmp    11ab <set_estop+0x5b>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_estop>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xe9c(%rip),%rsi
lea    0x6(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14d,%edx
mov    %r14d,%ecx
call   1060 <sprintf@plt>
xor    %eax,%eax
call   1050 <get_current_time@plt>
lea    0xe85(%rip),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1040 <printf@plt>
movw   $0xa,0xb(%rsp)
movb   $0x0,0xd(%rsp)
cmpb   $0x0,0x6(%rsp)
je     11d3 <set_estop+0x83>
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x64,%edi
call   1070 <usleep@plt>
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    11b0 <set_estop+0x60>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"E%02X%02X\00"
@.str.1 = [30 x i8] c"%s : estop command = %5s (%d)\00"
define i32 @set_estop(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [10 x i8]
%6 = alloca [200 x i8]
%7 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* %4
%10 = load i32, i32* %4
%11 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
%12 = call i8* (...) @get_current_time()
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%14 = load i32, i32* %4
%15 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* %13, i32 %14)
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 5
store i8 10, i8* %16
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 6
store i8 0, i8* %17
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 7
store i8 0, i8* %18
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
store i8* %19, i8** %7
br label %20
20: ; preds = %25, %2
%21 = load i8*, i8** %7
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %20
%26 = load i32, i32* %3
%27 = load i8*, i8** %7
%28 = call i32 @write(i32 %26, i8* %27, i32 1)
%29 = call i32 @usleep(i32 100)
%30 = load i8*, i8** %7
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %7
br label %20
32: ; preds = %20
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"E%02X%02X\00"
@.str.1 = [30 x i8] c"%s : estop command = %5s (%d)\00"
define i32 @set_estop(i32 %0, i32 %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %1)
%6 = tail call i8* (...) @get_current_time()
%7 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %4, i32 %1)
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 5
store i8 10, i8* %8
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 6
store i8 0, i8* %9
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 7
store i8 0, i8* %10
%11 = load i8, i8* %4
%12 = icmp eq i8 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %2, %13
%14 = phi i8* [ %17, %13 ], [ %4, %2 ]
%15 = call i32 @write(i32 %0, i8* %14, i32 1)
%16 = call i32 @usleep(i32 100)
%17 = getelementptr inbounds i8, i8* %14, i64 1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %13
20: ; preds = %13, %2
ret i32 0
}