#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*/ server_write(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ simple_write(int, char *);
int sscanf(char *, char *, int *);
char *strtok(char *, char *);
void send_data(int fd, char *line) {
  char *s;
  if (!*line) {
    simple_write(fd, "USAGE: senddata <hex byte> <hex byte>*\r\nExample: "
                     "senddata 41 42 43  -- sends ABC\r\n");
    return;
  }
  while ((s = strtok(line, " "))) {
    int x;
    line = 0;
    if (sscanf(s, "%x", &x) != 1 || x > 255 || x < 0) {
      simple_write(fd, "\r\nERROR: Unknown byte.\r\n");
      return;
    } else {
      char c = (char)x;
      server_write(fd, &c, 1, 0);
    }
  }
  simple_write(fd, "\r\n");
}


x86 assembly (clang, -O0):
<send_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1170 <send_data+0x30>
mov    -0x4(%rbp),%edi
lea    0xe9a(%rip),%rsi
call   1030 <simple_write@plt>
jmp    1210 <send_data+0xd0>
jmp    1175 <send_data+0x35>
mov    -0x10(%rbp),%rdi
lea    0xed3(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1201 <send_data+0xc1>
movq   $0x0,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeaf(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    11cf <send_data+0x8f>
cmpl   $0xff,-0x1c(%rbp)
jg     11cf <send_data+0x8f>
cmpl   $0x0,-0x1c(%rbp)
jge    11e3 <send_data+0xa3>
mov    -0x4(%rbp),%edi
lea    0xe7f(%rip),%rsi
call   1030 <simple_write@plt>
jmp    1210 <send_data+0xd0>
mov    -0x1c(%rbp),%eax
mov    %al,-0x1d(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1060 <server_write@plt>
jmp    1175 <send_data+0x35>
mov    -0x4(%rbp),%edi
lea    0xe63(%rip),%rsi
call   1030 <simple_write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_data>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
cmpb   $0x0,(%rsi)
je     11df <send_data+0x9f>
lea    0xef4(%rip),%rax
mov    %rsi,%rdi
mov    %rax,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
je     11d6 <send_data+0x96>
lea    0xedf(%rip),%r14
lea    0xc(%rsp),%r15
lea    0xb(%rsp),%r12
lea    0xecc(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    11fa <send_data+0xba>
mov    0xc(%rsp),%eax
cmp    $0xff,%eax
jg     11fa <send_data+0xba>
test   %eax,%eax
js     11fa <send_data+0xba>
mov    %al,0xb(%rsp)
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1060 <server_write@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
jne    1190 <send_data+0x50>
lea    0xe91(%rip),%rsi
jmp    1201 <send_data+0xc1>
lea    0xe1a(%rip),%rsi
mov    %ebx,%edi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <simple_write@plt>
lea    0xe57(%rip),%rsi
mov    %ebx,%edi
call   1030 <simple_write@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [83 x i8] c"USAGE: senddata <hex byte> <hex byte>*\0D\0AExample: senddata 41 42 43 -- sends ABC\0D\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [25 x i8] c"\0D\0AERROR: Unknown byte.\0D\0A\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
define void @send_data(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* %3
%13 = call i32 @simple_write(i32 %12, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0))
br label %41
14: ; preds = %2
br label %15
15: ; preds = %37, %14
%16 = load i8*, i8** %4
%17 = call i8* @strtok(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %17, i8** %5
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %38
19: ; preds = %15
store i8* null, i8** %4
%20 = load i8*, i8** %5
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%22 = icmp ne i32 %21, 1
br i1 %22, label %29, label %23
23: ; preds = %19
%24 = load i32, i32* %6
%25 = icmp sgt i32 %24, 255
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32, i32* %6
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26, %23, %19
%30 = load i32, i32* %3
%31 = call i32 @simple_write(i32 %30, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %41
32: ; preds = %26
%33 = load i32, i32* %6
%34 = trunc i32 %33 to i8
store i8 %34, i8* %7
%35 = load i32, i32* %3
%36 = call i32 @server_write(i32 %35, i8* %7, i32 1, i32 0)
br label %37
37: ; preds = %32
br label %15
38: ; preds = %15
%39 = load i32, i32* %3
%40 = call i32 @simple_write(i32 %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %41
41: ; preds = %38, %29, %11
ret void
}

LLVM IR (-O2):
@.str = [83 x i8] c"USAGE: senddata <hex byte> <hex byte>*\0D\0AExample: senddata 41 42 43 -- sends ABC\0D\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [25 x i8] c"\0D\0AERROR: Unknown byte.\0D\0A\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
define void @send_data(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = call i8* @strtok(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %30, label %10
10: ; preds = %7
%11 = bitcast i32* %3 to i8*
br label %14
12: ; preds = %2
%13 = tail call i32 @simple_write(i32 %0, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0))
br label %32
14: ; preds = %10, %25
%15 = phi i8* [ %8, %10 ], [ %28, %25 ]
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%17 = icmp ne i32 %16, 1
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, 255
%20 = select i1 %17, i1 true, i1 %19
%21 = icmp slt i32 %18, 0
%22 = select i1 %20, i1 true, i1 %21
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = call i32 @simple_write(i32 %0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %32
25: ; preds = %14
%26 = trunc i32 %18 to i8
store i8 %26, i8* %4
%27 = call i32 @server_write(i32 %0, i8* %4, i32 1, i32 0)
%28 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %14
30: ; preds = %25, %7
%31 = call i32 @simple_write(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %32
32: ; preds = %23, %30, %12
ret void
}