#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 */
struct stat {
  int st_size;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ dialdir_padding;
typedef int /*<<< orphan*/ dialdir_bak_name;
typedef int /*<<< orphan*/ data;

/* Variables and functions */
int MAXPATHLEN;
int O_CREAT;
int O_EXCL;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int rename(char *, char *);
int snprintf(char *, int, char *, char *);
int stat(char *, struct stat *);
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd, ret;
  char data[65535], dialdir_bak_name[MAXPATHLEN],
      dialdir_padding[] = {'\0', '\0', '\0', '\0'};
  unsigned short old_dialent_size = 0;
  ssize_t read_len, write_len, d_offset;
  struct stat st;
  if (argc != 2) {
    printf("Usage: %s DIALDIR\n", argv[0]);
    return 1;
  }
  ret = stat(argv[1], &st);
  if (ret == -1) {
    printf("stat(%s): %s\n", argv[1], strerror(errno));
    return 1;
  }
  fd = open(argv[1], O_RDONLY);
  if (fd == -1) {
    printf("open(%s): %s\n", argv[1], strerror(errno));
    return 1;
  }
  read_len = read(fd, data, sizeof(data));
  if (read_len == -1) {
    printf("read(%s): %s\n", argv[1], strerror(errno));
    return 1;
  }
  if (read_len != st.st_size) {
    printf("short read(%s): stat() == %lu vs. read length %lu.\n", argv[1],
           st.st_size, read_len);
    return 1;
  }
  ret =
      snprintf(dialdir_bak_name, sizeof(dialdir_bak_name), "%s.i386", argv[1]);
  if (ret != strlen(argv[1]) + strlen(".i386")) {
    printf("overflow when trying to back up %s to %s.i386.", argv[1], argv[1]);
    return 1;
  }
  ret = rename(argv[1], dialdir_bak_name);
  if (ret == -1) {
    printf("rename(%s, %s): %s\n", argv[1], dialdir_bak_name, strerror(errno));
    return 1;
  }
  switch (data[2]) {
  case 1:
  case 2:
  case 3:
  case 4:
  case 5:
    break;
  default:
    printf("unknown minicom phonebook version: %d\n", data[2]);
    return 1;
  }
  old_dialent_size = (data[5] & 0x00ff) + ((data[4] << 8) & 0xff00);
  data[5] += 4;
  fd = open(argv[1], O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR);
  if (fd == -1) {
    printf("open(%s) for writing: %s\n", argv[1], strerror(errno));
    return 1;
  }
  d_offset = 14;
  ret = write(fd, data, d_offset);
  if (ret != d_offset) {
    printf("short write(%s): wanted to write %lu but only wrote %d.\n", argv[1],
           d_offset, ret);
    return 1;
  }
  while (d_offset < read_len) {
    ret = write(fd, data + d_offset, old_dialent_size);
    if (ret != old_dialent_size) {
      printf("short write(%s): wanted to write %d but only wrote %d.\n",
             argv[1], old_dialent_size, ret);
      return 1;
    }
    write_len = write(fd, dialdir_padding, sizeof(dialdir_padding));
    if (write_len != sizeof(dialdir_padding)) {
      printf("short write(%s): wanted to write %lu but only wrote %lu.\n",
             argv[1], sizeof(dialdir_padding), write_len);
      return 1;
    }
    d_offset += old_dialent_size;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10090,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x10060(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x10028(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x10058(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x10030(%rbp)
lea    -0x10034(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
movw   $0x0,-0x10036(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1256 <main+0xa6>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x1004c(%rbp)
jmp    1788 <main+0x5d8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x10048(%rbp),%rsi
call   10a0 <stat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    12c2 <main+0x112>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x10068(%rbp)
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x10068(%rbp),%rsi
mov    %rax,%rdx
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x1004c(%rbp)
jmp    1788 <main+0x5d8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d0f(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1332 <main+0x182>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x10070(%rbp)
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x10070(%rbp),%rsi
mov    %rax,%rdx
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x1004c(%rbp)
jmp    1788 <main+0x5d8>
mov    -0x14(%rbp),%edi
lea    -0x10020(%rbp),%rsi
mov    $0xffff,%edx
call   1090 <read@plt>
mov    %eax,-0x1003c(%rbp)
cmpl   $0xffffffff,-0x1003c(%rbp)
jne    13a4 <main+0x1f4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x10078(%rbp)
mov    0x2c49(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x10078(%rbp),%rsi
mov    %rax,%rdx
lea    0xca8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x1004c(%rbp)
jmp    1788 <main+0x5d8>
mov    -0x1003c(%rbp),%eax
cmp    -0x10048(%rbp),%eax
je     13ee <main+0x23e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10048(%rbp),%edx
mov    -0x1003c(%rbp),%ecx
lea    0xc6c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x1004c(%rbp)
jmp    1788 <main+0x5d8>
mov    -0x10058(%rbp),%rdi
mov    -0x10060(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xc64(%rip),%rdx
call   1060 <snprintf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1007c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10080(%rbp)
lea    0xc3b(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x10080(%rbp),%ecx
mov    %eax,%edx
mov    -0x1007c(%rbp),%eax
add    %edx,%ecx
cmp    %ecx,%eax
je     1489 <main+0x2d9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xc0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x1004c(%rbp)
jmp    1788 <main+0x5d8>
mov    -0x10058(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <rename@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    14fc <main+0x34c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x10088(%rbp)
mov    0x2af8(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x10088(%rbp),%rsi
mov    -0x10058(%rbp),%rdx
mov    %rax,%rcx
lea    0xbc9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x1004c(%rbp)
jmp    1788 <main+0x5d8>
movsbl -0x1001e(%rbp),%eax
add    $0xffffffff,%eax
sub    $0x4,%eax
ja     1519 <main+0x369>
jmp    1514 <main+0x364>
jmp    1544 <main+0x394>
movsbl -0x1001e(%rbp),%esi
lea    0xb95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x1004c(%rbp)
jmp    1788 <main+0x5d8>
movsbl -0x1001b(%rbp),%eax
and    $0xff,%eax
movsbl -0x1001c(%rbp),%ecx
shl    $0x8,%ecx
and    $0xff00,%ecx
add    %ecx,%eax
mov    %ax,-0x10036(%rbp)
movsbl -0x1001b(%rbp),%eax
add    $0x4,%eax
mov    %al,-0x1001b(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2a70(%rip),%rax
mov    (%rax),%esi
mov    0x2a2f(%rip),%rax
or     (%rax),%esi
mov    0x2a06(%rip),%rax
or     (%rax),%esi
mov    0x2a0d(%rip),%rax
mov    (%rax),%edx
mov    0x2a24(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    160d <main+0x45d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x10090(%rbp)
mov    0x29e0(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x10090(%rbp),%rsi
mov    %rax,%rdx
lea    0xaf3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x1004c(%rbp)
jmp    1788 <main+0x5d8>
movl   $0xe,-0x10044(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x10020(%rbp),%rsi
mov    -0x10044(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10044(%rbp),%eax
je     1673 <main+0x4c3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10044(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xaa7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x1004c(%rbp)
jmp    1788 <main+0x5d8>
jmp    1678 <main+0x4c8>
mov    -0x10044(%rbp),%eax
cmp    -0x1003c(%rbp),%eax
jge    176f <main+0x5bf>
mov    -0x14(%rbp),%edi
lea    -0x10020(%rbp),%rsi
movslq -0x10044(%rbp),%rax
add    %rax,%rsi
movzwl -0x10036(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
movzwl -0x10036(%rbp),%ecx
cmp    %ecx,%eax
je     16f5 <main+0x545>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
movzwl -0x10036(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xa5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x1004c(%rbp)
jmp    1788 <main+0x5d8>
mov    -0x14(%rbp),%edi
lea    -0x10034(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0x10040(%rbp)
movslq -0x10040(%rbp),%rax
cmp    $0x4,%rax
je     1757 <main+0x5a7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10040(%rbp),%ecx
lea    0xa39(%rip),%rdi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x1004c(%rbp)
jmp    1788 <main+0x5d8>
movzwl -0x10036(%rbp),%eax
add    -0x10044(%rbp),%eax
mov    %eax,-0x10044(%rbp)
jmp    1678 <main+0x4c8>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x1004c(%rbp)
mov    -0x10028(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10018,%rsp
mov    %rsi,%r15
mov    %rsp,%r13
mov    0x2e17(%rip),%rax
mov    (%rax),%r12d
mov    %rsp,%rbx
lea    0xf(%r12),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
movl   $0x0,-0x3c(%rbp)
cmp    $0x2,%edi
jne    1395 <main+0x1f5>
mov    0x8(%r15),%rdi
lea    -0x38(%rbp),%rsi
call   1090 <stat@plt>
mov    0x8(%r15),%r14
cmp    $0xffffffff,%eax
je     13a8 <main+0x208>
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     13c2 <main+0x222>
lea    -0x10040(%rbp),%rsi
mov    %eax,%edi
mov    $0xffff,%edx
call   1080 <read@plt>
cmp    $0xffffffff,%eax
je     13dd <main+0x23d>
mov    %eax,%r14d
mov    -0x38(%rbp),%edx
mov    0x8(%r15),%rcx
cmp    %edx,%eax
jne    141a <main+0x27a>
lea    0xe20(%rip),%rdx
mov    %rbx,%rdi
mov    %r12d,%esi
call   1060 <snprintf@plt>
mov    %eax,-0x30(%rbp)
mov    0x8(%r15),%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
lea    0xe01(%rip),%rdi
call   1040 <strlen@plt>
add    %r12d,%eax
mov    0x8(%r15),%rdx
cmp    %eax,-0x30(%rbp)
jne    1430 <main+0x290>
mov    %rdx,%rdi
mov    %rbx,%rsi
call   10b0 <rename@plt>
cmp    $0xffffffff,%eax
je     143c <main+0x29c>
movsbl -0x1003e(%rbp),%esi
lea    -0x1(%rsi),%eax
cmp    $0x5,%eax
jae    1467 <main+0x2c7>
movzbl -0x1003b(%rbp),%ebx
movsbl -0x1003c(%rbp),%r12d
ff
lea    0x4(%rbx),%eax
mov    %al,-0x1003b(%rbp)
mov    0x8(%r15),%rdi
mov    0x2d27(%rip),%rax
mov    0x2ce8(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2cbd(%rip),%rax
or     (%rax),%esi
mov    0x2cc4(%rip),%rax
mov    0x2cdd(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
xor    %eax,%eax
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     1477 <main+0x2d7>
mov    %rbx,-0x30(%rbp)
lea    -0x10040(%rbp),%rsi
mov    %eax,%ebx
mov    %eax,%edi
mov    $0xe,%edx
call   1030 <write@plt>
cmp    $0xe,%eax
jne    1495 <main+0x2f5>
cmp    $0xf,%r14d
jl     138a <main+0x1ea>
mov    %r12,%rdx
shl    $0x8,%rdx
and    $0xff00,%edx
add    -0x30(%rbp),%rdx
mov    $0xe,%r12d
mov    %rdx,-0x30(%rbp)
lea    (%r12,%rbp,1),%rsi
add    $0xfffffffffffeffc0,%rsi
mov    %ebx,%edi
call   1030 <write@plt>
cmp    -0x30(%rbp),%eax
jne    14ac <main+0x30c>
mov    %ebx,%edi
lea    -0x3c(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x4,%eax
jne    14bd <main+0x31d>
mov    -0x30(%rbp),%rdx
add    %rdx,%r12
cmp    %r12d,%r14d
jg     134a <main+0x1aa>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
jmp    1408 <main+0x268>
mov    (%r15),%rsi
lea    0xc61(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1403 <main+0x263>
mov    0x2c09(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xc56(%rip),%rdi
mov    %r14,%rsi
jmp    13f9 <main+0x259>
mov    0x8(%r15),%rbx
mov    0x2beb(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xc46(%rip),%rdi
jmp    13f6 <main+0x256>
mov    0x8(%r15),%rbx
mov    0x2bd0(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xc39(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc1c(%rip),%rdi
mov    %rcx,%rsi
mov    %r14d,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1403 <main+0x263>
lea    0xc42(%rip),%rdi
mov    %rdx,%rsi
jmp    13fc <main+0x25c>
mov    0x8(%r15),%r14
mov    0x2b71(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xc53(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1403 <main+0x263>
lea    0xc4e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1403 <main+0x263>
mov    0x8(%r15),%rbx
mov    0x2b36(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xc53(%rip),%rdi
jmp    13f6 <main+0x256>
mov    0x8(%r15),%rsi
lea    0xc5d(%rip),%rdi
mov    $0xe,%edx
mov    %eax,%ecx
jmp    1427 <main+0x287>
mov    0x8(%r15),%rsi
lea    0xc7f(%rip),%rdi
mov    -0x30(%rbp),%rdx
jmp    14a5 <main+0x305>
mov    0x8(%r15),%rsi
lea    0xca6(%rip),%rdi
mov    $0x4,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1403 <main+0x263>

LLVM IR (-O0):
%struct.stat = type { i32 }
@MAXPATHLEN = global i32 0
@.str = [19 x i8] c"Usage: %s DIALDIR\0A\00"
@.str.1 = [14 x i8] c"stat(%s): %s\0A\00"
@errno = global i32 0
@O_RDONLY = global i32 0
@.str.2 = [14 x i8] c"open(%s): %s\0A\00"
@.str.3 = [14 x i8] c"read(%s): %s\0A\00"
@.str.4 = [52 x i8] c"short read(%s): stat() == %lu vs. read length %lu.\0A\00"
@.str.5 = [8 x i8] c"%s.i386\00"
@.str.6 = [6 x i8] c".i386\00"
@.str.7 = [47 x i8] c"overflow when trying to back up %s to %s.i386.\00"
@.str.8 = [20 x i8] c"rename(%s, %s): %s\0A\00"
@.str.9 = [39 x i8] c"unknown minicom phonebook version: %d\0A\00"
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_WRONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.10 = [26 x i8] c"open(%s) for writing: %s\0A\00"
@.str.11 = [57 x i8] c"short write(%s): wanted to write %lu but only wrote %d.\0A\00"
@.str.12 = [56 x i8] c"short write(%s): wanted to write %d but only wrote %d.\0A\00"
@.str.13 = [58 x i8] c"short write(%s): wanted to write %lu but only wrote %lu.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [65535 x i8]
%9 = alloca i8*
%10 = alloca i64
%11 = alloca [4 x i8]
%12 = alloca i16
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca %struct.stat
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i32, i32* @MAXPATHLEN
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %9
%21 = alloca i8, i64 %19
store i64 %19, i64* %10
%22 = bitcast [4 x i8]* %11 to i8*
store i16 0, i16* %12
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 2
br i1 %24, label %25, label %30
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %28)
store i32 1, i32* %3
store i32 1, i32* %17
br label %231
30: ; preds = %2
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @stat(i8* %33, %struct.stat* %16)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %44
37: ; preds = %30
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %40, i8* %42)
store i32 1, i32* %3
store i32 1, i32* %17
br label %231
44: ; preds = %30
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = load i32, i32* @O_RDONLY
%49 = call i32 (i8*, i32, ...) @open(i8* %47, i32 %48)
store i32 %49, i32* %6
%50 = load i32, i32* %6
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %59
52: ; preds = %44
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 1
%55 = load i8*, i8** %54
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %55, i8* %57)
store i32 1, i32* %3
store i32 1, i32* %17
br label %231
59: ; preds = %44
%60 = load i32, i32* %6
%61 = getelementptr inbounds [65535 x i8], [65535 x i8]* %8, i64 0, i64 0
%62 = call i32 @read(i32 %60, i8* %61, i32 65535)
store i32 %62, i32* %13
%63 = load i32, i32* %13
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %72
65: ; preds = %59
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 1
%68 = load i8*, i8** %67
%69 = load i32, i32* @errno
%70 = call i8* @strerror(i32 %69)
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %68, i8* %70)
store i32 1, i32* %3
store i32 1, i32* %17
br label %231
72: ; preds = %59
%73 = load i32, i32* %13
%74 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 0
%75 = load i32, i32* %74
%76 = icmp ne i32 %73, %75
br i1 %76, label %77, label %85
77: ; preds = %72
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 1
%80 = load i8*, i8** %79
%81 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 0
%82 = load i32, i32* %81
%83 = load i32, i32* %13
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i8* %80, i32 %82, i32 %83)
store i32 1, i32* %3
store i32 1, i32* %17
br label %231
85: ; preds = %72
%86 = trunc i64 %19 to i32
%87 = load i8**, i8*** %5
%88 = getelementptr inbounds i8*, i8** %87, i64 1
%89 = load i8*, i8** %88
%90 = call i32 @snprintf(i8* %21, i32 %86, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %89)
store i32 %90, i32* %7
%91 = load i32, i32* %7
%92 = load i8**, i8*** %5
%93 = getelementptr inbounds i8*, i8** %92, i64 1
%94 = load i8*, i8** %93
%95 = call i32 @strlen(i8* %94)
%96 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%97 = add nsw i32 %95, %96
%98 = icmp ne i32 %91, %97
br i1 %98, label %99, label %107
99: ; preds = %85
%100 = load i8**, i8*** %5
%101 = getelementptr inbounds i8*, i8** %100, i64 1
%102 = load i8*, i8** %101
%103 = load i8**, i8*** %5
%104 = getelementptr inbounds i8*, i8** %103, i64 1
%105 = load i8*, i8** %104
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i8* %102, i8* %105)
store i32 1, i32* %3
store i32 1, i32* %17
br label %231
107: ; preds = %85
%108 = load i8**, i8*** %5
%109 = getelementptr inbounds i8*, i8** %108, i64 1
%110 = load i8*, i8** %109
%111 = call i32 @rename(i8* %110, i8* %21)
store i32 %111, i32* %7
%112 = load i32, i32* %7
%113 = icmp eq i32 %112, -1
br i1 %113, label %114, label %121
114: ; preds = %107
%115 = load i8**, i8*** %5
%116 = getelementptr inbounds i8*, i8** %115, i64 1
%117 = load i8*, i8** %116
%118 = load i32, i32* @errno
%119 = call i8* @strerror(i32 %118)
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %117, i8* %21, i8* %119)
store i32 1, i32* %3
store i32 1, i32* %17
br label %231
121: ; preds = %107
%122 = getelementptr inbounds [65535 x i8], [65535 x i8]* %8, i64 0, i64 2
%123 = load i8, i8* %122
%124 = sext i8 %123 to i32
switch i32 %124, label %126 [
i32 1, label %125
i32 2, label %125
i32 3, label %125
i32 4, label %125
i32 5, label %125
]
125: ; preds = %121, %121, %121, %121, %121
br label %131
126: ; preds = %121
%127 = getelementptr inbounds [65535 x i8], [65535 x i8]* %8, i64 0, i64 2
%128 = load i8, i8* %127
%129 = sext i8 %128 to i32
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0), i32 %129)
store i32 1, i32* %3
store i32 1, i32* %17
br label %231
131: ; preds = %125
%132 = getelementptr inbounds [65535 x i8], [65535 x i8]* %8, i64 0, i64 5
%133 = load i8, i8* %132
%134 = sext i8 %133 to i32
%135 = and i32 %134, 255
%136 = getelementptr inbounds [65535 x i8], [65535 x i8]* %8, i64 0, i64 4
%137 = load i8, i8* %136
%138 = sext i8 %137 to i32
%139 = shl i32 %138, 8
%140 = and i32 %139, 65280
%141 = add nsw i32 %135, %140
%142 = trunc i32 %141 to i16
store i16 %142, i16* %12
%143 = getelementptr inbounds [65535 x i8], [65535 x i8]* %8, i64 0, i64 5
%144 = load i8, i8* %143
%145 = sext i8 %144 to i32
%146 = add nsw i32 %145, 4
%147 = trunc i32 %146 to i8
store i8 %147, i8* %143
%148 = load i8**, i8*** %5
%149 = getelementptr inbounds i8*, i8** %148, i64 1
%150 = load i8*, i8** %149
%151 = load i32, i32* @O_CREAT
%152 = load i32, i32* @O_EXCL
%153 = or i32 %151, %152
%154 = load i32, i32* @O_WRONLY
%155 = or i32 %153, %154
%156 = load i32, i32* @S_IRUSR
%157 = load i32, i32* @S_IWUSR
%158 = or i32 %156, %157
%159 = call i32 (i8*, i32, ...) @open(i8* %150, i32 %155, i32 %158)
store i32 %159, i32* %6
%160 = load i32, i32* %6
%161 = icmp eq i32 %160, -1
br i1 %161, label %162, label %169
162: ; preds = %131
%163 = load i8**, i8*** %5
%164 = getelementptr inbounds i8*, i8** %163, i64 1
%165 = load i8*, i8** %164
%166 = load i32, i32* @errno
%167 = call i8* @strerror(i32 %166)
%168 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i8* %165, i8* %167)
store i32 1, i32* %3
store i32 1, i32* %17
br label %231
169: ; preds = %131
store i32 14, i32* %15
%170 = load i32, i32* %6
%171 = getelementptr inbounds [65535 x i8], [65535 x i8]* %8, i64 0, i64 0
%172 = load i32, i32* %15
%173 = call i32 @write(i32 %170, i8* %171, i32 %172)
store i32 %173, i32* %7
%174 = load i32, i32* %7
%175 = load i32, i32* %15
%176 = icmp ne i32 %174, %175
br i1 %176, label %177, label %184
177: ; preds = %169
%178 = load i8**, i8*** %5
%179 = getelementptr inbounds i8*, i8** %178, i64 1
%180 = load i8*, i8** %179
%181 = load i32, i32* %15
%182 = load i32, i32* %7
%183 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.11, i64 0, i64 0), i8* %180, i32 %181, i32 %182)
store i32 1, i32* %3
store i32 1, i32* %17
br label %231
184: ; preds = %169
br label %185
185: ; preds = %223, %184
%186 = load i32, i32* %15
%187 = load i32, i32* %13
%188 = icmp slt i32 %186, %187
br i1 %188, label %189, label %228
189: ; preds = %185
%190 = load i32, i32* %6
%191 = getelementptr inbounds [65535 x i8], [65535 x i8]* %8, i64 0, i64 0
%192 = load i32, i32* %15
%193 = sext i32 %192 to i64
%194 = getelementptr inbounds i8, i8* %191, i64 %193
%195 = load i16, i16* %12
%196 = zext i16 %195 to i32
%197 = call i32 @write(i32 %190, i8* %194, i32 %196)
store i32 %197, i32* %7
%198 = load i32, i32* %7
%199 = load i16, i16* %12
%200 = zext i16 %199 to i32
%201 = icmp ne i32 %198, %200
br i1 %201, label %202, label %210
202: ; preds = %189
%203 = load i8**, i8*** %5
%204 = getelementptr inbounds i8*, i8** %203, i64 1
%205 = load i8*, i8** %204
%206 = load i16, i16* %12
%207 = zext i16 %206 to i32
%208 = load i32, i32* %7
%209 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.12, i64 0, i64 0), i8* %205, i32 %207, i32 %208)
store i32 1, i32* %3
store i32 1, i32* %17
br label %231
210: ; preds = %189
%211 = load i32, i32* %6
%212 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%213 = call i32 @write(i32 %211, i8* %212, i32 4)
store i32 %213, i32* %14
%214 = load i32, i32* %14
%215 = sext i32 %214 to i64
%216 = icmp ne i64 %215, 4
br i1 %216, label %217, label %223
217: ; preds = %210
%218 = load i8**, i8*** %5
%219 = getelementptr inbounds i8*, i8** %218, i64 1
%220 = load i8*, i8** %219
%221 = load i32, i32* %14
%222 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.13, i64 0, i64 0), i8* %220, i64 4, i32 %221)
store i32 1, i32* %3
store i32 1, i32* %17
br label %231
223: ; preds = %210
%224 = load i16, i16* %12
%225 = zext i16 %224 to i32
%226 = load i32, i32* %15
%227 = add nsw i32 %226, %225
store i32 %227, i32* %15
br label %185
228: ; preds = %185
%229 = load i32, i32* %6
%230 = call i32 @close(i32 %229)
store i32 0, i32* %3
store i32 1, i32* %17
br label %231
231: ; preds = %228, %217, %202, %177, %162, %126, %114, %99, %77, %65, %52, %37, %25
%232 = load i8*, i8** %9
%233 = load i32, i32* %3
ret i32 %233
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@MAXPATHLEN = global i32 0
@.str = [19 x i8] c"Usage: %s DIALDIR\0A\00"
@.str.1 = [14 x i8] c"stat(%s): %s\0A\00"
@errno = global i32 0
@O_RDONLY = global i32 0
@.str.2 = [14 x i8] c"open(%s): %s\0A\00"
@.str.3 = [14 x i8] c"read(%s): %s\0A\00"
@.str.4 = [52 x i8] c"short read(%s): stat() == %lu vs. read length %lu.\0A\00"
@.str.5 = [8 x i8] c"%s.i386\00"
@.str.6 = [6 x i8] c".i386\00"
@.str.7 = [47 x i8] c"overflow when trying to back up %s to %s.i386.\00"
@.str.8 = [20 x i8] c"rename(%s, %s): %s\0A\00"
@.str.9 = [39 x i8] c"unknown minicom phonebook version: %d\0A\00"
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_WRONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.10 = [26 x i8] c"open(%s) for writing: %s\0A\00"
@.str.11 = [57 x i8] c"short write(%s): wanted to write %lu but only wrote %d.\0A\00"
@.str.12 = [56 x i8] c"short write(%s): wanted to write %d but only wrote %d.\0A\00"
@.str.13 = [58 x i8] c"short write(%s): wanted to write %lu but only wrote %lu.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [65535 x i8]
%4 = alloca i32
%5 = alloca %struct.stat
%6 = getelementptr inbounds [65535 x i8], [65535 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @MAXPATHLEN
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%12 = bitcast %struct.stat* %5 to i8*
%13 = icmp eq i32 %0, 2
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i8*, i8** %1
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %134
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @stat(i8* %19, %struct.stat* %5)
%21 = icmp eq i32 %20, -1
%22 = load i8*, i8** %18
br i1 %21, label %23, label %27
23: ; preds = %17
%24 = load i32, i32* @errno
%25 = tail call i8* @strerror(i32 %24)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %25)
br label %134
27: ; preds = %17
%28 = load i32, i32* @O_RDONLY
%29 = tail call i32 (i8*, i32, ...) @open(i8* %22, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load i8*, i8** %18
%33 = load i32, i32* @errno
%34 = tail call i8* @strerror(i32 %33)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %32, i8* %34)
br label %134
36: ; preds = %27
%37 = call i32 @read(i32 %29, i8* %6, i32 65535)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = load i8*, i8** %18
%41 = load i32, i32* @errno
%42 = tail call i8* @strerror(i32 %41)
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %40, i8* %42)
br label %134
44: ; preds = %36
%45 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%46 = load i32, i32* %45
%47 = icmp eq i32 %37, %46
%48 = load i8*, i8** %18
br i1 %47, label %51, label %49
49: ; preds = %44
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i8* %48, i32 %46, i32 %37)
br label %134
51: ; preds = %44
%52 = call i32 @snprintf(i8* %10, i32 %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %48)
%53 = load i8*, i8** %18
%54 = call i32 @strlen(i8* %53)
%55 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%56 = add nsw i32 %55, %54
%57 = icmp eq i32 %52, %56
%58 = load i8*, i8** %18
br i1 %57, label %61, label %59
59: ; preds = %51
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i8* %58, i8* %58)
br label %134
61: ; preds = %51
%62 = call i32 @rename(i8* %58, i8* %10)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %69
64: ; preds = %61
%65 = load i8*, i8** %18
%66 = load i32, i32* @errno
%67 = call i8* @strerror(i32 %66)
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %65, i8* %10, i8* %67)
br label %134
69: ; preds = %61
%70 = getelementptr inbounds [65535 x i8], [65535 x i8]* %3, i64 0, i64 2
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = add nsw i32 %72, -1
%74 = icmp ult i32 %73, 5
br i1 %74, label %77, label %75
75: ; preds = %69
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0), i32 %72)
br label %134
77: ; preds = %69
%78 = getelementptr inbounds [65535 x i8], [65535 x i8]* %3, i64 0, i64 5
%79 = load i8, i8* %78
%80 = zext i8 %79 to i32
%81 = getelementptr inbounds [65535 x i8], [65535 x i8]* %3, i64 0, i64 4
%82 = load i8, i8* %81
%83 = sext i8 %82 to i32
%84 = shl nsw i32 %83, 8
%85 = add i8 %79, 4
store i8 %85, i8* %78
%86 = load i8*, i8** %18
%87 = load i32, i32* @O_CREAT
%88 = load i32, i32* @O_EXCL
%89 = or i32 %88, %87
%90 = load i32, i32* @O_WRONLY
%91 = or i32 %89, %90
%92 = load i32, i32* @S_IRUSR
%93 = load i32, i32* @S_IWUSR
%94 = or i32 %93, %92
%95 = call i32 (i8*, i32, ...) @open(i8* %86, i32 %91, i32 %94)
%96 = icmp eq i32 %95, -1
br i1 %96, label %97, label %102
97: ; preds = %77
%98 = load i8*, i8** %18
%99 = load i32, i32* @errno
%100 = call i8* @strerror(i32 %99)
%101 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i8* %98, i8* %100)
br label %134
102: ; preds = %77
%103 = call i32 @write(i32 %95, i8* %6, i32 14)
%104 = icmp eq i32 %103, 14
br i1 %104, label %105, label %111
105: ; preds = %102
%106 = icmp sgt i32 %37, 14
br i1 %106, label %107, label %132
107: ; preds = %105
%108 = and i32 %84, 65280
%109 = or i32 %108, %80
%110 = zext i32 %109 to i64
br label %117
111: ; preds = %102
%112 = load i8*, i8** %18
%113 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.11, i64 0, i64 0), i8* %112, i32 14, i32 %103)
br label %134
114: ; preds = %125
%115 = trunc i64 %128 to i32
%116 = icmp sgt i32 %37, %115
br i1 %116, label %117, label %132
117: ; preds = %107, %114
%118 = phi i64 [ 14, %107 ], [ %128, %114 ]
%119 = getelementptr inbounds [65535 x i8], [65535 x i8]* %3, i64 0, i64 %118
%120 = call i32 @write(i32 %95, i8* %119, i32 %109)
%121 = icmp eq i32 %120, %109
br i1 %121, label %125, label %122
122: ; preds = %117
%123 = load i8*, i8** %18
%124 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.12, i64 0, i64 0), i8* %123, i32 %109, i32 %120)
br label %134
125: ; preds = %117
%126 = call i32 @write(i32 %95, i8* %11, i32 4)
%127 = icmp eq i32 %126, 4
%128 = add i64 %118, %110
br i1 %127, label %114, label %129
129: ; preds = %125
%130 = load i8*, i8** %18
%131 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.13, i64 0, i64 0), i8* %130, i64 4, i32 %126)
br label %134
132: ; preds = %114, %105
%133 = call i32 @close(i32 %95)
br label %134
134: ; preds = %132, %129, %122, %111, %97, %75, %64, %59, %49, %39, %31, %23, %14
%135 = phi i32 [ 1, %14 ], [ 1, %23 ], [ 1, %31 ], [ 1, %39 ], [ 1, %49 ], [ 1, %59 ], [ 1, %64 ], [ 1, %75 ], [ 1, %97 ], [ 1, %111 ], [ 1, %122 ], [ 1, %129 ], [ 0, %132 ]
ret i32 %135
}