#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ die(char *, char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
char *index(char *, char);
int /*<<< orphan*/ info(int, char *, ...);
int /*<<< orphan*/ read_resp(int, char *, int, int);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ sync_interface(int);
int /*<<< orphan*/ write_line(int, char *);
int upgrade_zensys(int devfd, FILE *f) {
  char buf[64];
  int ret = 0;
  info(1, "Zensys upgrade: syncing up with the target...\n");
  sync_interface(devfd);
  write_line(devfd, ">ZB");
  read_resp(devfd, buf, 64, 3000000);
  if (strncmp(buf, "<E000", 5) != 0)
    die("error: bad response '%s'\n", buf);
  read_resp(devfd, buf, 64, 3000000);
  if (strncmp(buf, ":7F7F7F7F1F00", 13) != 0)
    die("error: bad response '%s'\n", buf);
  read_resp(devfd, buf, 64, 4000000);
  if (strncmp(buf, "<B000", 5) != 0)
    die("error: bad response '%s'\n", buf);
  info(1, "Programming...\n");
  while (fgets(buf, 64, f) != NULL && buf[0] == ':') {
    char *newline;
    newline = index(buf, '\n');
    if (*newline)
      *newline = 0;
    newline = index(buf, '\r');
    if (*newline)
      *newline = 0;
    info(3, "processing: '%s'\n", buf);
    write_line(devfd, buf);
    read_resp(devfd, buf, 64, 4000000);
    if (strncmp(buf, "<E000", 5) != 0) {
      info(0, "unexpected response: '%s'\n", buf);
      ret = 1;
    }
    read_resp(devfd, buf, 64, 4000000);
    if (strncmp(buf, "<B", 2) == 0)
      continue;
    if (buf[0] == ':')
      break;
    info(0, "unexpected response: '%s'\n", buf);
    ret = 1;
  }
  info(1, "Verifying... (or at least pretending to)\n");
  while (buf[0] != ':')
    read_resp(devfd, buf, 64, 4000000);
  do {
    read_resp(devfd, buf, 64, 4000000);
  } while (strncmp(buf, "<B000", 5) != 0);
  return ret;
}


