#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*/ tempfile;
typedef int pid_t;
typedef int /*<<< orphan*/ lockfile;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
scalar_t__ EEXIST;
scalar_t__ ENOENT;
scalar_t__ ESRCH;
int /*<<< orphan*/ O_RDONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int fchmod(int, int);
int /*<<< orphan*/ free(char *);
int getpid();
int kill(int, int /*<<< orphan*/);
int link(char *, char *);
int /*<<< orphan*/ message(int /*<<< orphan*/, char *, char *, ...);
int mkstemp(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ qprintf(char *, int, char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int sscanf(char *, char *, int *);
char *strchr(char *, char);
char *strdup(char const *);
int /*<<< orphan*/ strerror(scalar_t__);
int strlen(char *);
scalar_t__ strncmp(char const *, char *, int);
int unlink(char *);
int write(int, char *, int);
pid_t drv_generic_serial_lock_port(const char *Port) {
  char lockfile[256];
  char tempfile[256];
  char buffer[16];
  char *port, *p;
  int fd, len, pid;
  if (strncmp(Port, "/dev/", 5) == 0) {
    port = strdup(Port + 5);
  } else {
    port = strdup(Port);
  }
  while ((p = strchr(port, '/')) != NULL) {
    *p = '_';
  }
  qprintf(lockfile, sizeof(lockfile), "/var/lock/LCK..%s", port);
  qprintf(tempfile, sizeof(tempfile), "/var/lock/LCK..%s", "TMP.XXXXXX");
  free(port);
  if ((fd = mkstemp(tempfile)) == -1) {
    message(0, "mkstemp(%s) failed: %s", tempfile, strerror(errno));
    return -1;
  }
  if (fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1) {
    message(0, "fchmod(%s) failed: %s", tempfile, strerror(errno));
    close(fd);
    unlink(tempfile);
    return -1;
  }
  snprintf(buffer, sizeof(buffer), "%10d\n", (int)getpid());
  len = strlen(buffer);
  if (write(fd, buffer, len) != len) {
    message(0, "write(%s) failed: %s", tempfile, strerror(errno));
    close(fd);
    unlink(tempfile);
    return -1;
  }
  close(fd);
  while (link(tempfile, lockfile) == -1) {
    if (errno != EEXIST) {
      message(0, "link(%s, %s) failed: %s", tempfile, lockfile,
              strerror(errno));
      unlink(tempfile);
      return -1;
    }
    if ((fd = open(lockfile, O_RDONLY)) == -1) {
      if (errno == ENOENT)
        continue;
      message(0, "open(%s) failed: %s", lockfile, strerror(errno));
      unlink(tempfile);
      return -1;
    }
    len = read(fd, buffer, sizeof(buffer) - 1);
    if (len < 0) {
      message(0, "read(%s) failed: %s", lockfile, strerror(errno));
      unlink(tempfile);
      return -1;
    }
    buffer[len] = '\0';
    if (sscanf(buffer, "%d", &pid) != 1 || pid == 0) {
      message(0, "scan(%s) failed.", lockfile);
      unlink(tempfile);
      return -1;
    }
    if (pid == getpid()) {
      message(0, "%s already locked by us. uh-oh...", lockfile);
      unlink(tempfile);
      return 0;
    }
    if ((kill(pid, 0) == -1) && errno == ESRCH) {
      message(0, "removing stale lockfile %s", lockfile);
      if (unlink(lockfile) == -1 && errno != ENOENT) {
        message(0, "unlink(%s) failed: %s", lockfile, strerror(errno));
        unlink(tempfile);
        return pid;
      }
      continue;
    }
    unlink(tempfile);
    return pid;
  }
  unlink(tempfile);
  return 0;
}


x86 assembly (clang, -O0):
<drv_generic_serial_lock_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x290,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xda6(%rip),%rsi
mov    $0x5,%edx
call   1060 <strncmp@plt>
cmp    $0x0,%rax
jne    1287 <drv_generic_serial_lock_port+0x47>
mov    -0x10(%rbp),%rdi
add    $0x5,%rdi
call   1150 <strdup@plt>
mov    %rax,-0x228(%rbp)
jmp    1297 <drv_generic_serial_lock_port+0x57>
mov    -0x10(%rbp),%rdi
call   1150 <strdup@plt>
mov    %rax,-0x228(%rbp)
jmp    129c <drv_generic_serial_lock_port+0x5c>
mov    -0x228(%rbp),%rdi
mov    $0x2f,%esi
call   10a0 <strchr@plt>
mov    %rax,-0x230(%rbp)
cmp    $0x0,%rax
je     12cd <drv_generic_serial_lock_port+0x8d>
mov    -0x230(%rbp),%rax
movb   $0x5f,(%rax)
jmp    129c <drv_generic_serial_lock_port+0x5c>
lea    -0x110(%rbp),%rdi
mov    -0x228(%rbp),%rcx
mov    $0x100,%esi
lea    0xd1f(%rip),%rdx
call   1140 <qprintf@plt>
lea    -0x210(%rbp),%rdi
mov    $0x100,%esi
lea    0xd07(%rip),%rdx
lea    0xd12(%rip),%rcx
call   1140 <qprintf@plt>
mov    -0x228(%rbp),%rdi
call   1030 <free@plt>
lea    -0x210(%rbp),%rdi
call   1100 <mkstemp@plt>
mov    %eax,-0x234(%rbp)
cmp    $0xffffffff,%eax
jne    1374 <drv_generic_serial_lock_port+0x134>
lea    -0x210(%rbp),%rax
mov    %rax,-0x248(%rbp)
mov    0x2c81(%rip),%rax
mov    (%rax),%rdi
call   1160 <strerror@plt>
mov    -0x248(%rbp),%rdx
mov    %eax,%ecx
xor    %edi,%edi
lea    0xcc2(%rip),%rsi
mov    $0x0,%al
call   1040 <message@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1829 <drv_generic_serial_lock_port+0x5e9>
mov    -0x234(%rbp),%edi
mov    0x2c2f(%rip),%rax
mov    (%rax),%esi
mov    0x2c56(%rip),%rax
or     (%rax),%esi
mov    0x2c2d(%rip),%rax
or     (%rax),%esi
mov    0x2c1c(%rip),%rax
or     (%rax),%esi
call   1110 <fchmod@plt>
cmp    $0xffffffff,%eax
jne    1405 <drv_generic_serial_lock_port+0x1c5>
lea    -0x210(%rbp),%rax
mov    %rax,-0x250(%rbp)
mov    0x2c07(%rip),%rax
mov    (%rax),%rdi
call   1160 <strerror@plt>
mov    -0x250(%rbp),%rdx
mov    %eax,%ecx
xor    %edi,%edi
lea    0xc5f(%rip),%rsi
mov    $0x0,%al
call   1040 <message@plt>
mov    -0x234(%rbp),%edi
call   10c0 <close@plt>
lea    -0x210(%rbp),%rdi
call   1050 <unlink@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1829 <drv_generic_serial_lock_port+0x5e9>
lea    -0x220(%rbp),%rax
mov    %rax,-0x258(%rbp)
mov    $0x0,%al
call   1080 <getpid@plt>
mov    -0x258(%rbp),%rdi
mov    %eax,%ecx
mov    $0x10,%esi
lea    0xc21(%rip),%rdx
call   10b0 <snprintf@plt>
lea    -0x220(%rbp),%rdi
call   1090 <strlen@plt>
mov    %eax,-0x238(%rbp)
mov    -0x234(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    -0x238(%rbp),%edx
call   1070 <write@plt>
cmp    -0x238(%rbp),%eax
je     14c3 <drv_generic_serial_lock_port+0x283>
lea    -0x210(%rbp),%rax
mov    %rax,-0x260(%rbp)
mov    0x2b49(%rip),%rax
mov    (%rax),%rdi
call   1160 <strerror@plt>
mov    -0x260(%rbp),%rdx
mov    %eax,%ecx
xor    %edi,%edi
lea    0xbbd(%rip),%rsi
mov    $0x0,%al
call   1040 <message@plt>
mov    -0x234(%rbp),%edi
call   10c0 <close@plt>
lea    -0x210(%rbp),%rdi
call   1050 <unlink@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1829 <drv_generic_serial_lock_port+0x5e9>
mov    -0x234(%rbp),%edi
call   10c0 <close@plt>
lea    -0x210(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1130 <link@plt>
cmp    $0xffffffff,%eax
jne    1816 <drv_generic_serial_lock_port+0x5d6>
mov    0x2ad7(%rip),%rax
mov    (%rax),%rax
mov    0x2ad5(%rip),%rcx
cmp    (%rcx),%rax
je     1568 <drv_generic_serial_lock_port+0x328>
lea    -0x210(%rbp),%rax
mov    %rax,-0x270(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x268(%rbp)
mov    0x2aa1(%rip),%rax
mov    (%rax),%rdi
call   1160 <strerror@plt>
mov    -0x270(%rbp),%rdx
mov    -0x268(%rbp),%rcx
mov    %eax,%r8d
xor    %edi,%edi
lea    0xb22(%rip),%rsi
mov    $0x0,%al
call   1040 <message@plt>
lea    -0x210(%rbp),%rdi
call   1050 <unlink@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1829 <drv_generic_serial_lock_port+0x5e9>
lea    -0x110(%rbp),%rdi
mov    0x2a72(%rip),%rax
mov    (%rax),%esi
call   1120 <open@plt>
mov    %eax,-0x234(%rbp)
cmp    $0xffffffff,%eax
jne    15f9 <drv_generic_serial_lock_port+0x3b9>
mov    0x2a35(%rip),%rax
mov    (%rax),%rax
mov    0x2a03(%rip),%rcx
cmp    (%rcx),%rax
jne    15ab <drv_generic_serial_lock_port+0x36b>
jmp    14ce <drv_generic_serial_lock_port+0x28e>
lea    -0x110(%rbp),%rax
mov    %rax,-0x278(%rbp)
mov    0x2a08(%rip),%rax
mov    (%rax),%rdi
call   1160 <strerror@plt>
mov    -0x278(%rbp),%rdx
mov    %eax,%ecx
xor    %edi,%edi
lea    0xaa9(%rip),%rsi
mov    $0x0,%al
call   1040 <message@plt>
lea    -0x210(%rbp),%rdi
call   1050 <unlink@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1829 <drv_generic_serial_lock_port+0x5e9>
mov    -0x234(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0xf,%edx
call   10d0 <read@plt>
mov    %eax,-0x238(%rbp)
cmpl   $0x0,-0x238(%rbp)
jge    1671 <drv_generic_serial_lock_port+0x431>
lea    -0x110(%rbp),%rax
mov    %rax,-0x280(%rbp)
mov    0x2990(%rip),%rax
mov    (%rax),%rdi
call   1160 <strerror@plt>
mov    -0x280(%rbp),%rdx
mov    %eax,%ecx
xor    %edi,%edi
lea    0xa45(%rip),%rsi
mov    $0x0,%al
call   1040 <message@plt>
lea    -0x210(%rbp),%rdi
call   1050 <unlink@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1829 <drv_generic_serial_lock_port+0x5e9>
movslq -0x238(%rbp),%rax
movb   $0x0,-0x220(%rbp,%rax,1)
lea    -0x220(%rbp),%rdi
lea    0xa1d(%rip),%rsi
lea    -0x23c(%rbp),%rdx
call   10f0 <sscanf@plt>
cmp    $0x1,%eax
jne    16b0 <drv_generic_serial_lock_port+0x470>
cmpl   $0x0,-0x23c(%rbp)
jne    16df <drv_generic_serial_lock_port+0x49f>
lea    -0x110(%rbp),%rdx
xor    %edi,%edi
lea    0x9ee(%rip),%rsi
mov    $0x0,%al
call   1040 <message@plt>
lea    -0x210(%rbp),%rdi
call   1050 <unlink@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1829 <drv_generic_serial_lock_port+0x5e9>
mov    -0x23c(%rbp),%eax
mov    %eax,-0x284(%rbp)
mov    $0x0,%al
call   1080 <getpid@plt>
mov    %eax,%ecx
mov    -0x284(%rbp),%eax
cmp    %ecx,%eax
jne    1731 <drv_generic_serial_lock_port+0x4f1>
lea    -0x110(%rbp),%rdx
xor    %edi,%edi
lea    0x9ad(%rip),%rsi
mov    $0x0,%al
call   1040 <message@plt>
lea    -0x210(%rbp),%rdi
call   1050 <unlink@plt>
movl   $0x0,-0x4(%rbp)
jmp    1829 <drv_generic_serial_lock_port+0x5e9>
mov    -0x23c(%rbp),%edi
xor    %esi,%esi
call   10e0 <kill@plt>
cmp    $0xffffffff,%eax
jne    17fc <drv_generic_serial_lock_port+0x5bc>
mov    0x287a(%rip),%rax
mov    (%rax),%rax
mov    0x2840(%rip),%rcx
cmp    (%rcx),%rax
jne    17fc <drv_generic_serial_lock_port+0x5bc>
lea    -0x110(%rbp),%rdx
xor    %edi,%edi
lea    0x970(%rip),%rsi
mov    $0x0,%al
call   1040 <message@plt>
lea    -0x110(%rbp),%rdi
call   1050 <unlink@plt>
cmp    $0xffffffff,%eax
jne    17f7 <drv_generic_serial_lock_port+0x5b7>
mov    0x2834(%rip),%rax
mov    (%rax),%rax
mov    0x2802(%rip),%rcx
cmp    (%rcx),%rax
je     17f7 <drv_generic_serial_lock_port+0x5b7>
lea    -0x110(%rbp),%rax
mov    %rax,-0x290(%rbp)
mov    0x280c(%rip),%rax
mov    (%rax),%rdi
call   1160 <strerror@plt>
mov    -0x290(%rbp),%rdx
mov    %eax,%ecx
xor    %edi,%edi
lea    0x926(%rip),%rsi
mov    $0x0,%al
call   1040 <message@plt>
lea    -0x210(%rbp),%rdi
call   1050 <unlink@plt>
mov    -0x23c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1829 <drv_generic_serial_lock_port+0x5e9>
jmp    14ce <drv_generic_serial_lock_port+0x28e>
lea    -0x210(%rbp),%rdi
call   1050 <unlink@plt>
mov    -0x23c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1829 <drv_generic_serial_lock_port+0x5e9>
lea    -0x210(%rbp),%rdi
call   1050 <unlink@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x290,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drv_generic_serial_lock_port>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rdi,%rbx
lea    0xda5(%rip),%rsi
mov    $0x5,%edx
call   1060 <strncmp@plt>
test   %rax,%rax
jne    126e <drv_generic_serial_lock_port+0x2e>
add    $0x5,%rbx
mov    %rbx,%rdi
call   1150 <strdup@plt>
mov    %rax,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   10a0 <strchr@plt>
test   %rax,%rax
je     1297 <drv_generic_serial_lock_port+0x57>
movb   $0x5f,(%rax)
jmp    1280 <drv_generic_serial_lock_port+0x40>
lea    0xd68(%rip),%r14
lea    0x120(%rsp),%rdi
mov    $0x100,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1140 <qprintf@plt>
lea    0xd5b(%rip),%rcx
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1140 <qprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1100 <mkstemp@plt>
cmp    $0xffffffff,%eax
je     138d <drv_generic_serial_lock_port+0x14d>
mov    %eax,%ebx
mov    0x2cbc(%rip),%rax
mov    0x2ce5(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2cba(%rip),%rax
or     (%rax),%esi
mov    0x2ca9(%rip),%rax
or     (%rax),%esi
mov    %ebx,%edi
call   1110 <fchmod@plt>
cmp    $0xffffffff,%eax
je     13b5 <drv_generic_serial_lock_port+0x175>
xor    %eax,%eax
call   1080 <getpid@plt>
lea    0xd21(%rip),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x10,%esi
mov    %eax,%ecx
call   10b0 <snprintf@plt>
mov    %r14,%rdi
call   1090 <strlen@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1070 <write@plt>
cmp    %ebp,%eax
jne    13cd <drv_generic_serial_lock_port+0x18d>
mov    %ebx,%edi
call   10c0 <close@plt>
lea    0x20(%rsp),%rdi
lea    0x120(%rsp),%rsi
call   1130 <link@plt>
cmp    $0xffffffff,%eax
je     141e <drv_generic_serial_lock_port+0x1de>
lea    0x20(%rsp),%rdi
call   1050 <unlink@plt>
xor    %ebx,%ebx
jmp    140a <drv_generic_serial_lock_port+0x1ca>
mov    0x2c34(%rip),%rax
mov    (%rax),%rdi
call   1160 <strerror@plt>
lea    0xc80(%rip),%rsi
lea    0x20(%rsp),%rdx
xor    %edi,%edi
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <message@plt>
jmp    1405 <drv_generic_serial_lock_port+0x1c5>
mov    0x2c0c(%rip),%rax
mov    (%rax),%rdi
call   1160 <strerror@plt>
lea    0xc6f(%rip),%rsi
jmp    13e3 <drv_generic_serial_lock_port+0x1a3>
mov    0x2bf4(%rip),%rax
mov    (%rax),%rdi
call   1160 <strerror@plt>
lea    0xc73(%rip),%rsi
lea    0x20(%rsp),%rbp
xor    %edi,%edi
mov    %rbp,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <message@plt>
mov    %ebx,%edi
call   10c0 <close@plt>
mov    %rbp,%rdi
call   1050 <unlink@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ba3(%rip),%rbp
mov    0x2ba4(%rip),%r12
mov    0x2bb5(%rip),%r13
lea    0x120(%rsp),%rbx
lea    0x10(%rsp),%r15
jmp    146c <drv_generic_serial_lock_port+0x22c>
mov    0x0(%rbp),%rdi
mov    0x2b53(%rip),%rax
cmp    (%rax),%rdi
jne    15f3 <drv_generic_serial_lock_port+0x3b3>
lea    0x20(%rsp),%rdi
mov    %rbx,%rsi
call   1130 <link@plt>
cmp    $0xffffffff,%eax
jne    137f <drv_generic_serial_lock_port+0x13f>
mov    0x0(%rbp),%rdi
cmp    (%r12),%rdi
jne    156e <drv_generic_serial_lock_port+0x32e>
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1120 <open@plt>
cmp    $0xffffffff,%eax
je     1442 <drv_generic_serial_lock_port+0x202>
mov    %eax,%edi
mov    %r15,%rsi
mov    $0xf,%edx
call   10d0 <read@plt>
test   %eax,%eax
js     159e <drv_generic_serial_lock_port+0x35e>
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r15,%rdi
lea    0xbf8(%rip),%rsi
lea    0xc(%rsp),%rdx
call   10f0 <sscanf@plt>
cmp    $0x1,%eax
jne    15b0 <drv_generic_serial_lock_port+0x370>
mov    0xc(%rsp),%r14d
test   %r14d,%r14d
je     15b0 <drv_generic_serial_lock_port+0x370>
xor    %eax,%eax
call   1080 <getpid@plt>
cmp    %eax,%r14d
je     15ca <drv_generic_serial_lock_port+0x38a>
mov    0xc(%rsp),%edi
xor    %esi,%esi
call   10e0 <kill@plt>
cmp    $0xffffffff,%eax
jne    155b <drv_generic_serial_lock_port+0x31b>
mov    0x0(%rbp),%rax
mov    0x2a99(%rip),%rcx
cmp    (%rcx),%rax
jne    155b <drv_generic_serial_lock_port+0x31b>
xor    %edi,%edi
lea    0xbd4(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <message@plt>
mov    %rbx,%rdi
call   1050 <unlink@plt>
cmp    $0xffffffff,%eax
jne    1456 <drv_generic_serial_lock_port+0x216>
mov    0x0(%rbp),%rdi
mov    0x2a6d(%rip),%rax
cmp    (%rax),%rdi
je     1456 <drv_generic_serial_lock_port+0x216>
call   1160 <strerror@plt>
lea    0xbb4(%rip),%rsi
lea    0x120(%rsp),%rdx
xor    %edi,%edi
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <message@plt>
lea    0x20(%rsp),%rdi
call   1050 <unlink@plt>
mov    0xc(%rsp),%ebx
jmp    140a <drv_generic_serial_lock_port+0x1ca>
call   1160 <strerror@plt>
lea    0xaf1(%rip),%rsi
lea    0x20(%rsp),%rbx
lea    0x120(%rsp),%rcx
xor    %edi,%edi
mov    %rbx,%rdx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <message@plt>
mov    %rbx,%rdi
jmp    1400 <drv_generic_serial_lock_port+0x1c0>
mov    0x0(%rbp),%rdi
call   1160 <strerror@plt>
lea    0xae9(%rip),%rsi
jmp    15ff <drv_generic_serial_lock_port+0x3bf>
lea    0xaf7(%rip),%rsi
lea    0x120(%rsp),%rdx
xor    %edi,%edi
xor    %eax,%eax
call   1040 <message@plt>
jmp    1612 <drv_generic_serial_lock_port+0x3d2>
lea    0xaee(%rip),%rsi
xor    %ebx,%ebx
lea    0x120(%rsp),%rdx
xor    %edi,%edi
xor    %eax,%eax
call   1040 <message@plt>
lea    0x20(%rsp),%rdi
call   1050 <unlink@plt>
jmp    140a <drv_generic_serial_lock_port+0x1ca>
call   1160 <strerror@plt>
lea    0xa84(%rip),%rsi
lea    0x120(%rsp),%rdx
xor    %edi,%edi
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <message@plt>
lea    0x20(%rsp),%rdi
jmp    1400 <drv_generic_serial_lock_port+0x1c0>

LLVM IR (-O0):
@.str = [6 x i8] c"/dev/\00"
@.str.1 = [18 x i8] c"/var/lock/LCK..%s\00"
@.str.2 = [11 x i8] c"TMP.XXXXXX\00"
@.str.3 = [23 x i8] c"mkstemp(%s) failed: %s\00"
@errno = global i64 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.4 = [22 x i8] c"fchmod(%s) failed: %s\00"
@.str.5 = [6 x i8] c"%10d\0A\00"
@.str.6 = [21 x i8] c"write(%s) failed: %s\00"
@EEXIST = global i64 0
@.str.7 = [24 x i8] c"link(%s, %s) failed: %s\00"
@O_RDONLY = global i32 0
@ENOENT = global i64 0
@.str.8 = [20 x i8] c"open(%s) failed: %s\00"
@.str.9 = [20 x i8] c"read(%s) failed: %s\00"
@.str.10 = [3 x i8] c"%d\00"
@.str.11 = [17 x i8] c"scan(%s) failed.\00"
@.str.12 = [34 x i8] c"%s already locked by us. uh-oh...\00"
@ESRCH = global i64 0
@.str.13 = [27 x i8] c"removing stale lockfile %s\00"
@.str.14 = [22 x i8] c"unlink(%s) failed: %s\00"
define i32 @drv_generic_serial_lock_port(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = alloca [16 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %3
%12 = load i8*, i8** %3
%13 = call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 5
%18 = call i8* @strdup(i8* %17)
store i8* %18, i8** %7
br label %22
19: ; preds = %1
%20 = load i8*, i8** %3
%21 = call i8* @strdup(i8* %20)
store i8* %21, i8** %7
br label %22
22: ; preds = %19, %15
br label %23
23: ; preds = %27, %22
%24 = load i8*, i8** %7
%25 = call i8* @strchr(i8* %24, i8 signext 47)
store i8* %25, i8** %8
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = load i8*, i8** %8
store i8 95, i8* %28
br label %23
29: ; preds = %23
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%31 = load i8*, i8** %7
%32 = call i32 @qprintf(i8* %30, i32 256, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%34 = call i32 @qprintf(i8* %33, i32 256, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%35 = load i8*, i8** %7
%36 = call i32 @free(i8* %35)
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%38 = call i32 @mkstemp(i8* %37)
store i32 %38, i32* %9
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %45
40: ; preds = %29
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%42 = load i64, i64* @errno
%43 = call i32 @strerror(i64 %42)
%44 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %41, i32 %43)
store i32 -1, i32* %2
br label %194
45: ; preds = %29
%46 = load i32, i32* %9
%47 = load i32, i32* @S_IRUSR
%48 = load i32, i32* @S_IWUSR
%49 = or i32 %47, %48
%50 = load i32, i32* @S_IRGRP
%51 = or i32 %49, %50
%52 = load i32, i32* @S_IROTH
%53 = or i32 %51, %52
%54 = call i32 @fchmod(i32 %46, i32 %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %65
56: ; preds = %45
%57 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%58 = load i64, i64* @errno
%59 = call i32 @strerror(i64 %58)
%60 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %57, i32 %59)
%61 = load i32, i32* %9
%62 = call i32 @close(i32 %61)
%63 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%64 = call i32 @unlink(i8* %63)
store i32 -1, i32* %2
br label %194
65: ; preds = %45
%66 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%67 = call i32 (...) @getpid()
%68 = call i32 @snprintf(i8* %66, i32 16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %67)
%69 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%70 = call i32 @strlen(i8* %69)
store i32 %70, i32* %10
%71 = load i32, i32* %9
%72 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%73 = load i32, i32* %10
%74 = call i32 @write(i32 %71, i8* %72, i32 %73)
%75 = load i32, i32* %10
%76 = icmp ne i32 %74, %75
br i1 %76, label %77, label %86
77: ; preds = %65
%78 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%79 = load i64, i64* @errno
%80 = call i32 @strerror(i64 %79)
%81 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %78, i32 %80)
%82 = load i32, i32* %9
%83 = call i32 @close(i32 %82)
%84 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%85 = call i32 @unlink(i8* %84)
store i32 -1, i32* %2
br label %194
86: ; preds = %65
%87 = load i32, i32* %9
%88 = call i32 @close(i32 %87)
br label %89
89: ; preds = %186, %115, %86
%90 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%91 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%92 = call i32 @link(i8* %90, i8* %91)
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %191
94: ; preds = %89
%95 = load i64, i64* @errno
%96 = load i64, i64* @EEXIST
%97 = icmp ne i64 %95, %96
br i1 %97, label %98, label %106
98: ; preds = %94
%99 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%100 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%101 = load i64, i64* @errno
%102 = call i32 @strerror(i64 %101)
%103 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %99, i8* %100, i32 %102)
%104 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%105 = call i32 @unlink(i8* %104)
store i32 -1, i32* %2
br label %194
106: ; preds = %94
%107 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%108 = load i32, i32* @O_RDONLY
%109 = call i32 @open(i8* %107, i32 %108)
store i32 %109, i32* %9
%110 = icmp eq i32 %109, -1
br i1 %110, label %111, label %123
111: ; preds = %106
%112 = load i64, i64* @errno
%113 = load i64, i64* @ENOENT
%114 = icmp eq i64 %112, %113
br i1 %114, label %115, label %116
115: ; preds = %111
br label %89
116: ; preds = %111
%117 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%118 = load i64, i64* @errno
%119 = call i32 @strerror(i64 %118)
%120 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %117, i32 %119)
%121 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%122 = call i32 @unlink(i8* %121)
store i32 -1, i32* %2
br label %194
123: ; preds = %106
%124 = load i32, i32* %9
%125 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%126 = call i32 @read(i32 %124, i8* %125, i32 15)
store i32 %126, i32* %10
%127 = load i32, i32* %10
%128 = icmp slt i32 %127, 0
br i1 %128, label %129, label %136
129: ; preds = %123
%130 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%131 = load i64, i64* @errno
%132 = call i32 @strerror(i64 %131)
%133 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i8* %130, i32 %132)
%134 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%135 = call i32 @unlink(i8* %134)
store i32 -1, i32* %2
br label %194
136: ; preds = %123
%137 = load i32, i32* %10
%138 = sext i32 %137 to i64
%139 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 %138
store i8 0, i8* %139
%140 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%141 = call i32 @sscanf(i8* %140, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32* %11)
%142 = icmp ne i32 %141, 1
br i1 %142, label %146, label %143
143: ; preds = %136
%144 = load i32, i32* %11
%145 = icmp eq i32 %144, 0
br i1 %145, label %146, label %151
146: ; preds = %143, %136
%147 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%148 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0), i8* %147)
%149 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%150 = call i32 @unlink(i8* %149)
store i32 -1, i32* %2
br label %194
151: ; preds = %143
%152 = load i32, i32* %11
%153 = call i32 (...) @getpid()
%154 = icmp eq i32 %152, %153
br i1 %154, label %155, label %160
155: ; preds = %151
%156 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%157 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.12, i64 0, i64 0), i8* %156)
%158 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%159 = call i32 @unlink(i8* %158)
store i32 0, i32* %2
br label %194
160: ; preds = %151
%161 = load i32, i32* %11
%162 = call i32 @kill(i32 %161, i32 0)
%163 = icmp eq i32 %162, -1
br i1 %163, label %164, label %187
164: ; preds = %160
%165 = load i64, i64* @errno
%166 = load i64, i64* @ESRCH
%167 = icmp eq i64 %165, %166
br i1 %167, label %168, label %187
168: ; preds = %164
%169 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%170 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0), i8* %169)
%171 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%172 = call i32 @unlink(i8* %171)
%173 = icmp eq i32 %172, -1
br i1 %173, label %174, label %186
174: ; preds = %168
%175 = load i64, i64* @errno
%176 = load i64, i64* @ENOENT
%177 = icmp ne i64 %175, %176
br i1 %177, label %178, label %186
178: ; preds = %174
%179 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%180 = load i64, i64* @errno
%181 = call i32 @strerror(i64 %180)
%182 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.14, i64 0, i64 0), i8* %179, i32 %181)
%183 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%184 = call i32 @unlink(i8* %183)
%185 = load i32, i32* %11
store i32 %185, i32* %2
br label %194
186: ; preds = %174, %168
br label %89
187: ; preds = %164, %160
%188 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%189 = call i32 @unlink(i8* %188)
%190 = load i32, i32* %11
store i32 %190, i32* %2
br label %194
191: ; preds = %89
%192 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%193 = call i32 @unlink(i8* %192)
store i32 0, i32* %2
br label %194
194: ; preds = %191, %187, %178, %155, %146, %129, %116, %98, %77, %56, %40
%195 = load i32, i32* %2
ret i32 %195
}

