#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 EOF;
int EXIT_FAILURE;
char *build_dst(char const *, char const *);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fgetc(int /*<<< orphan*/);
int file_exists(char *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ isatty(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int rename(char const *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int do_move(const char *src, const char *dst, int interactive) {
  char *built_dst = NULL;
  int err = 0;
  int exists = 0;
  built_dst = build_dst(src, dst);
  if (!built_dst) {
    perror("do_move call to build_dst failed");
    exit(EXIT_FAILURE);
  }
  if (interactive == 2 && !isatty(fileno(stdin))) {
    interactive = 1;
  }
  if (interactive > 1) {
    exists = file_exists(built_dst);
    if (exists) {
      int yesno;
      if (exists == 1) {
        fprintf(stderr, "'%s' already exists. Overwrite? [Yn] ", built_dst);
      } else if (exists == 2) {
        fprintf(stderr, "'%s' is in use. Overwrite on reboot? [Yn] ",
                built_dst);
      }
      fflush(stderr);
      if ((yesno = fgetc(stdin)) == EOF) {
        fputs("Reading from STDIN failed.\n", stderr);
        return EXIT_FAILURE;
      }
      if (yesno == 'n' || yesno == 'N') {
        return exists == 2 ? EXIT_FAILURE : 0;
      }
    }
  }
  err = rename(src, built_dst ? built_dst : dst);
  if (err) {
    err = errno;
  }
  if (built_dst) {
    free(built_dst);
  }
  return err;
}


x86 assembly (clang, -O0):
<do_move>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <build_dst@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    121f <do_move+0x5f>
lea    0xdf4(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
cmpl   $0x2,-0x1c(%rbp)
jne    124e <do_move+0x8e>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   10a0 <fileno@plt>
mov    %eax,%edi
call   1050 <isatty@plt>
cmp    $0x0,%eax
jne    124e <do_move+0x8e>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jle    1360 <do_move+0x1a0>
mov    -0x28(%rbp),%rdi
call   1040 <file_exists@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     135b <do_move+0x19b>
cmpl   $0x1,-0x30(%rbp)
jne    1296 <do_move+0xd6>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd95(%rip),%rsi
call   1090 <fprintf@plt>
jmp    12be <do_move+0xfe>
cmpl   $0x2,-0x30(%rbp)
jne    12b9 <do_move+0xf9>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd93(%rip),%rsi
call   1090 <fprintf@plt>
jmp    12be <do_move+0xfe>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
call   1070 <fgetc@plt>
mov    %eax,-0x34(%rbp)
mov    0x2cfc(%rip),%rcx
cmp    (%rcx),%eax
jne    1312 <do_move+0x152>
mov    0x2cdd(%rip),%rax
mov    (%rax),%esi
lea    0xd76(%rip),%rdi
call   1060 <fputs@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13c8 <do_move+0x208>
cmpl   $0x6e,-0x34(%rbp)
je     1326 <do_move+0x166>
cmpl   $0x4e,-0x34(%rbp)
jne    1356 <do_move+0x196>
cmpl   $0x2,-0x30(%rbp)
jne    1341 <do_move+0x181>
mov    0x2c89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
jmp    134b <do_move+0x18b>
xor    %eax,%eax
mov    %eax,-0x38(%rbp)
jmp    134b <do_move+0x18b>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13c8 <do_move+0x208>
jmp    135b <do_move+0x19b>
jmp    1360 <do_move+0x1a0>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1380 <do_move+0x1c0>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1388 <do_move+0x1c8>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   10d0 <rename@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     13ae <do_move+0x1ee>
mov    0x2c1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     13c2 <do_move+0x202>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_move>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rdi,%r14
call   1080 <build_dst@plt>
test   %rax,%rax
je     12c8 <do_move+0x108>
mov    %rax,%rbx
cmp    $0x2,%ebp
jne    1200 <do_move+0x40>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   10a0 <fileno@plt>
mov    %eax,%edi
call   1050 <isatty@plt>
test   %eax,%eax
jne    1206 <do_move+0x46>
jmp    1299 <do_move+0xd9>
jl     1299 <do_move+0xd9>
mov    %rbx,%rdi
call   1040 <file_exists@plt>
test   %eax,%eax
je     1299 <do_move+0xd9>
mov    %eax,%r15d
cmp    $0x1,%eax
je     122d <do_move+0x6d>
cmp    $0x2,%r15d
jne    1245 <do_move+0x85>
lea    0xe1c(%rip),%rsi
jmp    1234 <do_move+0x74>
lea    0xded(%rip),%rsi
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rdx
call   1090 <fprintf@plt>
mov    0x2d84(%rip),%rbp
mov    0x0(%rbp),%edi
call   10b0 <fflush@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
call   1070 <fgetc@plt>
mov    0x2d77(%rip),%rcx
cmp    (%rcx),%eax
jne    1287 <do_move+0xc7>
mov    0x0(%rbp),%esi
lea    0xdfb(%rip),%rdi
call   1060 <fputs@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%ebp
jmp    12bb <do_move+0xfb>
and    $0xffffffdf,%eax
cmp    $0x4e,%eax
jne    1299 <do_move+0xd9>
xor    %ebp,%ebp
cmp    $0x2,%r15d
je     127c <do_move+0xbc>
jmp    12bb <do_move+0xfb>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10d0 <rename@plt>
mov    %eax,%ebp
test   %eax,%eax
je     12b3 <do_move+0xf3>
mov    0x2d17(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd31(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"do_move call to build_dst failed\00"
@EXIT_FAILURE = global i32 0
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [38 x i8] c"'%s' already exists. Overwrite? [Yn] \00"
@.str.2 = [43 x i8] c"'%s' is in use. Overwrite on reboot? [Yn] \00"
@EOF = global i32 0
@.str.3 = [28 x i8] c"Reading from STDIN failed.\0A\00"
@errno = global i32 0
define i32 @do_move(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* null, i8** %8
store i32 0, i32* %9
store i32 0, i32* %10
%12 = load i8*, i8** %5
%13 = load i8*, i8** %6
%14 = call i8* @build_dst(i8* %12, i8* %13)
store i8* %14, i8** %8
%15 = load i8*, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %21, label %17
17: ; preds = %3
%18 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %3
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, 2
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i32, i32* @stdin
%26 = call i32 @fileno(i32 %25)
%27 = call i32 @isatty(i32 %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %24
store i32 1, i32* %7
br label %30
30: ; preds = %29, %24, %21
%31 = load i32, i32* %7
%32 = icmp sgt i32 %31, 1
br i1 %32, label %33, label %80
33: ; preds = %30
%34 = load i8*, i8** %8
%35 = call i32 @file_exists(i8* %34)
store i32 %35, i32* %10
%36 = load i32, i32* %10
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %79
38: ; preds = %33
%39 = load i32, i32* %10
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %8
%44 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %43)
br label %53
45: ; preds = %38
%46 = load i32, i32* %10
%47 = icmp eq i32 %46, 2
br i1 %47, label %48, label %52
48: ; preds = %45
%49 = load i32, i32* @stderr
%50 = load i8*, i8** %8
%51 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %48, %45
br label %53
53: ; preds = %52, %41
%54 = load i32, i32* @stderr
%55 = call i32 @fflush(i32 %54)
%56 = load i32, i32* @stdin
%57 = call i32 @fgetc(i32 %56)
store i32 %57, i32* %11
%58 = load i32, i32* @EOF
%59 = icmp eq i32 %57, %58
br i1 %59, label %60, label %64
60: ; preds = %53
%61 = load i32, i32* @stderr
%62 = call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %61)
%63 = load i32, i32* @EXIT_FAILURE
store i32 %63, i32* %4
br label %103
64: ; preds = %53
%65 = load i32, i32* %11
%66 = icmp eq i32 %65, 110
br i1 %66, label %70, label %67
67: ; preds = %64
%68 = load i32, i32* %11
%69 = icmp eq i32 %68, 78
br i1 %69, label %70, label %78
70: ; preds = %67, %64
%71 = load i32, i32* %10
%72 = icmp eq i32 %71, 2
br i1 %72, label %73, label %75
73: ; preds = %70
%74 = load i32, i32* @EXIT_FAILURE
br label %76
75: ; preds = %70
br label %76
76: ; preds = %75, %73
%77 = phi i32 [ %74, %73 ], [ 0, %75 ]
store i32 %77, i32* %4
br label %103
78: ; preds = %67
br label %79
79: ; preds = %78, %33
br label %80
80: ; preds = %79, %30
%81 = load i8*, i8** %5
%82 = load i8*, i8** %8
%83 = icmp ne i8* %82, null
br i1 %83, label %84, label %86
84: ; preds = %80
%85 = load i8*, i8** %8
br label %88
86: ; preds = %80
%87 = load i8*, i8** %6
br label %88
88: ; preds = %86, %84
%89 = phi i8* [ %85, %84 ], [ %87, %86 ]
%90 = call i32 @rename(i8* %81, i8* %89)
store i32 %90, i32* %9
%91 = load i32, i32* %9
%92 = icmp ne i32 %91, 0
br i1 %92, label %93, label %95
93: ; preds = %88
%94 = load i32, i32* @errno
store i32 %94, i32* %9
br label %95
95: ; preds = %93, %88
%96 = load i8*, i8** %8
%97 = icmp ne i8* %96, null
br i1 %97, label %98, label %101
98: ; preds = %95
%99 = load i8*, i8** %8
%100 = call i32 @free(i8* %99)
br label %101
101: ; preds = %98, %95
%102 = load i32, i32* %9
store i32 %102, i32* %4
br label %103
103: ; preds = %101, %76, %60
%104 = load i32, i32* %4
ret i32 %104
}

LLVM IR (-O2):
@.str = [33 x i8] c"do_move call to build_dst failed\00"
@EXIT_FAILURE = global i32 0
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [38 x i8] c"'%s' already exists. Overwrite? [Yn] \00"
@.str.2 = [43 x i8] c"'%s' is in use. Overwrite on reboot? [Yn] \00"
@EOF = global i32 0
@.str.3 = [28 x i8] c"Reading from STDIN failed.\0A\00"
@errno = global i32 0
define i32 @do_move(i8* %0, i8* %1, i32 %2) {
%4 = tail call i8* @build_dst(i8* %0, i8* %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %3
%11 = icmp eq i32 %2, 2
br i1 %11, label %12, label %17
12: ; preds = %10
%13 = load i32, i32* @stdin
%14 = tail call i32 @fileno(i32 %13)
%15 = tail call i32 @isatty(i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %44, label %19
17: ; preds = %10
%18 = icmp sgt i32 %2, 1
br i1 %18, label %19, label %44
19: ; preds = %12, %17
%20 = tail call i32 @file_exists(i8* %4)
switch i32 %20, label %26 [
i32 0, label %44
i32 1, label %22
i32 2, label %21
]
21: ; preds = %19
br label %22
22: ; preds = %19, %21
%23 = phi i8* [ getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), %21 ], [ getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), %19 ]
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* %23, i8* %4)
br label %26
26: ; preds = %22, %19
%27 = load i32, i32* @stderr
%28 = tail call i32 @fflush(i32 %27)
%29 = load i32, i32* @stdin
%30 = tail call i32 @fgetc(i32 %29)
%31 = load i32, i32* @EOF
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %37
33: ; preds = %26
%34 = load i32, i32* @stderr
%35 = tail call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = load i32, i32* @EXIT_FAILURE
br label %50
37: ; preds = %26
%38 = and i32 %30, -33
%39 = icmp eq i32 %38, 78
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = icmp eq i32 %20, 2
%42 = load i32, i32* @EXIT_FAILURE
%43 = select i1 %41, i32 %42, i32 0
br label %50
44: ; preds = %12, %37, %19, %17
%45 = tail call i32 @rename(i8* %0, i8* %4)
%46 = icmp eq i32 %45, 0
%47 = load i32, i32* @errno
%48 = select i1 %46, i32 0, i32 %47
%49 = tail call i32 @free(i8* %4)
br label %50
50: ; preds = %40, %33, %44
%51 = phi i32 [ %48, %44 ], [ %43, %40 ], [ %36, %33 ]
ret i32 %51
}