#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int /*<<< orphan*/ chmod(char *, int);
int /*<<< orphan*/ copy(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int mkstemp(char *);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char *argv[]) {
  FILE *ffp, *tfp;
  char *ffile, tfile[20];
  int fd;
  while (--argc) {
    if (NULL == (ffp = fopen(ffile = *++argv, "r"))) {
      fprintf(stderr, "Can't open %s\n", ffile);
      continue;
    }
    strcpy(tfile, "tfXXXXXX");
    fd = mkstemp(tfile);
    if (NULL == (tfp = fdopen(fd, "w"))) {
      fprintf(stderr, "Can't create %s\n", tfile);
      fclose(ffp);
      continue;
    }
    copy(ffp, tfp);
    fclose(ffp);
    fclose(tfp);
    unlink(ffile);
    rename(tfile, ffile);
    chmod(ffile, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     1308 <main+0x158>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
mov    %rdi,-0x28(%rbp)
lea    0xe0a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    122b <main+0x7b>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xde1(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11c6 <main+0x16>
lea    -0x40(%rbp),%rdi
lea    0xddb(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x40(%rbp),%rdi
call   1080 <mkstemp@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edi
lea    0xdc9(%rip),%rsi
call   1090 <fdopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    128f <main+0xdf>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rdx
lea    0xda0(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
jmp    11c6 <main+0x16>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <copy@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10c0 <rename@plt>
mov    -0x28(%rbp),%rdi
mov    0x2ce9(%rip),%rax
mov    (%rax),%esi
mov    0x2d08(%rip),%rax
or     (%rax),%esi
mov    0x2ce7(%rip),%rax
or     (%rax),%esi
mov    0x2cfe(%rip),%rax
or     (%rax),%esi
mov    0x2ccd(%rip),%rax
or     (%rax),%esi
mov    0x2cac(%rip),%rax
or     (%rax),%esi
call   10a0 <chmod@plt>
jmp    11c6 <main+0x16>
xor    %edi,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,0x8(%rsp)
cmp    $0x1,%edi
jne    11cf <main+0x1f>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    %edi,%r14d
mov    $0x1,%r13d
lea    0x10(%rsp),%rbx
jmp    1201 <main+0x51>
nop
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
mov    %r15,%rdx
call   1070 <fprintf@plt>
add    $0x1,%r13
cmp    %r13d,%r14d
je     11c8 <main+0x18>
mov    0x8(%rsp),%rax
mov    (%rax,%r13,8),%r15
mov    %r15,%rdi
lea    0xdec(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     11e0 <main+0x30>
mov    %rax,%r12
mov    %rbx,%rdi
lea    0xde6(%rip),%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1080 <mkstemp@plt>
mov    %eax,%edi
lea    0xdd9(%rip),%rsi
call   1090 <fdopen@plt>
test   %rax,%rax
je     12c0 <main+0x110>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %rax,%rsi
call   1060 <copy@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1030 <unlink@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10c0 <rename@plt>
mov    0x2d5d(%rip),%rax
mov    (%rax),%esi
mov    0x2d2c(%rip),%rax
or     (%rax),%esi
mov    0x2d33(%rip),%rax
or     (%rax),%esi
mov    0x2d4a(%rip),%rax
or     (%rax),%esi
mov    0x2d19(%rip),%rax
or     (%rax),%esi
mov    0x2cf8(%rip),%rax
or     (%rax),%esi
mov    %r15,%rdi
call   10a0 <chmod@plt>
jmp    11f8 <main+0x48>
nop
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
lea    0xd4c(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
jmp    11f8 <main+0x48>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"Can't open %s\0A\00"
@.str.2 = [9 x i8] c"tfXXXXXX\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [17 x i8] c"Can't create %s\0A\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca [20 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %11
11: ; preds = %39, %33, %21, %2
%12 = load i32, i32* %4
%13 = add nsw i32 %12, -1
store i32 %13, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %65
15: ; preds = %11
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i32 1
store i8** %17, i8*** %5
%18 = load i8*, i8** %17
store i8* %18, i8** %8
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %6
%20 = icmp eq i32* null, %19
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %8
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %11
25: ; preds = %15
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%27 = call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%29 = call i32 @mkstemp(i8* %28)
store i32 %29, i32* %10
%30 = load i32, i32* %10
%31 = call i32* @fdopen(i32 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %31, i32** %7
%32 = icmp eq i32* null, %31
br i1 %32, label %33, label %39
33: ; preds = %25
%34 = load i32, i32* @stderr
%35 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%36 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %35)
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
br label %11
39: ; preds = %25
%40 = load i32*, i32** %6
%41 = load i32*, i32** %7
%42 = call i32 @copy(i32* %40, i32* %41)
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
%45 = load i32*, i32** %7
%46 = call i32 @fclose(i32* %45)
%47 = load i8*, i8** %8
%48 = call i32 @unlink(i8* %47)
%49 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%50 = load i8*, i8** %8
%51 = call i32 @rename(i8* %49, i8* %50)
%52 = load i8*, i8** %8
%53 = load i32, i32* @S_IRUSR
%54 = load i32, i32* @S_IWUSR
%55 = or i32 %53, %54
%56 = load i32, i32* @S_IRGRP
%57 = or i32 %55, %56
%58 = load i32, i32* @S_IWGRP
%59 = or i32 %57, %58
%60 = load i32, i32* @S_IROTH
%61 = or i32 %59, %60
%62 = load i32, i32* @S_IWOTH
%63 = or i32 %61, %62
%64 = call i32 @chmod(i8* %52, i32 %63)
br label %11
65: ; preds = %11
%66 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"Can't open %s\0A\00"
@.str.2 = [9 x i8] c"tfXXXXXX\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [17 x i8] c"Can't create %s\0A\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = add nsw i32 %0, -1
%6 = icmp eq i32 %5, 0
br i1 %6, label %47, label %7
7: ; preds = %2, %17
%8 = phi i32 [ %18, %17 ], [ %5, %2 ]
%9 = phi i8** [ %10, %17 ], [ %1, %2 ]
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %20
14: ; preds = %7
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %17
17: ; preds = %14, %25, %29
%18 = add nsw i32 %8, -1
%19 = icmp eq i32 %18, 0
br i1 %19, label %47, label %7
20: ; preds = %7
%21 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @mkstemp(i8* %4)
%23 = call i32* @fdopen(i32 %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%28 = call i32 @fclose(i32* %12)
br label %17
29: ; preds = %20
%30 = call i32 @copy(i32* %12, i32* %23)
%31 = call i32 @fclose(i32* %12)
%32 = call i32 @fclose(i32* %23)
%33 = call i32 @unlink(i8* %11)
%34 = call i32 @rename(i8* %4, i8* %11)
%35 = load i32, i32* @S_IRUSR
%36 = load i32, i32* @S_IWUSR
%37 = or i32 %36, %35
%38 = load i32, i32* @S_IRGRP
%39 = or i32 %37, %38
%40 = load i32, i32* @S_IWGRP
%41 = or i32 %39, %40
%42 = load i32, i32* @S_IROTH
%43 = or i32 %41, %42
%44 = load i32, i32* @S_IWOTH
%45 = or i32 %43, %44
%46 = call i32 @chmod(i8* %11, i32 %45)
br label %17
47: ; preds = %17, %2
%48 = call i32 @exit(i32 0)
unreachable
}