#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 {
  size_t st_size;
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ ENOENT;
int O_CREAT;
int O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int close(int);
int /*<<< orphan*/ err(int, char *, ...);
scalar_t__ errno;
int /*<<< orphan*/ errx(int, char *, ...);
scalar_t__ memcmp(char *, char const *, size_t);
int open(char const *, int, int);
int /*<<< orphan*/ printf(char *);
int read_all(int, char *, size_t);
int rename(char const *, char const *);
int stat(char const *, struct stat *);
size_t strlen(char const *);
int unlink(char const *);
int write_all(int, char const *, size_t);
int main(int argc, char *argv[]) {
  if (argc != 3)
    errx(1, "Usage: %s <path1> <path2>", argv[0]);
  const char *path1 = argv[1];
  const char *path2 = argv[2];
  const char *message = "hello world\n";
  size_t message_len = strlen(message);
  int fd = open(path1, O_WRONLY | O_CREAT | O_TRUNC, 0600);
  if (fd == -1)
    err(1, "open %s", path1);
  if (write_all(fd, message, message_len) == -1)
    err(1, "write_all");
  if (close(fd) == -1)
    err(1, "close %s", path1);
  if (rename(path1, path2) == -1)
    err(1, "rename");
  struct stat statbuf;
  if (stat(path1, &statbuf) == 0)
    errx(1, "%s unexpectedly exists", path1);
  if (errno != ENOENT)
    err(1, "stat %s", path1);
  if (stat(path2, &statbuf) == -1)
    err(1, "stat %s", path2);
  if (!S_ISREG(statbuf.st_mode))
    errx(1, "%s has wrong mode (%o)", path2, statbuf.st_mode);
  if (statbuf.st_size != message_len)
    errx(1, "%s has wrong size (%lu)", path2, statbuf.st_size);
  fd = open(path2, O_RDONLY, 0);
  if (fd == -1)
    err(1, "open %s", path2);
  char buffer[message_len];
  if (read_all(fd, buffer, message_len) == -1)
    errx(1, "read_all");
  if (memcmp(buffer, message, message_len) != 0)
    errx(1, "%s has wrong content", path2);
  if (close(fd) == -1)
    err(1, "close %s", path2);
  if (unlink(path2) == -1)
    err(1, "unlink");
  printf("TEST OK\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     120a <main+0x3a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    $0x1,%edi
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
lea    0xdf1(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d6b(%rip),%rax
mov    (%rax),%esi
mov    0x2daa(%rip),%rax
or     (%rax),%esi
mov    0x2d99(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   10d0 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    1287 <main+0xb7>
mov    -0x18(%rbp),%rdx
mov    $0x1,%edi
lea    0xda7(%rip),%rsi
mov    $0x0,%al
call   10c0 <err@plt>
mov    -0x34(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   10b0 <write_all@plt>
cmp    $0xffffffff,%eax
jne    12b3 <main+0xe3>
mov    $0x1,%edi
lea    0xd83(%rip),%rsi
mov    $0x0,%al
call   10c0 <err@plt>
mov    -0x34(%rbp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    12db <main+0x10b>
mov    -0x18(%rbp),%rdx
mov    $0x1,%edi
lea    0xd65(%rip),%rsi
mov    $0x0,%al
call   10c0 <err@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10e0 <rename@plt>
cmp    $0xffffffff,%eax
jne    1304 <main+0x134>
mov    $0x1,%edi
lea    0xd45(%rip),%rsi
mov    $0x0,%al
call   10c0 <err@plt>
mov    -0x18(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%eax
jne    1331 <main+0x161>
mov    -0x18(%rbp),%rdx
mov    $0x1,%edi
lea    0xd1f(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    0x2c90(%rip),%rax
mov    (%rax),%rax
mov    0x2c76(%rip),%rcx
cmp    (%rcx),%rax
je     1362 <main+0x192>
mov    -0x18(%rbp),%rdx
mov    $0x1,%edi
lea    0xd05(%rip),%rsi
mov    $0x0,%al
call   10c0 <err@plt>
mov    -0x20(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0xffffffff,%eax
jne    138f <main+0x1bf>
mov    -0x20(%rbp),%rdx
mov    $0x1,%edi
lea    0xcd8(%rip),%rsi
mov    $0x0,%al
call   10c0 <err@plt>
mov    -0x40(%rbp),%edi
call   10a0 <S_ISREG@plt>
cmp    $0x0,%eax
jne    13ba <main+0x1ea>
mov    -0x20(%rbp),%rdx
mov    -0x40(%rbp),%ecx
mov    $0x1,%edi
lea    0xcb5(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    -0x48(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     13e3 <main+0x213>
mov    -0x20(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    $0x1,%edi
lea    0xca3(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    -0x20(%rbp),%rdi
mov    0x2bea(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    141b <main+0x24b>
mov    -0x20(%rbp),%rdx
mov    $0x1,%edi
lea    0xc13(%rip),%rsi
mov    $0x0,%al
call   10c0 <err@plt>
mov    -0x30(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x60(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x58(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
call   10f0 <read_all@plt>
cmp    $0xffffffff,%eax
jne    146a <main+0x29a>
mov    $0x1,%edi
lea    0xc34(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    -0x60(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1080 <memcmp@plt>
cmp    $0x0,%rax
je     149c <main+0x2cc>
mov    -0x20(%rbp),%rdx
mov    $0x1,%edi
lea    0xc0b(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    -0x34(%rbp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    14c4 <main+0x2f4>
mov    -0x20(%rbp),%rdx
mov    $0x1,%edi
lea    0xb7c(%rip),%rsi
mov    $0x0,%al
call   10c0 <err@plt>
mov    -0x20(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    14e9 <main+0x319>
mov    $0x1,%edi
lea    0xbd3(%rip),%rsi
mov    $0x0,%al
call   10c0 <err@plt>
lea    0xbcc(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x50(%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   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
je     11ed <main+0x2d>
mov    (%rbx),%rdx
lea    0xe1f(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <errx@plt>
mov    0x8(%rbx),%r15
mov    0x2db8(%rip),%rax
mov    0x2df9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x10(%rbx),%r14
mov    0x2de2(%rip),%rax
or     (%rax),%esi
mov    %r15,%rdi
mov    $0x180,%edx
call   10c0 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    123a <main+0x7a>
lea    0xdfc(%rip),%rsi
mov    $0x1,%edi
mov    %r15,%rdx
xor    %eax,%eax
call   10b0 <err@plt>
lea    0xdd9(%rip),%rsi
mov    $0xc,%edx
mov    %ebx,%edi
call   10a0 <write_all@plt>
cmp    $0xffffffff,%eax
jne    1265 <main+0xa5>
lea    0xdd6(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10b0 <err@plt>
mov    %ebx,%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
jne    1287 <main+0xc7>
lea    0xdc1(%rip),%rsi
mov    $0x1,%edi
mov    %r15,%rdx
xor    %eax,%eax
call   10b0 <err@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   10d0 <rename@plt>
cmp    $0xffffffff,%eax
jne    12aa <main+0xea>
lea    0xda4(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10b0 <err@plt>
lea    -0x30(%rbp),%rsi
mov    %r15,%rdi
call   1080 <stat@plt>
test   %eax,%eax
jne    12d0 <main+0x110>
lea    0xd88(%rip),%rsi
mov    $0x1,%edi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <errx@plt>
mov    0x2cf1(%rip),%rax
mov    (%rax),%rax
mov    0x2cd7(%rip),%rcx
cmp    (%rcx),%rax
je     12fc <main+0x13c>
lea    0xd73(%rip),%rsi
mov    $0x1,%edi
mov    %r15,%rdx
xor    %eax,%eax
call   10b0 <err@plt>
lea    -0x30(%rbp),%rsi
mov    %r14,%rdi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    1323 <main+0x163>
lea    0xd4c(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   10b0 <err@plt>
mov    -0x28(%rbp),%ebx
mov    %ebx,%edi
call   1090 <S_ISREG@plt>
test   %eax,%eax
jne    1349 <main+0x189>
lea    0xd30(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
mov    %ebx,%ecx
xor    %eax,%eax
call   1050 <errx@plt>
mov    -0x30(%rbp),%rcx
cmp    $0xc,%rcx
je     1369 <main+0x1a9>
lea    0xd25(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <errx@plt>
mov    0x2c68(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
xor    %edx,%edx
call   10c0 <open@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
jne    139a <main+0x1da>
lea    0xc9c(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   10b0 <err@plt>
mov    %rsp,%r12
mov    %rsp,%rbx
add    $0xfffffffffffffff0,%rbx
mov    %rbx,%rsp
mov    $0xc,%edx
mov    %r15d,%edi
mov    %rbx,%rsi
call   10e0 <read_all@plt>
cmp    $0xffffffff,%eax
jne    13cf <main+0x20f>
lea    0xcd4(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <errx@plt>
lea    0xc44(%rip),%rsi
mov    $0xc,%edx
mov    %rbx,%rdi
call   1070 <memcmp@plt>
test   %rax,%rax
je     13fe <main+0x23e>
lea    0xcb1(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <errx@plt>
mov    %r15d,%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
jne    1421 <main+0x261>
lea    0xc27(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   10b0 <err@plt>
mov    %r14,%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    1441 <main+0x281>
lea    0xc80(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10b0 <err@plt>
lea    0xc74(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64, i32 }
@.str = [26 x i8] c"Usage: %s <path1> <path2>\00"
@.str.1 = [13 x i8] c"hello world\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.2 = [8 x i8] c"open %s\00"
@.str.3 = [10 x i8] c"write_all\00"
@.str.4 = [9 x i8] c"close %s\00"
@.str.5 = [7 x i8] c"rename\00"
@.str.6 = [23 x i8] c"%s unexpectedly exists\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.7 = [8 x i8] c"stat %s\00"
@.str.8 = [23 x i8] c"%s has wrong mode (%o)\00"
@.str.9 = [24 x i8] c"%s has wrong size (%lu)\00"
@O_RDONLY = global i32 0
@.str.10 = [9 x i8] c"read_all\00"
@.str.11 = [21 x i8] c"%s has wrong content\00"
@.str.12 = [7 x i8] c"unlink\00"
@.str.13 = [9 x i8] c"TEST OK\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca %struct.stat
%12 = alloca i8*
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %16, %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
store i8* %27, i8** %7
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8** %8
%28 = load i8*, i8** %8
%29 = call i64 @strlen(i8* %28)
store i64 %29, i64* %9
%30 = load i8*, i8** %6
%31 = load i32, i32* @O_WRONLY
%32 = load i32, i32* @O_CREAT
%33 = or i32 %31, %32
%34 = load i32, i32* @O_TRUNC
%35 = or i32 %33, %34
%36 = call i32 @open(i8* %30, i32 %35, i32 384)
store i32 %36, i32* %10
%37 = load i32, i32* %10
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %42
39: ; preds = %21
%40 = load i8*, i8** %6
%41 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %39, %21
%43 = load i32, i32* %10
%44 = load i8*, i8** %8
%45 = load i64, i64* %9
%46 = call i32 @write_all(i32 %43, i8* %44, i64 %45)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %42
%49 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %50
50: ; preds = %48, %42
%51 = load i32, i32* %10
%52 = call i32 @close(i32 %51)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = load i8*, i8** %6
%56 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %54, %50
%58 = load i8*, i8** %6
%59 = load i8*, i8** %7
%60 = call i32 @rename(i8* %58, i8* %59)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %64
62: ; preds = %57
%63 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %64
64: ; preds = %62, %57
%65 = load i8*, i8** %6
%66 = call i32 @stat(i8* %65, %struct.stat* %11)
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %64
%69 = load i8*, i8** %6
%70 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %69)
br label %71
71: ; preds = %68, %64
%72 = load i64, i64* @errno
%73 = load i64, i64* @ENOENT
%74 = icmp ne i64 %72, %73
br i1 %74, label %75, label %78
75: ; preds = %71
%76 = load i8*, i8** %6
%77 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %76)
br label %78
78: ; preds = %75, %71
%79 = load i8*, i8** %7
%80 = call i32 @stat(i8* %79, %struct.stat* %11)
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %85
82: ; preds = %78
%83 = load i8*, i8** %7
%84 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %83)
br label %85
85: ; preds = %82, %78
%86 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 1
%87 = load i32, i32* %86
%88 = call i32 @S_ISREG(i32 %87)
%89 = icmp ne i32 %88, 0
br i1 %89, label %95, label %90
90: ; preds = %85
%91 = load i8*, i8** %7
%92 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 1
%93 = load i32, i32* %92
%94 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %91, i32 %93)
br label %95
95: ; preds = %90, %85
%96 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%97 = load i64, i64* %96
%98 = load i64, i64* %9
%99 = icmp ne i64 %97, %98
br i1 %99, label %100, label %105
100: ; preds = %95
%101 = load i8*, i8** %7
%102 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%103 = load i64, i64* %102
%104 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i8* %101, i64 %103)
br label %105
105: ; preds = %100, %95
%106 = load i8*, i8** %7
%107 = load i32, i32* @O_RDONLY
%108 = call i32 @open(i8* %106, i32 %107, i32 0)
store i32 %108, i32* %10
%109 = load i32, i32* %10
%110 = icmp eq i32 %109, -1
br i1 %110, label %111, label %114
111: ; preds = %105
%112 = load i8*, i8** %7
%113 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %112)
br label %114
114: ; preds = %111, %105
%115 = load i64, i64* %9
%116 = call i8* @llvm.stacksave()
store i8* %116, i8** %12
%117 = alloca i8, i64 %115
store i64 %115, i64* %13
%118 = load i32, i32* %10
%119 = load i64, i64* %9
%120 = call i32 @read_all(i32 %118, i8* %117, i64 %119)
%121 = icmp eq i32 %120, -1
br i1 %121, label %122, label %124
122: ; preds = %114
%123 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
br label %124
124: ; preds = %122, %114
%125 = load i8*, i8** %8
%126 = load i64, i64* %9
%127 = call i64 @memcmp(i8* %117, i8* %125, i64 %126)
%128 = icmp ne i64 %127, 0
br i1 %128, label %129, label %132
129: ; preds = %124
%130 = load i8*, i8** %7
%131 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i8* %130)
br label %132
132: ; preds = %129, %124
%133 = load i32, i32* %10
%134 = call i32 @close(i32 %133)
%135 = icmp eq i32 %134, -1
br i1 %135, label %136, label %139
136: ; preds = %132
%137 = load i8*, i8** %7
%138 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %137)
br label %139
139: ; preds = %136, %132
%140 = load i8*, i8** %7
%141 = call i32 @unlink(i8* %140)
%142 = icmp eq i32 %141, -1
br i1 %142, label %143, label %145
143: ; preds = %139
%144 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
br label %145
145: ; preds = %143, %139
%146 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.13, i64 0, i64 0))
store i32 0, i32* %3
%147 = load i8*, i8** %12
%148 = load i32, i32* %3
ret i32 %148
}

LLVM IR (-O2):
%struct.stat = type { i64, i32 }
@.str = [26 x i8] c"Usage: %s <path1> <path2>\00"
@.str.1 = [13 x i8] c"hello world\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.2 = [8 x i8] c"open %s\00"
@.str.3 = [10 x i8] c"write_all\00"
@.str.4 = [9 x i8] c"close %s\00"
@.str.5 = [7 x i8] c"rename\00"
@.str.6 = [23 x i8] c"%s unexpectedly exists\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.7 = [8 x i8] c"stat %s\00"
@.str.8 = [23 x i8] c"%s has wrong mode (%o)\00"
@.str.9 = [24 x i8] c"%s has wrong size (%lu)\00"
@O_RDONLY = global i32 0
@.str.10 = [9 x i8] c"read_all\00"
@.str.11 = [21 x i8] c"%s has wrong content\00"
@.str.12 = [7 x i8] c"unlink\00"
@str = [8 x i8] c"TEST OK\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = icmp eq i32 %0, 3
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %8
8: ; preds = %5, %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_WRONLY
%14 = load i32, i32* @O_CREAT
%15 = or i32 %14, %13
%16 = load i32, i32* @O_TRUNC
%17 = or i32 %15, %16
%18 = tail call i32 @open(i8* %10, i32 %17, i32 384)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %8
%21 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %10)
br label %22
22: ; preds = %20, %8
%23 = tail call i32 @write_all(i32 %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 12)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
%28 = tail call i32 @close(i32 %18)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %10)
br label %32
32: ; preds = %30, %27
%33 = tail call i32 @rename(i8* %10, i8* %12)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %35, %32
%38 = bitcast %struct.stat* %3 to i8*
%39 = call i32 @stat(i8* %10, %struct.stat* %3)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %10)
br label %43
43: ; preds = %41, %37
%44 = load i64, i64* @errno
%45 = load i64, i64* @ENOENT
%46 = icmp eq i64 %44, %45
br i1 %46, label %49, label %47
47: ; preds = %43
%48 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %10)
br label %49
49: ; preds = %47, %43
%50 = call i32 @stat(i8* %12, %struct.stat* %3)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %12)
br label %54
54: ; preds = %52, %49
%55 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%56 = load i32, i32* %55
%57 = tail call i32 @S_ISREG(i32 %56)
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %54
%60 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %12, i32 %56)
br label %61
61: ; preds = %59, %54
%62 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%63 = load i64, i64* %62
%64 = icmp eq i64 %63, 12
br i1 %64, label %67, label %65
65: ; preds = %61
%66 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i8* %12, i64 %63)
br label %67
67: ; preds = %65, %61
%68 = load i32, i32* @O_RDONLY
%69 = tail call i32 @open(i8* %12, i32 %68, i32 0)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %73
71: ; preds = %67
%72 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %12)
br label %73
73: ; preds = %71, %67
%74 = tail call i8* @llvm.stacksave()
%75 = alloca [12 x i8]
%76 = getelementptr inbounds [12 x i8], [12 x i8]* %75, i64 0, i64 0
%77 = call i32 @read_all(i32 %69, i8* %76, i64 12)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %81
79: ; preds = %73
%80 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
br label %81
81: ; preds = %79, %73
%82 = call i64 @memcmp(i8* %76, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 12)
%83 = icmp eq i64 %82, 0
br i1 %83, label %86, label %84
84: ; preds = %81
%85 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i8* %12)
br label %86
86: ; preds = %84, %81
%87 = call i32 @close(i32 %69)
%88 = icmp eq i32 %87, -1
br i1 %88, label %89, label %91
89: ; preds = %86
%90 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %12)
br label %91
91: ; preds = %89, %86
%92 = call i32 @unlink(i8* %12)
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %96
94: ; preds = %91
%95 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
br label %96
96: ; preds = %94, %91
%97 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
ret i32 0
}