#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*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, ...);
char *strerror(int /*<<< orphan*/);
int write(int, char *, int);
void send_data(int mfd, const unsigned char *command, const char *data_dir,
               int address_size) {
  char filename[256];
  int seek = 0, size = -1, chunk = 12;
  int data_fd;
  char buffer[4096];
  switch (command[0]) {
  case 0x05:
    size = ((unsigned int)(command + 4)[0] + ((command + 4)[1] << 8));
    if (command[1] == 0x9d)
      sprintf(filename, "%s/id0", data_dir);
    else
      sprintf(filename, "%s/id1", data_dir);
    break;
  case 0x96:
    size = 512;
    sprintf(filename, "%s/config%d", data_dir, command[1]);
    break;
  case 0x89:
    size = ((unsigned int)(command + 5)[0] + ((command + 5)[1] << 8));
    sprintf(filename, "%s/misc", data_dir);
    break;
  case 0x15:
    chunk = 4096;
    if (address_size == 4) {
      seek = ((unsigned int)(command + 1)[0] + ((command + 1)[1] << 8) +
              ((command + 1)[2] << 16) + ((command + 1)[3] << 24));
      size = ((unsigned int)(command + 5)[0] + ((command + 5)[1] << 8) +
              ((command + 5)[2] << 16) + ((command + 5)[3] << 24));
    } else {
      seek = ((unsigned int)(command + 1)[0] + ((command + 1)[1] << 8) +
              ((command + 1)[2] << 16));
      size = ((unsigned int)(command + 4)[0] + ((command + 4)[1] << 8) +
              ((command + 4)[2] << 16));
    }
    sprintf(filename, "%s/memory", data_dir);
    break;
  default:
    printf("Unknown command %02x.\n", command[0]);
  }
  printf("Sending file %s, bytes (%d - %d)", filename, seek, seek + size);
  data_fd = open(filename, O_RDONLY);
  if (data_fd < 0) {
    printf("%s: opening %s\n", strerror(errno), filename);
    return;
  }
  if (seek) {
    if (lseek(data_fd, seek, SEEK_SET) == -1) {
      printf("%s while positioning file pointer.\n", strerror(errno));
      return;
    }
  }
  if (size < chunk)
    chunk = size;
  while (size > 0) {
    int byte_count;
    byte_count = read(data_fd, buffer, chunk);
    if (byte_count != chunk) {
      printf("%s: error reading %s\n", strerror(errno), filename);
      return;
    }
    byte_count = write(mfd, buffer, chunk);
    if (byte_count != chunk) {
      printf("%3: error writing\n", strerror(errno));
      return;
    }
    size -= chunk;
    if (size < chunk)
      chunk = size;
  }
  close(data_fd);
  printf("\n");
}


