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

/* Variables and functions */
int FILENAME_MAX;
scalar_t__ File(char *, char *);
scalar_t__ isEmpty(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, ...);
int /*<<< orphan*/ sync();
int system(char *);
int Update(char *file_id, char *file_name, char *action) {
  int rv = 0;
  char tmpfile[FILENAME_MAX];
  char cmdline[FILENAME_MAX];
  snprintf(tmpfile, FILENAME_MAX, "%s.tmp", file_name);
  if (File(file_id, tmpfile)) {
    snprintf(cmdline, FILENAME_MAX, "rm -f %s", tmpfile);
    rv = system(cmdline);
    return 1;
  }
  if (isEmpty(tmpfile)) {
    snprintf(cmdline, FILENAME_MAX, "rm -f %s", tmpfile);
    rv = system(cmdline);
    return 1;
  }
  snprintf(cmdline, FILENAME_MAX, "mv %s %s", tmpfile, file_name);
  rv = system(cmdline);
  rv = system(action);
  sync();
  return rv;
}


x86 assembly (clang, -O0):
<Update>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x30(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rdi
sub    %rdx,%rdi
mov    %rdi,-0x50(%rbp)
mov    %rdi,%rsp
mov    %rcx,-0x38(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rcx
lea    0xe37(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x50(%rbp),%rsi
mov    -0x10(%rbp),%rdi
call   1060 <File@plt>
cmp    $0x0,%rax
je     1225 <Update+0xd5>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rcx
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
lea    0xe08(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x58(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0x24(%rbp)
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    12c5 <Update+0x175>
mov    -0x50(%rbp),%rdi
call   1070 <isEmpty@plt>
cmp    $0x0,%rax
je     1276 <Update+0x126>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rcx
mov    0x2da1(%rip),%rax
mov    (%rax),%esi
lea    0xdb7(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x58(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0x24(%rbp)
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    12c5 <Update+0x175>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rcx
mov    0x2d63(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%r8
lea    0xd7e(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x58(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1050 <sync@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Update>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,-0x30(%rbp)
mov    %rsi,%r12
mov    %rdi,%r13
mov    0x2e79(%rip),%r14
mov    (%r14),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
lea    0xe6a(%rip),%rdx
mov    %rbx,%rdi
mov    %r12,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1060 <File@plt>
test   %rax,%rax
je     11b8 <Update+0x68>
mov    (%r14),%esi
jmp    11cc <Update+0x7c>
mov    -0x30(%rbp),%r13
mov    %rbx,%rdi
call   1070 <isEmpty@plt>
mov    (%r14),%esi
test   %rax,%rax
je     11fe <Update+0xae>
lea    0xe34(%rip),%rdx
mov    %r15,%rdi
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r15,%rdi
call   1030 <system@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe0b(%rip),%rdx
mov    %r15,%rdi
mov    %rbx,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r15,%rdi
call   1030 <system@plt>
mov    %r13,%rdi
call   1030 <system@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <sync@plt>
jmp    11ed <Update+0x9d>

LLVM IR (-O0):
@FILENAME_MAX = global i32 0
@.str = [7 x i8] c"%s.tmp\00"
@.str.1 = [9 x i8] c"rm -f %s\00"
@.str.2 = [9 x i8] c"mv %s %s\00"
define i32 @Update(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 0, i32* %8
%13 = load i32, i32* @FILENAME_MAX
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %9
%16 = alloca i8, i64 %14
store i64 %14, i64* %10
%17 = load i32, i32* @FILENAME_MAX
%18 = zext i32 %17 to i64
%19 = alloca i8, i64 %18
store i64 %18, i64* %11
%20 = load i32, i32* @FILENAME_MAX
%21 = load i8*, i8** %6
%22 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %16, i32 %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %5
%24 = call i64 @File(i8* %23, i8* %16)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %3
%27 = load i32, i32* @FILENAME_MAX
%28 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %19, i32 %27, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%29 = call i32 @system(i8* %19)
store i32 %29, i32* %8
store i32 1, i32* %4
store i32 1, i32* %12
br label %46
30: ; preds = %3
%31 = call i64 @isEmpty(i8* %16)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i32, i32* @FILENAME_MAX
%35 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %19, i32 %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%36 = call i32 @system(i8* %19)
store i32 %36, i32* %8
store i32 1, i32* %4
store i32 1, i32* %12
br label %46
37: ; preds = %30
%38 = load i32, i32* @FILENAME_MAX
%39 = load i8*, i8** %6
%40 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %19, i32 %38, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %16, i8* %39)
%41 = call i32 @system(i8* %19)
store i32 %41, i32* %8
%42 = load i8*, i8** %7
%43 = call i32 @system(i8* %42)
store i32 %43, i32* %8
%44 = call i32 (...) @sync()
%45 = load i32, i32* %8
store i32 %45, i32* %4
store i32 1, i32* %12
br label %46
46: ; preds = %37, %33, %26
%47 = load i8*, i8** %9
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
@FILENAME_MAX = global i32 0
@.str = [7 x i8] c"%s.tmp\00"
@.str.1 = [9 x i8] c"rm -f %s\00"
@.str.2 = [9 x i8] c"mv %s %s\00"
define i32 @Update(i8* %0, i8* %1, i8* nocapture %2) {
%4 = load i32, i32* @FILENAME_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = alloca i8, i64 %5
%8 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %6, i32 %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %1)
%9 = call i64 @File(i8* %0, i8* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %3
%12 = load i32, i32* @FILENAME_MAX
%13 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %7, i32 %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%14 = call i32 @system(i8* %7)
br label %27
15: ; preds = %3
%16 = call i64 @isEmpty(i8* %6)
%17 = icmp eq i64 %16, 0
%18 = load i32, i32* @FILENAME_MAX
br i1 %17, label %22, label %19
19: ; preds = %15
%20 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %7, i32 %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%21 = call i32 @system(i8* %7)
br label %27
22: ; preds = %15
%23 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %7, i32 %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %6, i8* %1)
%24 = call i32 @system(i8* %7)
%25 = call i32 @system(i8* %2)
%26 = call i32 (...) @sync()
br label %27
27: ; preds = %22, %19, %11
%28 = phi i32 [ 1, %11 ], [ 1, %19 ], [ %25, %22 ]
ret i32 %28
}