x86 assembly (clang, -O0):
<upgrade_zensys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x54(%rbp)
mov    $0x1,%edi
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   10a0 <info@plt>
mov    -0x4(%rbp),%edi
call   1090 <sync_interface@plt>
mov    -0x4(%rbp),%edi
lea    0xe74(%rip),%rsi
call   1080 <write_line@plt>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x40,%edx
mov    $0x2dc6c0,%ecx
call   1060 <read_resp@plt>
lea    -0x50(%rbp),%rdi
lea    0xe52(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1205 <upgrade_zensys+0x85>
lea    -0x50(%rbp),%rsi
lea    0xe39(%rip),%rdi
call   1070 <die@plt>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x40,%edx
mov    $0x2dc6c0,%ecx
call   1060 <read_resp@plt>
lea    -0x50(%rbp),%rdi
lea    0xe2d(%rip),%rsi
mov    $0xd,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     124a <upgrade_zensys+0xca>
lea    -0x50(%rbp),%rsi
lea    0xdf4(%rip),%rdi
call   1070 <die@plt>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x40,%edx
mov    $0x3d0900,%ecx
call   1060 <read_resp@plt>
lea    -0x50(%rbp),%rdi
lea    0xdf6(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     128f <upgrade_zensys+0x10f>
lea    -0x50(%rbp),%rsi
lea    0xdaf(%rip),%rdi
call   1070 <die@plt>
mov    $0x1,%edi
lea    0xdcc(%rip),%rsi
mov    $0x0,%al
call   10a0 <info@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x40,%esi
call   1050 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x61(%rbp)
je     12d3 <upgrade_zensys+0x153>
movsbl -0x50(%rbp),%eax
cmp    $0x3a,%eax
sete   %al
mov    %al,-0x61(%rbp)
mov    -0x61(%rbp),%al
test   $0x1,%al
jne    12e3 <upgrade_zensys+0x163>
jmp    140e <upgrade_zensys+0x28e>
lea    -0x50(%rbp),%rdi
mov    $0xa,%esi
call   1040 <index@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
cmpb   $0x0,(%rax)
je     1309 <upgrade_zensys+0x189>
mov    -0x60(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x50(%rbp),%rdi
mov    $0xd,%esi
call   1040 <index@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
cmpb   $0x0,(%rax)
je     132f <upgrade_zensys+0x1af>
mov    -0x60(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x50(%rbp),%rdx
mov    $0x3,%edi
lea    0xd38(%rip),%rsi
mov    $0x0,%al
call   10a0 <info@plt>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1080 <write_line@plt>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x40,%edx
mov    $0x3d0900,%ecx
call   1060 <read_resp@plt>
lea    -0x50(%rbp),%rdi
lea    0xcc0(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     13a2 <upgrade_zensys+0x222>
lea    -0x50(%rbp),%rdx
xor    %edi,%edi
lea    0xcf5(%rip),%rsi
mov    $0x0,%al
call   10a0 <info@plt>
movl   $0x1,-0x54(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x40,%edx
mov    $0x3d0900,%ecx
call   1060 <read_resp@plt>
lea    -0x50(%rbp),%rdi
lea    0xce1(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    13dc <upgrade_zensys+0x25c>
jmp    12a2 <upgrade_zensys+0x122>
movsbl -0x50(%rbp),%eax
cmp    $0x3a,%eax
jne    13ee <upgrade_zensys+0x26e>
jmp    140e <upgrade_zensys+0x28e>
lea    -0x50(%rbp),%rdx
xor    %edi,%edi
lea    0xc8e(%rip),%rsi
mov    $0x0,%al
call   10a0 <info@plt>
movl   $0x1,-0x54(%rbp)
jmp    12a2 <upgrade_zensys+0x122>
mov    $0x1,%edi
lea    0xc8d(%rip),%rsi
mov    $0x0,%al
call   10a0 <info@plt>
movsbl -0x50(%rbp),%eax
cmp    $0x3a,%eax
je     1449 <upgrade_zensys+0x2c9>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x40,%edx
mov    $0x3d0900,%ecx
call   1060 <read_resp@plt>
jmp    1421 <upgrade_zensys+0x2a1>
jmp    144e <upgrade_zensys+0x2ce>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x40,%edx
mov    $0x3d0900,%ecx
call   1060 <read_resp@plt>
lea    -0x50(%rbp),%rdi
lea    0xbf2(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    144e <upgrade_zensys+0x2ce>
mov    -0x54(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upgrade_zensys>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r14
mov    %edi,%r12d
lea    0xe65(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <info@plt>
mov    %r12d,%edi
call   1090 <sync_interface@plt>
lea    0xe79(%rip),%rsi
mov    %r12d,%edi
call   1080 <write_line@plt>
mov    %rsp,%rbx
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
mov    $0x2dc6c0,%ecx
call   1060 <read_resp@plt>
lea    0xe56(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11fe <upgrade_zensys+0x7e>
lea    0xe43(%rip),%rdi
mov    %rsp,%rsi
call   1070 <die@plt>
mov    %rsp,%rbx
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
mov    $0x2dc6c0,%ecx
call   1060 <read_resp@plt>
lea    0xe36(%rip),%rsi
mov    %rbx,%rdi
mov    $0xd,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     123e <upgrade_zensys+0xbe>
lea    0xe03(%rip),%rdi
mov    %rsp,%rsi
call   1070 <die@plt>
mov    %rsp,%rbx
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
mov    $0x3d0900,%ecx
call   1060 <read_resp@plt>
lea    0xe04(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     127e <upgrade_zensys+0xfe>
lea    0xdc3(%rip),%rdi
mov    %rsp,%rsi
call   1070 <die@plt>
lea    0xde2(%rip),%rsi
xor    %r15d,%r15d
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <info@plt>
mov    %rsp,%rdi
mov    $0x40,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     13c2 <upgrade_zensys+0x242>
cmpb   $0x3a,(%rsp)
jne    13c2 <upgrade_zensys+0x242>
mov    %rsp,%rbp
lea    0xde3(%rip),%rbx
lea    0xdc1(%rip),%r13
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0xa,%esi
call   1040 <index@plt>
cmpb   $0x0,(%rax)
je     12e5 <upgrade_zensys+0x165>
movb   $0x0,(%rax)
mov    %rbp,%rdi
mov    $0xd,%esi
call   1040 <index@plt>
cmpb   $0x0,(%rax)
je     12fa <upgrade_zensys+0x17a>
movb   $0x0,(%rax)
mov    $0x3,%edi
lea    0xd71(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   10a0 <info@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
call   1080 <write_line@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x40,%edx
mov    $0x3d0900,%ecx
call   1060 <read_resp@plt>
mov    %rbp,%rdi
lea    0xcf9(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     135e <upgrade_zensys+0x1de>
xor    %edi,%edi
mov    %r13,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   10a0 <info@plt>
mov    $0x1,%r15d
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x40,%edx
mov    $0x3d0900,%ecx
call   1060 <read_resp@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     13a3 <upgrade_zensys+0x223>
cmpb   $0x3a,(%rsp)
je     13c2 <upgrade_zensys+0x242>
xor    %edi,%edi
mov    %r13,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   10a0 <info@plt>
mov    $0x1,%r15d
mov    %rbp,%rdi
mov    $0x40,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     13c2 <upgrade_zensys+0x242>
cmpb   $0x3a,(%rsp)
je     12d0 <upgrade_zensys+0x150>
lea    0xcde(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <info@plt>
cmpb   $0x3a,(%rsp)
je     13fb <upgrade_zensys+0x27b>
mov    %rsp,%rbx
xchg   %ax,%ax
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
mov    $0x3d0900,%ecx
call   1060 <read_resp@plt>
cmpb   $0x3a,(%rsp)
jne    13e0 <upgrade_zensys+0x260>
mov    %rsp,%rbp
lea    0xc5c(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x40,%edx
mov    $0x3d0900,%ecx
call   1060 <read_resp@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1410 <upgrade_zensys+0x290>
mov    %r15d,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [47 x i8] c"Zensys upgrade: syncing up with the target...\0A\00"
@.str.1 = [4 x i8] c">ZB\00"
@.str.2 = [6 x i8] c"<E000\00"
@.str.3 = [26 x i8] c"error: bad response '%s'\0A\00"
@.str.4 = [14 x i8] c":7F7F7F7F1F00\00"
@.str.5 = [6 x i8] c"<B000\00"
@.str.6 = [16 x i8] c"Programming...\0A\00"
@.str.7 = [18 x i8] c"processing: '%s'\0A\00"
@.str.8 = [27 x i8] c"unexpected response: '%s'\0A\00"
@.str.9 = [3 x i8] c"<B\00"
@.str.10 = [42 x i8] c"Verifying... (or at least pretending to)\0A\00"
define i32 @upgrade_zensys(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [64 x i8]
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %3
store i32* %1, i32** %4
store i32 0, i32* %6
%8 = call i32 (i32, i8*, ...) @info(i32 1, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* %3
%10 = call i32 @sync_interface(i32 %9)
%11 = load i32, i32* %3
%12 = call i32 @write_line(i32 %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* %3
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%15 = call i32 @read_resp(i32 %13, i8* %14, i32 64, i32 3000000)
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%17 = call i64 @strncmp(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%21 = call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %19, %2
%23 = load i32, i32* %3
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%25 = call i32 @read_resp(i32 %23, i8* %24, i32 64, i32 3000000)
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%27 = call i64 @strncmp(i8* %26, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 13)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%31 = call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %29, %22
%33 = load i32, i32* %3
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%35 = call i32 @read_resp(i32 %33, i8* %34, i32 64, i32 4000000)
%36 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%37 = call i64 @strncmp(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %32
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%41 = call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %39, %32
%43 = call i32 (i32, i8*, ...) @info(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %44
44: ; preds = %101, %94, %42
%45 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%46 = load i32*, i32** %4
%47 = call i32* @fgets(i8* %45, i32 64, i32* %46)
%48 = icmp ne i32* %47, null
br i1 %48, label %49, label %54
49: ; preds = %44
%50 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 58
br label %54
54: ; preds = %49, %44
%55 = phi i1 [ false, %44 ], [ %53, %49 ]
br i1 %55, label %56, label %104
56: ; preds = %54
%57 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%58 = call i8* @index(i8* %57, i8 signext 10)
store i8* %58, i8** %7
%59 = load i8*, i8** %7
%60 = load i8, i8* %59
%61 = icmp ne i8 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %56
%63 = load i8*, i8** %7
store i8 0, i8* %63
br label %64
64: ; preds = %62, %56
%65 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%66 = call i8* @index(i8* %65, i8 signext 13)
store i8* %66, i8** %7
%67 = load i8*, i8** %7
%68 = load i8, i8* %67
%69 = icmp ne i8 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %64
%71 = load i8*, i8** %7
store i8 0, i8* %71
br label %72
72: ; preds = %70, %64
%73 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%74 = call i32 (i32, i8*, ...) @info(i32 3, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8* %73)
%75 = load i32, i32* %3
%76 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%77 = call i32 @write_line(i32 %75, i8* %76)
%78 = load i32, i32* %3
%79 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%80 = call i32 @read_resp(i32 %78, i8* %79, i32 64, i32 4000000)
%81 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%82 = call i64 @strncmp(i8* %81, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %72
%85 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%86 = call i32 (i32, i8*, ...) @info(i32 0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* %85)
store i32 1, i32* %6
br label %87
87: ; preds = %84, %72
%88 = load i32, i32* %3
%89 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%90 = call i32 @read_resp(i32 %88, i8* %89, i32 64, i32 4000000)
%91 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%92 = call i64 @strncmp(i8* %91, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 2)
%93 = icmp eq i64 %92, 0
br i1 %93, label %94, label %95
94: ; preds = %87
br label %44
95: ; preds = %87
%96 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%97 = load i8, i8* %96
%98 = sext i8 %97 to i32
%99 = icmp eq i32 %98, 58
br i1 %99, label %100, label %101
100: ; preds = %95
br label %104
101: ; preds = %95
%102 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%103 = call i32 (i32, i8*, ...) @info(i32 0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* %102)
store i32 1, i32* %6
br label %44
104: ; preds = %100, %54
%105 = call i32 (i32, i8*, ...) @info(i32 1, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.10, i64 0, i64 0))
br label %106
106: ; preds = %111, %104
%107 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%108 = load i8, i8* %107
%109 = sext i8 %108 to i32
%110 = icmp ne i32 %109, 58
br i1 %110, label %111, label %115
111: ; preds = %106
%112 = load i32, i32* %3
%113 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%114 = call i32 @read_resp(i32 %112, i8* %113, i32 64, i32 4000000)
br label %106
115: ; preds = %106
br label %116
116: ; preds = %120, %115
%117 = load i32, i32* %3
%118 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%119 = call i32 @read_resp(i32 %117, i8* %118, i32 64, i32 4000000)
br label %120
120: ; preds = %116
%121 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%122 = call i64 @strncmp(i8* %121, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%123 = icmp ne i64 %122, 0
br i1 %123, label %116, label %124
124: ; preds = %120
%125 = load i32, i32* %6
ret i32 %125
}

LLVM IR (-O2):
@.str = [47 x i8] c"Zensys upgrade: syncing up with the target...\0A\00"
@.str.1 = [4 x i8] c">ZB\00"
@.str.2 = [6 x i8] c"<E000\00"
@.str.3 = [26 x i8] c"error: bad response '%s'\0A\00"
@.str.4 = [14 x i8] c":7F7F7F7F1F00\00"
@.str.5 = [6 x i8] c"<B000\00"
@.str.6 = [16 x i8] c"Programming...\0A\00"
@.str.7 = [18 x i8] c"processing: '%s'\0A\00"
@.str.8 = [27 x i8] c"unexpected response: '%s'\0A\00"
@.str.9 = [3 x i8] c"<B\00"
@.str.10 = [42 x i8] c"Verifying... (or at least pretending to)\0A\00"
define i32 @upgrade_zensys(i32 %0, i32* nocapture %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (i32, i8*, ...) @info(i32 1, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @sync_interface(i32 %0)
%7 = tail call i32 @write_line(i32 %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @read_resp(i32 %0, i8* %4, i32 64, i32 3000000)
%9 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %13
13: ; preds = %11, %2
%14 = call i32 @read_resp(i32 %0, i8* %4, i32 64, i32 3000000)
%15 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 13)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %19
19: ; preds = %17, %13
%20 = call i32 @read_resp(i32 %0, i8* %4, i32 64, i32 4000000)
%21 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %25
25: ; preds = %23, %19
%26 = call i32 (i32, i8*, ...) @info(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%27 = call i32* @fgets(i8* %4, i32 64, i32* %1)
%28 = icmp ne i32* %27, null
%29 = load i8, i8* %4
%30 = icmp eq i8 %29, 58
%31 = select i1 %28, i1 %30, i1 false
br i1 %31, label %32, label %68
32: ; preds = %25, %61
%33 = phi i32 [ %62, %61 ], [ 0, %25 ]
%34 = call i8* @index(i8* %4, i8 signext 10)
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %32
store i8 0, i8* %34
br label %38
38: ; preds = %37, %32
%39 = call i8* @index(i8* %4, i8 signext 13)
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %38
store i8 0, i8* %39
br label %43
43: ; preds = %42, %38
%44 = call i32 (i32, i8*, ...) @info(i32 3, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8* %4)
%45 = call i32 @write_line(i32 %0, i8* %4)
%46 = call i32 @read_resp(i32 %0, i8* %4, i32 64, i32 4000000)
%47 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%48 = icmp eq i64 %47, 0
br i1 %48, label %51, label %49
49: ; preds = %43
%50 = call i32 (i32, i8*, ...) @info(i32 0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* %4)
br label %51
51: ; preds = %49, %43
%52 = phi i32 [ 1, %49 ], [ %33, %43 ]
%53 = call i32 @read_resp(i32 %0, i8* %4, i32 64, i32 4000000)
%54 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 2)
%55 = icmp eq i64 %54, 0
br i1 %55, label %61, label %56
56: ; preds = %51
%57 = load i8, i8* %4
%58 = icmp eq i8 %57, 58
br i1 %58, label %68, label %59
59: ; preds = %56
%60 = call i32 (i32, i8*, ...) @info(i32 0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* %4)
br label %61
61: ; preds = %51, %59
%62 = phi i32 [ 1, %59 ], [ %52, %51 ]
%63 = call i32* @fgets(i8* %4, i32 64, i32* %1)
%64 = icmp ne i32* %63, null
%65 = load i8, i8* %4
%66 = icmp eq i8 %65, 58
%67 = select i1 %64, i1 %66, i1 false
br i1 %67, label %32, label %68
68: ; preds = %61, %56, %25
%69 = phi i32 [ 0, %25 ], [ %52, %56 ], [ %62, %61 ]
%70 = call i32 (i32, i8*, ...) @info(i32 1, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.10, i64 0, i64 0))
%71 = load i8, i8* %4
%72 = icmp eq i8 %71, 58
br i1 %72, label %77, label %73
73: ; preds = %68, %73
%74 = call i32 @read_resp(i32 %0, i8* %4, i32 64, i32 4000000)
%75 = load i8, i8* %4
%76 = icmp eq i8 %75, 58
br i1 %76, label %77, label %73
77: ; preds = %73, %68
br label %78
78: ; preds = %77, %78
%79 = call i32 @read_resp(i32 %0, i8* %4, i32 64, i32 4000000)
%80 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%81 = icmp eq i64 %80, 0
br i1 %81, label %82, label %78
82: ; preds = %78
ret i32 %69
}