x86 assembly (clang, -O0):
<send_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1140,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x124(%rbp)
movl   $0xffffffff,-0x128(%rbp)
ff ff ff
movl   $0xc,-0x12c(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x1138(%rbp)
sub    $0x5,%eax
je     1212 <send_data+0x92>
jmp    11d2 <send_data+0x52>
mov    -0x1138(%rbp),%eax
sub    $0x15,%eax
je     12e5 <send_data+0x165>
jmp    11e6 <send_data+0x66>
mov    -0x1138(%rbp),%eax
sub    $0x89,%eax
je     12ac <send_data+0x12c>
jmp    11fc <send_data+0x7c>
mov    -0x1138(%rbp),%eax
sub    $0x96,%eax
je     127c <send_data+0xfc>
jmp    13d6 <send_data+0x256>
mov    -0x10(%rbp),%rax
movzbl 0x4(%rax),%eax
mov    -0x10(%rbp),%rcx
movzbl 0x5(%rcx),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    %eax,-0x128(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x9d,%eax
jne    125e <send_data+0xde>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdae(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
jmp    1277 <send_data+0xf7>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd97(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
jmp    13eb <send_data+0x26b>
movl   $0x200,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%ecx
lea    0xd6e(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
jmp    13eb <send_data+0x26b>
mov    -0x10(%rbp),%rax
movzbl 0x5(%rax),%eax
mov    -0x10(%rbp),%rcx
movzbl 0x6(%rcx),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    %eax,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd41(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
jmp    13eb <send_data+0x26b>
movl   $0x1000,-0x12c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jne    1368 <send_data+0x1e8>
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
mov    -0x10(%rbp),%rcx
movzbl 0x2(%rcx),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
movzbl 0x3(%rcx),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
movzbl 0x4(%rcx),%ecx
shl    $0x18,%ecx
add    %ecx,%eax
mov    %eax,-0x124(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x5(%rax),%eax
mov    -0x10(%rbp),%rcx
movzbl 0x6(%rcx),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
movzbl 0x7(%rcx),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
movzbl 0x8(%rcx),%ecx
shl    $0x18,%ecx
add    %ecx,%eax
mov    %eax,-0x128(%rbp)
jmp    13b8 <send_data+0x238>
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
mov    -0x10(%rbp),%rcx
movzbl 0x2(%rcx),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
movzbl 0x3(%rcx),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
mov    %eax,-0x124(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x4(%rax),%eax
mov    -0x10(%rbp),%rcx
movzbl 0x5(%rcx),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
movzbl 0x6(%rcx),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
mov    %eax,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xc58(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
jmp    13eb <send_data+0x26b>
mov    -0x10(%rbp),%rax
movzbl (%rax),%esi
lea    0xc48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x120(%rbp),%rsi
mov    -0x124(%rbp),%edx
mov    -0x124(%rbp),%ecx
add    -0x128(%rbp),%ecx
lea    0xc38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x120(%rbp),%rdi
mov    0x2bc8(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x130(%rbp)
cmpl   $0x0,-0x130(%rbp)
jge    1465 <send_data+0x2e5>
mov    0x2b97(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    -0x120(%rbp),%rdx
lea    0xc0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    15ea <send_data+0x46a>
cmpl   $0x0,-0x124(%rbp)
je     14be <send_data+0x33e>
mov    -0x130(%rbp),%edi
mov    -0x124(%rbp),%esi
mov    0x2b4b(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
jne    14b9 <send_data+0x339>
mov    0x2b3c(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xbc7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    15ea <send_data+0x46a>
jmp    14be <send_data+0x33e>
mov    -0x128(%rbp),%eax
cmp    -0x12c(%rbp),%eax
jge    14dc <send_data+0x35c>
mov    -0x128(%rbp),%eax
mov    %eax,-0x12c(%rbp)
jmp    14e1 <send_data+0x361>
cmpl   $0x0,-0x128(%rbp)
jle    15d1 <send_data+0x451>
mov    -0x130(%rbp),%edi
lea    -0x1130(%rbp),%rsi
mov    -0x12c(%rbp),%edx
call   1070 <read@plt>
mov    %eax,-0x1134(%rbp)
mov    -0x1134(%rbp),%eax
cmp    -0x12c(%rbp),%eax
je     1549 <send_data+0x3c9>
mov    0x2ab3(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    -0x120(%rbp),%rdx
lea    0xb5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    15ea <send_data+0x46a>
mov    -0x4(%rbp),%edi
lea    -0x1130(%rbp),%rsi
mov    -0x12c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x1134(%rbp)
mov    -0x1134(%rbp),%eax
cmp    -0x12c(%rbp),%eax
je     159a <send_data+0x41a>
mov    0x2a5b(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xb20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    15ea <send_data+0x46a>
mov    -0x12c(%rbp),%ecx
mov    -0x128(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x128(%rbp)
mov    -0x128(%rbp),%eax
cmp    -0x12c(%rbp),%eax
jge    15cc <send_data+0x44c>
mov    -0x128(%rbp),%eax
mov    %eax,-0x12c(%rbp)
jmp    14e1 <send_data+0x361>
mov    -0x130(%rbp),%edi
call   1060 <close@plt>
lea    0xab3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x1140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_data>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1100,%rsp
mov    %edi,%r14d
mov    (%rsi),%al
cmp    $0x4,%al
jg     11db <send_data+0x4b>
cmp    $0x89,%al
je     11f6 <send_data+0x66>
cmp    $0x96,%al
jne    1239 <send_data+0xa9>
movzbl 0x1(%rsi),%ecx
lea    0xe4f(%rip),%rsi
xor    %r15d,%r15d
mov    %rsp,%rdi
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    $0xc,%ebp
mov    $0x200,%ebx
jmp    12a5 <send_data+0x115>
cmp    $0x15,%al
je     1203 <send_data+0x73>
cmp    $0x5,%al
jne    1239 <send_data+0xa9>
movzwl 0x4(%rsi),%ebx
cmpb   $0x9d,0x1(%rsi)
jne    1259 <send_data+0xc9>
lea    0xe0c(%rip),%rsi
jmp    1260 <send_data+0xd0>
movzwl 0x5(%rsi),%ebx
lea    0xe19(%rip),%rsi
jmp    1260 <send_data+0xd0>
movzwl 0x1(%rsi),%eax
movzbl 0x3(%rsi),%r15d
shl    $0x10,%r15d
or     %eax,%r15d
movzbl 0x4(%rsi),%eax
cmp    $0x4,%ecx
jne    1274 <send_data+0xe4>
shl    $0x18,%eax
or     %eax,%r15d
movzwl 0x5(%rsi),%edi
movzbl 0x7(%rsi),%eax
shl    $0x10,%eax
mov    $0x18,%ecx
mov    $0x8,%ebp
jmp    1285 <send_data+0xf5>
movzbl %al,%esi
lea    0xde9(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xc,%ebp
mov    $0xffffffff,%ebx
jmp    12a5 <send_data+0x115>
lea    0xda7(%rip),%rsi
xor    %r15d,%r15d
mov    %rsp,%rdi
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    $0xc,%ebp
jmp    12a5 <send_data+0x115>
movzbl 0x5(%rsi),%edi
shl    $0x8,%edi
mov    $0x10,%ecx
mov    $0x6,%ebp
or     %edi,%eax
movzbl (%rsi,%rbp,1),%ebx
shl    %cl,%ebx
or     %eax,%ebx
lea    0xd8c(%rip),%rsi
mov    %rsp,%rdi
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    $0x1000,%ebp
lea    (%r15,%rbx,1),%ecx
lea    0xd93(%rip),%rdi
mov    %rsp,%r12
mov    %r12,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1351 <send_data+0x1c1>
mov    %eax,%r12d
test   %r15d,%r15d
je     12f6 <send_data+0x166>
mov    0x2cec(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
mov    %r15d,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
je     1368 <send_data+0x1d8>
test   %ebx,%ebx
jle    133d <send_data+0x1ad>
cmp    %ebp,%ebx
cmovb  %ebx,%ebp
lea    0x100(%rsp),%r15
nopw   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %r15,%rsi
mov    %ebp,%edx
call   1080 <read@plt>
cmp    %ebp,%eax
jne    137f <send_data+0x1ef>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
cmp    %ebp,%eax
jne    13a3 <send_data+0x213>
sub    %ebp,%ebx
cmp    %ebp,%ebx
cmovl  %ebx,%ebp
test   %ebx,%ebx
jg     1310 <send_data+0x180>
mov    %r12d,%edi
call   1070 <close@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    13c2 <send_data+0x232>
mov    0x2c80(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xcfe(%rip),%rdi
jmp    1394 <send_data+0x204>
mov    0x2c69(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xcf7(%rip),%rdi
jmp    13b8 <send_data+0x228>
mov    0x2c52(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd04(%rip),%rdi
mov    %rsp,%rdx
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    13c2 <send_data+0x232>
mov    0x2c2e(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xcf6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%s/id0\00"
@.str.1 = [7 x i8] c"%s/id1\00"
@.str.2 = [12 x i8] c"%s/config%d\00"
@.str.3 = [8 x i8] c"%s/misc\00"
@.str.4 = [10 x i8] c"%s/memory\00"
@.str.5 = [23 x i8] c"Unknown command %02x.\0A\00"
@.str.6 = [33 x i8] c"Sending file %s, bytes (%d - %d)\00"
@O_RDONLY = global i32 0
@.str.7 = [16 x i8] c"%s: opening %s\0A\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.8 = [36 x i8] c"%s while positioning file pointer.\0A\00"
@.str.9 = [22 x i8] c"%s: error reading %s\0A\00"
@.str.10 = [19 x i8] c"%3: error writing\0A\00"
@.str.11 = [2 x i8] c"\0A\00"
define void @send_data(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [256 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [4096 x i8]
%15 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 0, i32* %10
store i32 -1, i32* %11
store i32 12, i32* %12
%16 = load i8*, i8** %6
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
switch i32 %19, label %170 [
i32 5, label %20
i32 150, label %47
i32 137, label %55
i32 21, label %71
]
20: ; preds = %4
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 4
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i64 4
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = shl i32 %30, 8
%32 = add i32 %25, %31
store i32 %32, i32* %11
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = icmp eq i32 %36, 157
br i1 %37, label %38, label %42
38: ; preds = %20
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%40 = load i8*, i8** %7
%41 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %40)
br label %46
42: ; preds = %20
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%44 = load i8*, i8** %7
%45 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %43, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %42, %38
br label %176
47: ; preds = %4
store i32 512, i32* %11
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%49 = load i8*, i8** %7
%50 = load i8*, i8** %6
%51 = getelementptr inbounds i8, i8* %50, i64 1
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %48, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %49, i32 %53)
br label %176
55: ; preds = %4
%56 = load i8*, i8** %6
%57 = getelementptr inbounds i8, i8* %56, i64 5
%58 = getelementptr inbounds i8, i8* %57, i64 0
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = load i8*, i8** %6
%62 = getelementptr inbounds i8, i8* %61, i64 5
%63 = getelementptr inbounds i8, i8* %62, i64 1
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
%66 = shl i32 %65, 8
%67 = add i32 %60, %66
store i32 %67, i32* %11
%68 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%69 = load i8*, i8** %7
%70 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %68, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %69)
br label %176
71: ; preds = %4
store i32 4096, i32* %12
%72 = load i32, i32* %8
%73 = icmp eq i32 %72, 4
br i1 %73, label %74, label %127
74: ; preds = %71
%75 = load i8*, i8** %6
%76 = getelementptr inbounds i8, i8* %75, i64 1
%77 = getelementptr inbounds i8, i8* %76, i64 0
%78 = load i8, i8* %77
%79 = zext i8 %78 to i32
%80 = load i8*, i8** %6
%81 = getelementptr inbounds i8, i8* %80, i64 1
%82 = getelementptr inbounds i8, i8* %81, i64 1
%83 = load i8, i8* %82
%84 = zext i8 %83 to i32
%85 = shl i32 %84, 8
%86 = add i32 %79, %85
%87 = load i8*, i8** %6
%88 = getelementptr inbounds i8, i8* %87, i64 1
%89 = getelementptr inbounds i8, i8* %88, i64 2
%90 = load i8, i8* %89
%91 = zext i8 %90 to i32
%92 = shl i32 %91, 16
%93 = add i32 %86, %92
%94 = load i8*, i8** %6
%95 = getelementptr inbounds i8, i8* %94, i64 1
%96 = getelementptr inbounds i8, i8* %95, i64 3
%97 = load i8, i8* %96
%98 = zext i8 %97 to i32
%99 = shl i32 %98, 24
%100 = add i32 %93, %99
store i32 %100, i32* %10
%101 = load i8*, i8** %6
%102 = getelementptr inbounds i8, i8* %101, i64 5
%103 = getelementptr inbounds i8, i8* %102, i64 0
%104 = load i8, i8* %103
%105 = zext i8 %104 to i32
%106 = load i8*, i8** %6
%107 = getelementptr inbounds i8, i8* %106, i64 5
%108 = getelementptr inbounds i8, i8* %107, i64 1
%109 = load i8, i8* %108
%110 = zext i8 %109 to i32
%111 = shl i32 %110, 8
%112 = add i32 %105, %111
%113 = load i8*, i8** %6
%114 = getelementptr inbounds i8, i8* %113, i64 5
%115 = getelementptr inbounds i8, i8* %114, i64 2
%116 = load i8, i8* %115
%117 = zext i8 %116 to i32
%118 = shl i32 %117, 16
%119 = add i32 %112, %118
%120 = load i8*, i8** %6
%121 = getelementptr inbounds i8, i8* %120, i64 5
%122 = getelementptr inbounds i8, i8* %121, i64 3
%123 = load i8, i8* %122
%124 = zext i8 %123 to i32
%125 = shl i32 %124, 24
%126 = add i32 %119, %125
store i32 %126, i32* %11
br label %166
127: ; preds = %71
%128 = load i8*, i8** %6
%129 = getelementptr inbounds i8, i8* %128, i64 1
%130 = getelementptr inbounds i8, i8* %129, i64 0
%131 = load i8, i8* %130
%132 = zext i8 %131 to i32
%133 = load i8*, i8** %6
%134 = getelementptr inbounds i8, i8* %133, i64 1
%135 = getelementptr inbounds i8, i8* %134, i64 1
%136 = load i8, i8* %135
%137 = zext i8 %136 to i32
%138 = shl i32 %137, 8
%139 = add i32 %132, %138
%140 = load i8*, i8** %6
%141 = getelementptr inbounds i8, i8* %140, i64 1
%142 = getelementptr inbounds i8, i8* %141, i64 2
%143 = load i8, i8* %142
%144 = zext i8 %143 to i32
%145 = shl i32 %144, 16
%146 = add i32 %139, %145
store i32 %146, i32* %10
%147 = load i8*, i8** %6
%148 = getelementptr inbounds i8, i8* %147, i64 4
%149 = getelementptr inbounds i8, i8* %148, i64 0
%150 = load i8, i8* %149
%151 = zext i8 %150 to i32
%152 = load i8*, i8** %6
%153 = getelementptr inbounds i8, i8* %152, i64 4
%154 = getelementptr inbounds i8, i8* %153, i64 1
%155 = load i8, i8* %154
%156 = zext i8 %155 to i32
%157 = shl i32 %156, 8
%158 = add i32 %151, %157
%159 = load i8*, i8** %6
%160 = getelementptr inbounds i8, i8* %159, i64 4
%161 = getelementptr inbounds i8, i8* %160, i64 2
%162 = load i8, i8* %161
%163 = zext i8 %162 to i32
%164 = shl i32 %163, 16
%165 = add i32 %158, %164
store i32 %165, i32* %11
br label %166
166: ; preds = %127, %74
%167 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%168 = load i8*, i8** %7
%169 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %167, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %168)
br label %176
170: ; preds = %4
%171 = load i8*, i8** %6
%172 = getelementptr inbounds i8, i8* %171, i64 0
%173 = load i8, i8* %172
%174 = zext i8 %173 to i32
%175 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %174)
br label %176
176: ; preds = %170, %166, %55, %47, %46
%177 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%178 = load i32, i32* %10
%179 = load i32, i32* %10
%180 = load i32, i32* %11
%181 = add nsw i32 %179, %180
%182 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %177, i32 %178, i32 %181)
%183 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%184 = load i32, i32* @O_RDONLY
%185 = call i32 @open(i8* %183, i32 %184)
store i32 %185, i32* %13
%186 = load i32, i32* %13
%187 = icmp slt i32 %186, 0
br i1 %187, label %188, label %193
188: ; preds = %176
%189 = load i32, i32* @errno
%190 = call i8* @strerror(i32 %189)
%191 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%192 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %190, i8* %191)
br label %256
193: ; preds = %176
%194 = load i32, i32* %10
%195 = icmp ne i32 %194, 0
br i1 %195, label %196, label %207
196: ; preds = %193
%197 = load i32, i32* %13
%198 = load i32, i32* %10
%199 = load i32, i32* @SEEK_SET
%200 = call i32 @lseek(i32 %197, i32 %198, i32 %199)
%201 = icmp eq i32 %200, -1
br i1 %201, label %202, label %206
202: ; preds = %196
%203 = load i32, i32* @errno
%204 = call i8* @strerror(i32 %203)
%205 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), i8* %204)
br label %256
206: ; preds = %196
br label %207
207: ; preds = %206, %193
%208 = load i32, i32* %11
%209 = load i32, i32* %12
%210 = icmp slt i32 %208, %209
br i1 %210, label %211, label %213
211: ; preds = %207
%212 = load i32, i32* %11
store i32 %212, i32* %12
br label %213
213: ; preds = %211, %207
br label %214
214: ; preds = %251, %213
%215 = load i32, i32* %11
%216 = icmp sgt i32 %215, 0
br i1 %216, label %217, label %252
217: ; preds = %214
%218 = load i32, i32* %13
%219 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%220 = load i32, i32* %12
%221 = call i32 @read(i32 %218, i8* %219, i32 %220)
store i32 %221, i32* %15
%222 = load i32, i32* %15
%223 = load i32, i32* %12
%224 = icmp ne i32 %222, %223
br i1 %224, label %225, label %230
225: ; preds = %217
%226 = load i32, i32* @errno
%227 = call i8* @strerror(i32 %226)
%228 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%229 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* %227, i8* %228)
br label %256
230: ; preds = %217
%231 = load i32, i32* %5
%232 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%233 = load i32, i32* %12
%234 = call i32 @write(i32 %231, i8* %232, i32 %233)
store i32 %234, i32* %15
%235 = load i32, i32* %15
%236 = load i32, i32* %12
%237 = icmp ne i32 %235, %236
br i1 %237, label %238, label %242
238: ; preds = %230
%239 = load i32, i32* @errno
%240 = call i8* @strerror(i32 %239)
%241 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i8* %240)
br label %256
242: ; preds = %230
%243 = load i32, i32* %12
%244 = load i32, i32* %11
%245 = sub nsw i32 %244, %243
store i32 %245, i32* %11
%246 = load i32, i32* %11
%247 = load i32, i32* %12
%248 = icmp slt i32 %246, %247
br i1 %248, label %249, label %251
249: ; preds = %242
%250 = load i32, i32* %11
store i32 %250, i32* %12
br label %251
251: ; preds = %249, %242
br label %214
252: ; preds = %214
%253 = load i32, i32* %13
%254 = call i32 @close(i32 %253)
%255 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
br label %256
256: ; preds = %252, %238, %225, %202, %188
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s/id0\00"
@.str.1 = [7 x i8] c"%s/id1\00"
@.str.2 = [12 x i8] c"%s/config%d\00"
@.str.3 = [8 x i8] c"%s/misc\00"
@.str.4 = [10 x i8] c"%s/memory\00"
@.str.5 = [23 x i8] c"Unknown command %02x.\0A\00"
@.str.6 = [33 x i8] c"Sending file %s, bytes (%d - %d)\00"
@O_RDONLY = global i32 0
@.str.7 = [16 x i8] c"%s: opening %s\0A\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.8 = [36 x i8] c"%s while positioning file pointer.\0A\00"
@.str.9 = [22 x i8] c"%s: error reading %s\0A\00"
@.str.10 = [19 x i8] c"%3: error writing\0A\00"
define void @send_data(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [256 x i8]
%6 = alloca [4096 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%9 = load i8, i8* %1
switch i8 %9, label %92 [
i8 5, label %10
i8 -106, label %26
i8 -119, label %31
i8 21, label %41
]
10: ; preds = %4
%11 = getelementptr inbounds i8, i8* %1, i64 4
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = getelementptr inbounds i8, i8* %1, i64 5
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = shl nuw nsw i32 %16, 8
%18 = or i32 %17, %13
%19 = getelementptr inbounds i8, i8* %1, i64 1
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, -99
br i1 %21, label %22, label %24
22: ; preds = %10
%23 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %95
24: ; preds = %10
%25 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %95
26: ; preds = %4
%27 = getelementptr inbounds i8, i8* %1, i64 1
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %2, i32 %29)
br label %95
31: ; preds = %4
%32 = getelementptr inbounds i8, i8* %1, i64 5
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = getelementptr inbounds i8, i8* %1, i64 6
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = shl nuw nsw i32 %37, 8
%39 = or i32 %38, %34
%40 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %95
41: ; preds = %4
%42 = icmp eq i32 %3, 4
%43 = getelementptr inbounds i8, i8* %1, i64 1
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = getelementptr inbounds i8, i8* %1, i64 2
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = shl nuw nsw i32 %48, 8
%50 = or i32 %49, %45
%51 = getelementptr inbounds i8, i8* %1, i64 3
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = shl nuw nsw i32 %53, 16
%55 = or i32 %50, %54
%56 = getelementptr inbounds i8, i8* %1, i64 4
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
br i1 %42, label %59, label %74
59: ; preds = %41
%60 = shl nuw i32 %58, 24
%61 = or i32 %55, %60
%62 = getelementptr inbounds i8, i8* %1, i64 5
%63 = load i8, i8* %62
%64 = zext i8 %63 to i32
%65 = getelementptr inbounds i8, i8* %1, i64 6
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = shl nuw nsw i32 %67, 8
%69 = or i32 %68, %64
%70 = getelementptr inbounds i8, i8* %1, i64 7
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = shl nuw nsw i32 %72, 16
br label %79
74: ; preds = %41
%75 = getelementptr inbounds i8, i8* %1, i64 5
%76 = load i8, i8* %75
%77 = zext i8 %76 to i32
%78 = shl nuw nsw i32 %77, 8
br label %79
79: ; preds = %74, %59
%80 = phi i32 [ %58, %74 ], [ %73, %59 ]
%81 = phi i32 [ %78, %74 ], [ %69, %59 ]
%82 = phi i64 [ 6, %74 ], [ 8, %59 ]
%83 = phi i32 [ 16, %74 ], [ 24, %59 ]
%84 = phi i32 [ %55, %74 ], [ %61, %59 ]
%85 = or i32 %81, %80
%86 = getelementptr inbounds i8, i8* %1, i64 %82
%87 = load i8, i8* %86
%88 = zext i8 %87 to i32
%89 = shl nuw i32 %88, %83
%90 = or i32 %85, %89
%91 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %2)
br label %95
92: ; preds = %4
%93 = zext i8 %9 to i32
%94 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %93)
br label %95
95: ; preds = %22, %24, %92, %79, %31, %26
%96 = phi i32 [ -1, %92 ], [ %90, %79 ], [ %39, %31 ], [ 512, %26 ], [ %18, %22 ], [ %18, %24 ]
%97 = phi i32 [ 12, %92 ], [ 4096, %79 ], [ 12, %31 ], [ 12, %26 ], [ 12, %22 ], [ 12, %24 ]
%98 = phi i32 [ 0, %92 ], [ %84, %79 ], [ 0, %31 ], [ 0, %26 ], [ 0, %22 ], [ 0, %24 ]
%99 = add nsw i32 %98, %96
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %7, i32 %98, i32 %99)
%101 = load i32, i32* @O_RDONLY
%102 = call i32 @open(i8* %7, i32 %101)
%103 = icmp slt i32 %102, 0
br i1 %103, label %104, label %108
104: ; preds = %95
%105 = load i32, i32* @errno
%106 = call i8* @strerror(i32 %105)
%107 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %106, i8* %7)
br label %147
108: ; preds = %95
%109 = icmp eq i32 %98, 0
br i1 %109, label %118, label %110
110: ; preds = %108
%111 = load i32, i32* @SEEK_SET
%112 = call i32 @lseek(i32 %102, i32 %98, i32 %111)
%113 = icmp eq i32 %112, -1
br i1 %113, label %114, label %118
114: ; preds = %110
%115 = load i32, i32* @errno
%116 = call i8* @strerror(i32 %115)
%117 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), i8* %116)
br label %147
118: ; preds = %110, %108
%119 = icmp sgt i32 %96, 0
br i1 %119, label %120, label %144
120: ; preds = %118
%121 = icmp ult i32 %96, %97
%122 = select i1 %121, i32 %96, i32 %97
br label %123
123: ; preds = %120, %139
%124 = phi i32 [ %142, %139 ], [ %122, %120 ]
%125 = phi i32 [ %140, %139 ], [ %96, %120 ]
%126 = call i32 @read(i32 %102, i8* %8, i32 %124)
%127 = icmp eq i32 %126, %124
br i1 %127, label %132, label %128
128: ; preds = %123
%129 = load i32, i32* @errno
%130 = call i8* @strerror(i32 %129)
%131 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* %130, i8* %7)
br label %147
132: ; preds = %123
%133 = call i32 @write(i32 %0, i8* %8, i32 %124)
%134 = icmp eq i32 %133, %124
br i1 %134, label %139, label %135
135: ; preds = %132
%136 = load i32, i32* @errno
%137 = call i8* @strerror(i32 %136)
%138 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i8* %137)
br label %147
139: ; preds = %132
%140 = sub nsw i32 %125, %124
%141 = icmp slt i32 %140, %124
%142 = select i1 %141, i32 %140, i32 %124
%143 = icmp sgt i32 %140, 0
br i1 %143, label %123, label %144
144: ; preds = %139, %118
%145 = call i32 @close(i32 %102)
%146 = call i32 @putchar(i32 10)
br label %147
147: ; preds = %135, %128, %144, %114, %104
ret void
}