LLVM IR (-O2):
@.str = [6 x i8] c"/dev/\00"
@.str.1 = [18 x i8] c"/var/lock/LCK..%s\00"
@.str.2 = [11 x i8] c"TMP.XXXXXX\00"
@.str.3 = [23 x i8] c"mkstemp(%s) failed: %s\00"
@errno = global i64 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.4 = [22 x i8] c"fchmod(%s) failed: %s\00"
@.str.5 = [6 x i8] c"%10d\0A\00"
@.str.6 = [21 x i8] c"write(%s) failed: %s\00"
@EEXIST = global i64 0
@.str.7 = [24 x i8] c"link(%s, %s) failed: %s\00"
@O_RDONLY = global i32 0
@ENOENT = global i64 0
@.str.8 = [20 x i8] c"open(%s) failed: %s\00"
@.str.9 = [20 x i8] c"read(%s) failed: %s\00"
@.str.10 = [3 x i8] c"%d\00"
@.str.11 = [17 x i8] c"scan(%s) failed.\00"
@.str.12 = [34 x i8] c"%s already locked by us. uh-oh...\00"
@ESRCH = global i64 0
@.str.13 = [27 x i8] c"removing stale lockfile %s\00"
@.str.14 = [22 x i8] c"unlink(%s) failed: %s\00"
define i32 @drv_generic_serial_lock_port(i8* %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = alloca [16 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%9 = bitcast i32* %5 to i8*
%10 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = getelementptr inbounds i8, i8* %0, i64 5
%14 = tail call i8* @strdup(i8* %13)
br label %17
15: ; preds = %1
%16 = tail call i8* @strdup(i8* %0)
br label %17
17: ; preds = %15, %12
%18 = phi i8* [ %14, %12 ], [ %16, %15 ]
%19 = tail call i8* @strchr(i8* dereferenceable(1) %18, i8 signext 47)
%20 = icmp eq i8* %19, null
br i1 %20, label %25, label %21
21: ; preds = %17, %21
%22 = phi i8* [ %23, %21 ], [ %19, %17 ]
store i8 95, i8* %22
%23 = tail call i8* @strchr(i8* dereferenceable(1) %18, i8 signext 47)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %21
25: ; preds = %21, %17
%26 = call i32 @qprintf(i8* %6, i32 256, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%27 = call i32 @qprintf(i8* %7, i32 256, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @free(i8* %18)
%29 = call i32 @mkstemp(i8* %7)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %25
%32 = load i64, i64* @errno
%33 = call i32 @strerror(i64 %32)
%34 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %7, i32 %33)
br label %141
35: ; preds = %25
%36 = load i32, i32* @S_IRUSR
%37 = load i32, i32* @S_IWUSR
%38 = or i32 %37, %36
%39 = load i32, i32* @S_IRGRP
%40 = or i32 %38, %39
%41 = load i32, i32* @S_IROTH
%42 = or i32 %40, %41
%43 = call i32 @fchmod(i32 %29, i32 %42)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %51
45: ; preds = %35
%46 = load i64, i64* @errno
%47 = call i32 @strerror(i64 %46)
%48 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %7, i32 %47)
%49 = call i32 @close(i32 %29)
%50 = call i32 @unlink(i8* %7)
br label %141
51: ; preds = %35
%52 = call i32 (...) @getpid()
%53 = call i32 @snprintf(i8* %8, i32 16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %52)
%54 = call i32 @strlen(i8* %8)
%55 = call i32 @write(i32 %29, i8* %8, i32 %54)
%56 = icmp eq i32 %55, %54
br i1 %56, label %63, label %57
57: ; preds = %51
%58 = load i64, i64* @errno
%59 = call i32 @strerror(i64 %58)
%60 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %7, i32 %59)
%61 = call i32 @close(i32 %29)
%62 = call i32 @unlink(i8* %7)
br label %141
63: ; preds = %51
%64 = call i32 @close(i32 %29)
%65 = call i32 @link(i8* %7, i8* %6)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %139
67: ; preds = %63, %133
%68 = load i64, i64* @errno
%69 = load i64, i64* @EEXIST
%70 = icmp eq i64 %68, %69
br i1 %70, label %75, label %71
71: ; preds = %67
%72 = call i32 @strerror(i64 %68)
%73 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %7, i8* %6, i32 %72)
%74 = call i32 @unlink(i8* %7)
br label %141
75: ; preds = %67
%76 = load i32, i32* @O_RDONLY
%77 = call i32 @open(i8* %6, i32 %76)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %87
79: ; preds = %75
%80 = load i64, i64* @errno
%81 = load i64, i64* @ENOENT
%82 = icmp eq i64 %80, %81
br i1 %82, label %133, label %83
83: ; preds = %79
%84 = call i32 @strerror(i64 %80)
%85 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %6, i32 %84)
%86 = call i32 @unlink(i8* %7)
br label %141
87: ; preds = %75
%88 = call i32 @read(i32 %77, i8* %8, i32 15)
%89 = icmp slt i32 %88, 0
br i1 %89, label %90, label %95
90: ; preds = %87
%91 = load i64, i64* @errno
%92 = call i32 @strerror(i64 %91)
%93 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i8* %6, i32 %92)
%94 = call i32 @unlink(i8* %7)
br label %141
95: ; preds = %87
%96 = zext i32 %88 to i64
%97 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 %96
store i8 0, i8* %97
%98 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32* %5)
%99 = icmp ne i32 %98, 1
%100 = load i32, i32* %5
%101 = icmp eq i32 %100, 0
%102 = select i1 %99, i1 true, i1 %101
br i1 %102, label %103, label %106
103: ; preds = %95
%104 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0), i8* %6)
%105 = call i32 @unlink(i8* %7)
br label %141
106: ; preds = %95
%107 = call i32 (...) @getpid()
%108 = icmp eq i32 %100, %107
br i1 %108, label %109, label %112
109: ; preds = %106
%110 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.12, i64 0, i64 0), i8* %6)
%111 = call i32 @unlink(i8* %7)
br label %141
112: ; preds = %106
%113 = load i32, i32* %5
%114 = call i32 @kill(i32 %113, i32 0)
%115 = icmp eq i32 %114, -1
br i1 %115, label %116, label %136
116: ; preds = %112
%117 = load i64, i64* @errno
%118 = load i64, i64* @ESRCH
%119 = icmp eq i64 %117, %118
br i1 %119, label %120, label %136
120: ; preds = %116
%121 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0), i8* %6)
%122 = call i32 @unlink(i8* %6)
%123 = icmp eq i32 %122, -1
br i1 %123, label %124, label %133
124: ; preds = %120
%125 = load i64, i64* @errno
%126 = load i64, i64* @ENOENT
%127 = icmp eq i64 %125, %126
br i1 %127, label %133, label %128
128: ; preds = %124
%129 = call i32 @strerror(i64 %125)
%130 = call i32 (i32, i8*, i8*, ...) @message(i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.14, i64 0, i64 0), i8* %6, i32 %129)
%131 = call i32 @unlink(i8* %7)
%132 = load i32, i32* %5
br label %141
133: ; preds = %120, %124, %79
%134 = call i32 @link(i8* %7, i8* %6)
%135 = icmp eq i32 %134, -1
br i1 %135, label %67, label %139
136: ; preds = %116, %112
%137 = call i32 @unlink(i8* %7)
%138 = load i32, i32* %5
br label %141
139: ; preds = %133, %63
%140 = call i32 @unlink(i8* %7)
br label %141
141: ; preds = %139, %136, %128, %109, %103, %90, %83, %71, %57, %45, %31
%142 = phi i32 [ -1, %31 ], [ -1, %45 ], [ -1, %57 ], [ -1, %71 ], [ -1, %83 ], [ -1, %90 ], [ -1, %103 ], [ 0, %109 ], [ %132, %128 ], [ %138, %136 ], [ 0, %139 ]
ret i32 %142
}