#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 int /*<<< orphan*/ data;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ *openfile(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
char toupper(char);
main(int argc, char *argv[]) {
  FILE *fd = NULL;
  char buffer[257], data[256], *remoteip, input;
  size_t count;
  int quit = 0, ch;
  if (argc < 2) {
    printf("Error: please indicate whether this is the [t]arget or [d]ebug "
           "machine as an argument.");
    return 0;
  }
  if (argv[1][0] == 't') {
    remoteip = "192.168.5.128";
  } else {
    remoteip = "192.168.5.130";
  }
  printf("Using destination address: %s\n", remoteip);
  memset(buffer, 0, 257);
  buffer[0] = 1;
  memcpy(buffer + 1, remoteip, strlen(remoteip) + 1);
  fd = openfile("wb");
  if (!fd) {
    exit(1);
  }
  fwrite(buffer, 1, 30, fd);
  fclose(fd);
  while (quit == 0) {
    printf("\n********Main Menu********\n");
    printf("  (D) Set destination address\n");
    printf("  (W) Write to the device\n");
    printf("  (R) Read from the device\n");
    printf("  (Q) Quit\n");
    scanf("%c", &input);
    input = toupper(input);
    while ((ch = fgetc(stdin)) != EOF && ch != '\n') {
    }
    switch (input) {
    case 'D':
      printf("Please destination IP address (ex. 192.168.67.51):\n");
      scanf("%256s", data);
      while ((ch = fgetc(stdin)) != EOF && ch != '\n') {
      }
      memset(buffer, 0, 257);
      buffer[0] = 1;
      memcpy(buffer + 1, data, strlen(data) + 1);
      fd = openfile("wb");
      if (fd) {
        fwrite(buffer, 1, strlen(data) + 1, fd);
        printf("Destination address set to: %s\n", data);
        fclose(fd);
      }
      break;
    case 'W':
      printf("Please input string:\n");
      scanf("%256s", data);
      while ((ch = fgetc(stdin)) != EOF && ch != '\n') {
      }
      memset(buffer, 0, 257);
      buffer[0] = 2;
      memcpy(buffer + 1, data, strlen(data) + 1);
      fd = openfile("wb");
      if (fd) {
        fwrite(buffer, 1, strlen(data) + 1, fd);
        printf("Message sent: %s\n", data);
        fclose(fd);
      }
      break;
    case 'R':
      fd = openfile("rb");
      if (fd) {
        count = fread(data, 1, sizeof(data) - 1, fd);
        if (!count)
          printf("No data read\n");
        else
          printf("%s\n", data);
        fclose(fd);
      }
      break;
    case 'Q':
      quit = 1;
      break;
    default:
      printf("Unknown Entry\n");
      break;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x23c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    120f <main+0x4f>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    172d <main+0x56d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x74,%eax
jne    1236 <main+0x76>
lea    0xe7d(%rip),%rax
mov    %rax,-0x228(%rbp)
jmp    1244 <main+0x84>
lea    0xe78(%rip),%rax
mov    %rax,-0x228(%rbp)
mov    -0x228(%rbp),%rsi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1090 <memset@plt>
movb   $0x1,-0x120(%rbp)
lea    -0x120(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x250(%rbp)
mov    -0x228(%rbp),%rax
mov    %rax,-0x248(%rbp)
mov    -0x228(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x250(%rbp),%rdi
mov    -0x248(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   10b0 <memcpy@plt>
lea    0xe24(%rip),%rdi
call   1030 <openfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12dc <main+0x11c>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1e,%edx
call   10e0 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
cmpl   $0x0,-0x23c(%rbp)
jne    172d <main+0x56d>
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xe0a(%rip),%rdi
lea    -0x229(%rbp),%rsi
call   10c0 <scanf@plt>
movsbl -0x229(%rbp),%edi
call   1040 <toupper@plt>
mov    %al,-0x229(%rbp)
mov    0x2c6a(%rip),%rax
mov    (%rax),%edi
call   10a0 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x240(%rbp)
xor    %eax,%eax
mov    0x2c4a(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x251(%rbp)
je     13b4 <main+0x1f4>
cmpl   $0xa,-0x240(%rbp)
setne  %al
mov    %al,-0x251(%rbp)
mov    -0x251(%rbp),%al
test   $0x1,%al
jne    13c7 <main+0x207>
jmp    13cc <main+0x20c>
jmp    1377 <main+0x1b7>
movsbl -0x229(%rbp),%eax
add    $0xffffffbc,%eax
mov    %eax,%ecx
mov    %rcx,-0x260(%rbp)
sub    $0x13,%eax
ja     171a <main+0x55a>
mov    -0x260(%rbp),%rax
lea    0xc0a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x220(%rbp),%rsi
lea    0xd7f(%rip),%rdi
call   10c0 <scanf@plt>
mov    0x2bc1(%rip),%rax
mov    (%rax),%edi
call   10a0 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x240(%rbp)
xor    %eax,%eax
mov    0x2ba1(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x261(%rbp)
je     145d <main+0x29d>
cmpl   $0xa,-0x240(%rbp)
setne  %al
mov    %al,-0x261(%rbp)
mov    -0x261(%rbp),%al
test   $0x1,%al
jne    1470 <main+0x2b0>
jmp    1475 <main+0x2b5>
jmp    1420 <main+0x260>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1090 <memset@plt>
movb   $0x1,-0x120(%rbp)
lea    -0x120(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x278(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x270(%rbp)
lea    -0x220(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x278(%rbp),%rdi
mov    -0x270(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   10b0 <memcpy@plt>
lea    0xc08(%rip),%rdi
call   1030 <openfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1540 <main+0x380>
lea    -0x120(%rbp),%rax
mov    %rax,-0x280(%rbp)
lea    -0x220(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x280(%rbp),%rdi
mov    %eax,%edx
add    $0x1,%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
lea    -0x220(%rbp),%rsi
lea    0xc70(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
jmp    1728 <main+0x568>
lea    0xc74(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x220(%rbp),%rsi
lea    0xc39(%rip),%rdi
call   10c0 <scanf@plt>
mov    0x2a7b(%rip),%rax
mov    (%rax),%edi
call   10a0 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x240(%rbp)
xor    %eax,%eax
mov    0x2a5b(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x281(%rbp)
je     15a3 <main+0x3e3>
cmpl   $0xa,-0x240(%rbp)
setne  %al
mov    %al,-0x281(%rbp)
mov    -0x281(%rbp),%al
test   $0x1,%al
jne    15b6 <main+0x3f6>
jmp    15bb <main+0x3fb>
jmp    1566 <main+0x3a6>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1090 <memset@plt>
movb   $0x2,-0x120(%rbp)
lea    -0x120(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x298(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x290(%rbp)
lea    -0x220(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x298(%rbp),%rdi
mov    -0x290(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   10b0 <memcpy@plt>
lea    0xac2(%rip),%rdi
call   1030 <openfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1686 <main+0x4c6>
lea    -0x120(%rbp),%rax
mov    %rax,-0x2a0(%rbp)
lea    -0x220(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x2a0(%rbp),%rdi
mov    %eax,%edx
add    $0x1,%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
lea    -0x220(%rbp),%rsi
lea    0xb60(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
jmp    1728 <main+0x568>
lea    0xb56(%rip),%rdi
call   1030 <openfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1706 <main+0x546>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0xff,%edx
call   1050 <fread@plt>
mov    %rax,-0x238(%rbp)
cmpq   $0x0,-0x238(%rbp)
jne    16e8 <main+0x528>
lea    0xb0f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    16fd <main+0x53d>
lea    -0x220(%rbp),%rsi
lea    0xac6(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
jmp    1728 <main+0x568>
movl   $0x1,-0x23c(%rbp)
jmp    1728 <main+0x568>
lea    0xad8(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    12ff <main+0x13f>
mov    -0x4(%rbp),%eax
add    $0x2a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
cmp    $0x1,%edi
jg     1208 <main+0x38>
lea    0xe63(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
xor    %eax,%eax
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsi),%rax
cmpb   $0x74,(%rax)
lea    0xe91(%rip),%rax
lea    0xe98(%rip),%rbx
cmove  %rax,%rbx
lea    0xe9b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   10a0 <memset@plt>
movb   $0x1,0x10(%rsp)
lea    0x11(%rsp),%rbp
mov    %rbx,%rdi
call   1080 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10c0 <memcpy@plt>
lea    0xe78(%rip),%rdi
call   1030 <openfile@plt>
test   %rax,%rax
je     1511 <main+0x341>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1e,%edx
mov    %rax,%rcx
call   10f0 <fwrite@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
lea    0xf(%rsp),%r12
mov    0x2d42(%rip),%rbp
mov    0x2d33(%rip),%r14
lea    0xd4c(%rip),%r15
lea    0x120(%rsp),%r13
jmp    12cc <main+0xfc>
xchg   %ax,%ax
lea    0xf2a(%rip),%rdi
call   1050 <puts@plt>
lea    0xe50(%rip),%rdi
call   1050 <puts@plt>
lea    0xe5f(%rip),%rdi
call   1050 <puts@plt>
lea    0xe71(%rip),%rdi
call   1050 <puts@plt>
lea    0xe7f(%rip),%rdi
call   1050 <puts@plt>
lea    0xe8e(%rip),%rdi
call   1050 <puts@plt>
lea    0xdd6(%rip),%rdi
mov    %r12,%rsi
call   10d0 <scanf@plt>
movsbl 0xf(%rsp),%edi
call   1040 <toupper@plt>
mov    %al,0xf(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%rbp),%edi
call   10b0 <fgetc@plt>
cmp    $0xa,%eax
je     1342 <main+0x172>
cmp    (%r14),%eax
jne    1330 <main+0x160>
movsbl 0xf(%rsp),%eax
add    $0xffffffbc,%eax
cmp    $0x13,%eax
ja     12c0 <main+0xf0>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
lea    0xe5b(%rip),%rdi
call   1050 <puts@plt>
lea    0xd79(%rip),%rdi
mov    %r13,%rsi
call   10d0 <scanf@plt>
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp),%edi
call   10b0 <fgetc@plt>
cmp    $0xa,%eax
je     1392 <main+0x1c2>
cmp    (%r14),%eax
jne    1380 <main+0x1b0>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   10a0 <memset@plt>
movb   $0x1,0x10(%rsp)
mov    %r13,%rdi
call   1080 <strlen@plt>
lea    0x1(%rax),%edx
lea    0x11(%rsp),%rdi
mov    %r13,%rsi
call   10c0 <memcpy@plt>
lea    0xd1b(%rip),%rdi
call   1030 <openfile@plt>
test   %rax,%rax
je     12cc <main+0xfc>
mov    %rax,%rbx
mov    %r13,%rdi
call   1080 <strlen@plt>
lea    0x1(%rax),%edx
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   10f0 <fwrite@plt>
lea    0xcf2(%rip),%rdi
jmp    14ec <main+0x31c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xd09(%rip),%rdi
call   1030 <openfile@plt>
test   %rax,%rax
je     12cc <main+0xfc>
mov    %rax,%rbx
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0xff,%edx
mov    %rax,%rcx
call   1060 <fread@plt>
test   %rax,%rax
je     14f8 <main+0x328>
mov    %r13,%rdi
jmp    14ff <main+0x32f>
xchg   %ax,%ax
lea    0xd52(%rip),%rdi
call   1050 <puts@plt>
lea    0xc85(%rip),%rdi
mov    %r13,%rsi
call   10d0 <scanf@plt>
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%edi
call   10b0 <fgetc@plt>
cmp    $0xa,%eax
je     1482 <main+0x2b2>
cmp    (%r14),%eax
jne    1470 <main+0x2a0>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   10a0 <memset@plt>
movb   $0x2,0x10(%rsp)
mov    %r13,%rdi
call   1080 <strlen@plt>
lea    0x1(%rax),%edx
lea    0x11(%rsp),%rdi
mov    %r13,%rsi
call   10c0 <memcpy@plt>
lea    0xc2b(%rip),%rdi
call   1030 <openfile@plt>
test   %rax,%rax
je     12cc <main+0xfc>
mov    %rax,%rbx
mov    %r13,%rdi
call   1080 <strlen@plt>
lea    0x1(%rax),%edx
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   10f0 <fwrite@plt>
lea    0xc22(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
jmp    1504 <main+0x334>
lea    0xc9d(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
jmp    12cc <main+0xfc>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [87 x i8] c"Error: please indicate whether this is the [t]arget or [d]ebug machine as an argument.\00"
@.str.1 = [14 x i8] c"192.168.5.128\00"
@.str.2 = [14 x i8] c"192.168.5.130\00"
@.str.3 = [31 x i8] c"Using destination address: %s\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [28 x i8] c"\0A********Main Menu********\0A\00"
@.str.6 = [31 x i8] c" (D) Set destination address\0A\00"
@.str.7 = [27 x i8] c" (W) Write to the device\0A\00"
@.str.8 = [28 x i8] c" (R) Read from the device\0A\00"
@.str.9 = [12 x i8] c" (Q) Quit\0A\00"
@.str.10 = [3 x i8] c"%c\00"
@stdin = global i32 0
@EOF = global i32 0
@.str.11 = [52 x i8] c"Please destination IP address (ex. 192.168.67.51):\0A\00"
@.str.12 = [6 x i8] c"%256s\00"
@.str.13 = [32 x i8] c"Destination address set to: %s\0A\00"
@.str.14 = [22 x i8] c"Please input string:\0A\00"
@.str.15 = [18 x i8] c"Message sent: %s\0A\00"
@.str.16 = [3 x i8] c"rb\00"
@.str.17 = [14 x i8] c"No data read\0A\00"
@.str.18 = [4 x i8] c"%s\0A\00"
@.str.19 = [15 x i8] c"Unknown Entry\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [257 x i8]
%8 = alloca [256 x i8]
%9 = alloca i8*
%10 = alloca i8
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32 0, i32* %12
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %183
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 116
br i1 %25, label %26, label %27
26: ; preds = %18
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %9
br label %28
27: ; preds = %18
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8** %9
br label %28
28: ; preds = %27, %26
%29 = load i8*, i8** %9
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%32 = call i32 @memset(i8* %31, i32 0, i32 257)
%33 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
store i8 1, i8* %33
%34 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8*, i8** %9
%37 = load i8*, i8** %9
%38 = call i32 @strlen(i8* %37)
%39 = add nsw i32 %38, 1
%40 = call i32 @memcpy(i8* %35, i8* %36, i32 %39)
%41 = call i32* @openfile(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %41, i32** %6
%42 = load i32*, i32** %6
%43 = icmp ne i32* %42, null
br i1 %43, label %46, label %44
44: ; preds = %28
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %28
%47 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%48 = load i32*, i32** %6
%49 = call i32 @fwrite(i8* %47, i32 1, i32 30, i32* %48)
%50 = load i32*, i32** %6
%51 = call i32 @fclose(i32* %50)
br label %52
52: ; preds = %182, %46
%53 = load i32, i32* %12
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %183
55: ; preds = %52
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
%61 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8* %10)
%62 = load i8, i8* %10
%63 = call signext i8 @toupper(i8 signext %62)
store i8 %63, i8* %10
br label %64
64: ; preds = %74, %55
%65 = load i32, i32* @stdin
%66 = call i32 @fgetc(i32 %65)
store i32 %66, i32* %13
%67 = load i32, i32* @EOF
%68 = icmp ne i32 %66, %67
br i1 %68, label %69, label %72
69: ; preds = %64
%70 = load i32, i32* %13
%71 = icmp ne i32 %70, 10
br label %72
72: ; preds = %69, %64
%73 = phi i1 [ false, %64 ], [ %71, %69 ]
br i1 %73, label %74, label %75
74: ; preds = %72
br label %64
75: ; preds = %72
%76 = load i8, i8* %10
%77 = sext i8 %76 to i32
switch i32 %77, label %180 [
i32 68, label %78
i32 87, label %119
i32 82, label %160
i32 81, label %179
]
78: ; preds = %75
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.11, i64 0, i64 0))
%80 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%81 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i8* %80)
br label %82
82: ; preds = %92, %78
%83 = load i32, i32* @stdin
%84 = call i32 @fgetc(i32 %83)
store i32 %84, i32* %13
%85 = load i32, i32* @EOF
%86 = icmp ne i32 %84, %85
br i1 %86, label %87, label %90
87: ; preds = %82
%88 = load i32, i32* %13
%89 = icmp ne i32 %88, 10
br label %90
90: ; preds = %87, %82
%91 = phi i1 [ false, %82 ], [ %89, %87 ]
br i1 %91, label %92, label %93
92: ; preds = %90
br label %82
93: ; preds = %90
%94 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%95 = call i32 @memset(i8* %94, i32 0, i32 257)
%96 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
store i8 1, i8* %96
%97 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%98 = getelementptr inbounds i8, i8* %97, i64 1
%99 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%100 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%101 = call i32 @strlen(i8* %100)
%102 = add nsw i32 %101, 1
%103 = call i32 @memcpy(i8* %98, i8* %99, i32 %102)
%104 = call i32* @openfile(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %104, i32** %6
%105 = load i32*, i32** %6
%106 = icmp ne i32* %105, null
br i1 %106, label %107, label %118
107: ; preds = %93
%108 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%109 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%110 = call i32 @strlen(i8* %109)
%111 = add nsw i32 %110, 1
%112 = load i32*, i32** %6
%113 = call i32 @fwrite(i8* %108, i32 1, i32 %111, i32* %112)
%114 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0), i8* %114)
%116 = load i32*, i32** %6
%117 = call i32 @fclose(i32* %116)
br label %118
118: ; preds = %107, %93
br label %182
119: ; preds = %75
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.14, i64 0, i64 0))
%121 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%122 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i8* %121)
br label %123
123: ; preds = %133, %119
%124 = load i32, i32* @stdin
%125 = call i32 @fgetc(i32 %124)
store i32 %125, i32* %13
%126 = load i32, i32* @EOF
%127 = icmp ne i32 %125, %126
br i1 %127, label %128, label %131
128: ; preds = %123
%129 = load i32, i32* %13
%130 = icmp ne i32 %129, 10
br label %131
131: ; preds = %128, %123
%132 = phi i1 [ false, %123 ], [ %130, %128 ]
br i1 %132, label %133, label %134
133: ; preds = %131
br label %123
134: ; preds = %131
%135 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%136 = call i32 @memset(i8* %135, i32 0, i32 257)
%137 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
store i8 2, i8* %137
%138 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%139 = getelementptr inbounds i8, i8* %138, i64 1
%140 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%141 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%142 = call i32 @strlen(i8* %141)
%143 = add nsw i32 %142, 1
%144 = call i32 @memcpy(i8* %139, i8* %140, i32 %143)
%145 = call i32* @openfile(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %145, i32** %6
%146 = load i32*, i32** %6
%147 = icmp ne i32* %146, null
br i1 %147, label %148, label %159
148: ; preds = %134
%149 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%150 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%151 = call i32 @strlen(i8* %150)
%152 = add nsw i32 %151, 1
%153 = load i32*, i32** %6
%154 = call i32 @fwrite(i8* %149, i32 1, i32 %152, i32* %153)
%155 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.15, i64 0, i64 0), i8* %155)
%157 = load i32*, i32** %6
%158 = call i32 @fclose(i32* %157)
br label %159
159: ; preds = %148, %134
br label %182
160: ; preds = %75
%161 = call i32* @openfile(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0))
store i32* %161, i32** %6
%162 = load i32*, i32** %6
%163 = icmp ne i32* %162, null
br i1 %163, label %164, label %178
164: ; preds = %160
%165 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%166 = load i32*, i32** %6
%167 = call i64 @fread(i8* %165, i32 1, i32 255, i32* %166)
store i64 %167, i64* %11
%168 = load i64, i64* %11
%169 = icmp ne i64 %168, 0
br i1 %169, label %172, label %170
170: ; preds = %164
%171 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.17, i64 0, i64 0))
br label %175
172: ; preds = %164
%173 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%174 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.18, i64 0, i64 0), i8* %173)
br label %175
175: ; preds = %172, %170
%176 = load i32*, i32** %6
%177 = call i32 @fclose(i32* %176)
br label %178
178: ; preds = %175, %160
br label %182
179: ; preds = %75
store i32 1, i32* %12
br label %182
180: ; preds = %75
%181 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.19, i64 0, i64 0))
br label %182
182: ; preds = %180, %179, %178, %159, %118
br label %52
183: ; preds = %16, %52
%184 = load i32, i32* %3
ret i32 %184
}

LLVM IR (-O2):
@.str = [87 x i8] c"Error: please indicate whether this is the [t]arget or [d]ebug machine as an argument.\00"
@.str.1 = [14 x i8] c"192.168.5.128\00"
@.str.2 = [14 x i8] c"192.168.5.130\00"
@.str.3 = [31 x i8] c"Using destination address: %s\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.10 = [3 x i8] c"%c\00"
@stdin = global i32 0
@EOF = global i32 0
@.str.12 = [6 x i8] c"%256s\00"
@.str.13 = [32 x i8] c"Destination address set to: %s\0A\00"
@.str.15 = [18 x i8] c"Message sent: %s\0A\00"
@.str.16 = [3 x i8] c"rb\00"
@str = [27 x i8] c"\0A********Main Menu********\00"
@str.20 = [30 x i8] c" (D) Set destination address\00"
@str.21 = [26 x i8] c" (W) Write to the device\00"
@str.22 = [27 x i8] c" (R) Read from the device\00"
@str.23 = [11 x i8] c" (Q) Quit\00"
@str.24 = [13 x i8] c"No data read\00"
@str.25 = [21 x i8] c"Please input string:\00"
@str.26 = [51 x i8] c"Please destination IP address (ex. 192.168.67.51):\00"
@str.27 = [14 x i8] c"Unknown Entry\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [257 x i8]
%4 = alloca [256 x i8]
%5 = alloca i8
%6 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = icmp slt i32 %0, 2
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0))
br label %110
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 116
%16 = select i1 %15, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%18 = call i32 @memset(i8* %6, i32 0, i32 257)
store i8 1, i8* %6
%19 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 1
%20 = call i32 @strlen(i8* %16)
%21 = add nsw i32 %20, 1
%22 = call i32 @memcpy(i8* %19, i8* %16, i32 %21)
%23 = call i32* @openfile(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %27
25: ; preds = %11
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %11
%28 = call i32 @fwrite(i8* %6, i32 1, i32 30, i32* %23)
%29 = call i32 @fclose(i32* %23)
br label %30
30: ; preds = %98, %27
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.20, i64 0, i64 0))
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.21, i64 0, i64 0))
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.22, i64 0, i64 0))
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.23, i64 0, i64 0))
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8* %5)
%37 = load i8, i8* %5
%38 = call signext i8 @toupper(i8 signext %37)
store i8 %38, i8* %5
br label %39
39: ; preds = %39, %30
%40 = load i32, i32* @stdin
%41 = call i32 @fgetc(i32 %40)
%42 = load i32, i32* @EOF
%43 = icmp ne i32 %41, %42
%44 = icmp ne i32 %41, 10
%45 = and i1 %44, %43
br i1 %45, label %39, label %46
46: ; preds = %39
%47 = load i8, i8* %5
%48 = sext i8 %47 to i32
switch i32 %48, label %108 [
i32 68, label %49
i32 87, label %72
i32 82, label %95
i32 81, label %110
]
49: ; preds = %46
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.26, i64 0, i64 0))
%51 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i8* %7)
br label %52
52: ; preds = %52, %49
%53 = load i32, i32* @stdin
%54 = call i32 @fgetc(i32 %53)
%55 = load i32, i32* @EOF
%56 = icmp ne i32 %54, %55
%57 = icmp ne i32 %54, 10
%58 = and i1 %57, %56
br i1 %58, label %52, label %59
59: ; preds = %52
%60 = call i32 @memset(i8* %6, i32 0, i32 257)
store i8 1, i8* %6
%61 = call i32 @strlen(i8* %7)
%62 = add nsw i32 %61, 1
%63 = call i32 @memcpy(i8* %19, i8* %7, i32 %62)
%64 = call i32* @openfile(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%65 = icmp eq i32* %64, null
br i1 %65, label %98, label %66
66: ; preds = %59
%67 = call i32 @strlen(i8* %7)
%68 = add nsw i32 %67, 1
%69 = call i32 @fwrite(i8* %6, i32 1, i32 %68, i32* %64)
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0), i8* %7)
%71 = call i32 @fclose(i32* %64)
br label %98
72: ; preds = %46
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.25, i64 0, i64 0))
%74 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i8* %7)
br label %75
75: ; preds = %75, %72
%76 = load i32, i32* @stdin
%77 = call i32 @fgetc(i32 %76)
%78 = load i32, i32* @EOF
%79 = icmp ne i32 %77, %78
%80 = icmp ne i32 %77, 10
%81 = and i1 %80, %79
br i1 %81, label %75, label %82
82: ; preds = %75
%83 = call i32 @memset(i8* %6, i32 0, i32 257)
store i8 2, i8* %6
%84 = call i32 @strlen(i8* %7)
%85 = add nsw i32 %84, 1
%86 = call i32 @memcpy(i8* %19, i8* %7, i32 %85)
%87 = call i32* @openfile(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%88 = icmp eq i32* %87, null
br i1 %88, label %98, label %89
89: ; preds = %82
%90 = call i32 @strlen(i8* %7)
%91 = add nsw i32 %90, 1
%92 = call i32 @fwrite(i8* %6, i32 1, i32 %91, i32* %87)
%93 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.15, i64 0, i64 0), i8* %7)
%94 = call i32 @fclose(i32* %87)
br label %98
95: ; preds = %46
%96 = call i32* @openfile(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0))
%97 = icmp eq i32* %96, null
br i1 %97, label %98, label %99
98: ; preds = %95, %106, %82, %89, %59, %66, %108
br label %30
99: ; preds = %95
%100 = call i64 @fread(i8* %7, i32 1, i32 255, i32* %96)
%101 = icmp eq i64 %100, 0
br i1 %101, label %102, label %104
102: ; preds = %99
%103 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.24, i64 0, i64 0))
br label %106
104: ; preds = %99
%105 = call i32 @puts(i8* %7)
br label %106
106: ; preds = %104, %102
%107 = call i32 @fclose(i32* %96)
br label %98
108: ; preds = %46
%109 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.27, i64 0, i64 0))
br label %98
110: ; preds = %46, %9
ret i32 0
}