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

/* Variables and functions */
scalar_t__ ENOENT;
int EOF;
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
char *basename(char *);
int copy(char *, char *);
scalar_t__ errno;
int /*<<< orphan*/ error();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int getchar();
int stat(char *, struct stat *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int r, ch, checkch, i;
  char target[] = "/bin";
  char *src;
  struct stat to_stat;
  if (argc < 2)
    usage();
  if (!strcmp(argv[1], "-?"))
    usage();
  r = stat(target, &to_stat);
  if (r == -1 && errno != ENOENT)
    error();
  if (r == -1 || !S_ISDIR(to_stat.st_mode)) {
    error();
  } else {
    r = 0;
    for (i = 1; i < argc; i++) {
      src = argv[i];
      fputs("Are you sure you want to install ", stdout);
      fputs(basename(src), stdout);
      fputs("? (y/n) ", stdout);
      checkch = ch = getchar();
      while (ch != '\n' && ch != EOF)
        ch = getchar();
      if (checkch != 'y')
        exit(0);
      r = copy(src, target);
      if (r)
        error();
    }
  }
  exit(r);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe44(%rip),%eax
mov    %eax,-0x25(%rbp)
mov    0xe3f(%rip),%al
mov    %al,-0x21(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11d9 <main+0x39>
mov    $0x0,%al
call   10a0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1d(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11fd <main+0x5d>
mov    $0x0,%al
call   10a0 <usage@plt>
lea    -0x25(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1090 <stat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1238 <main+0x98>
mov    0x2dba(%rip),%rax
mov    (%rax),%rax
mov    0x2d98(%rip),%rcx
cmp    (%rcx),%rax
je     1238 <main+0x98>
mov    $0x0,%al
call   10b0 <error@plt>
cmpl   $0xffffffff,-0x14(%rbp)
je     1253 <main+0xb3>
mov    -0x38(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    125f <main+0xbf>
mov    $0x0,%al
call   10b0 <error@plt>
jmp    1364 <main+0x1c4>
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    135f <main+0x1bf>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%esi
lea    0xd6f(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x30(%rbp),%rdi
call   1080 <basename@plt>
mov    %rax,%rdi
mov    0x2d1f(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2d11(%rip),%rax
mov    (%rax),%esi
lea    0xd62(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,-0x18(%rbp)
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0xa,-0x18(%rbp)
mov    %al,-0x39(%rbp)
je     12fb <main+0x15b>
mov    -0x18(%rbp),%eax
mov    0x2cf5(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    130b <main+0x16b>
jmp    131a <main+0x17a>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,-0x18(%rbp)
jmp    12da <main+0x13a>
cmpl   $0x79,-0x1c(%rbp)
je     132b <main+0x18b>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x30(%rbp),%rdi
lea    -0x25(%rbp),%rsi
call   1050 <copy@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     134c <main+0x1ac>
mov    $0x0,%al
call   10b0 <error@plt>
jmp    1351 <main+0x1b1>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    126d <main+0xcd>
jmp    1364 <main+0x1c4>
mov    -0x14(%rbp),%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
mov    %edi,%r14d
movb   $0x0,0x4(%rsp)
movl   $0x6e69622f,(%rsp)
cmp    $0x1,%edi
jg     11ce <main+0x2e>
xor    %eax,%eax
call   10a0 <usage@plt>
mov    0x10(%rsp),%rax
mov    0x8(%rax),%rdi
lea    0xe27(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    11ee <main+0x4e>
xor    %eax,%eax
call   10a0 <usage@plt>
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1090 <stat@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1221 <main+0x81>
mov    0x2dcf(%rip),%rax
mov    (%rax),%rax
mov    0x2dad(%rip),%rcx
cmp    (%rcx),%rax
je     122e <main+0x8e>
xor    %eax,%eax
call   10b0 <error@plt>
jmp    122e <main+0x8e>
mov    0x8(%rsp),%edi
call   1030 <S_ISDIR@plt>
test   %eax,%eax
jne    123c <main+0x9c>
xor    %eax,%eax
call   10b0 <error@plt>
mov    %ebp,%edi
call   10c0 <exit@plt>
xor    %ebp,%ebp
cmp    $0x2,%r14d
jl     1308 <main+0x168>
mov    %r14d,%r14d
mov    $0x1,%r15d
mov    0x2d78(%rip),%r12
mov    0x2d89(%rip),%r13
jmp    127d <main+0xdd>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15
cmp    %r14,%r15
je     1308 <main+0x168>
mov    0x10(%rsp),%rax
mov    (%rax,%r15,8),%rbp
mov    (%r12),%esi
lea    0xd77(%rip),%rdi
call   1040 <fputs@plt>
mov    %rbp,%rdi
call   1080 <basename@plt>
mov    (%r12),%esi
mov    %rax,%rdi
call   1040 <fputs@plt>
mov    (%r12),%esi
lea    0xd75(%rip),%rdi
call   1040 <fputs@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %eax,%ebx
cmp    $0xa,%eax
je     12e2 <main+0x142>
cmp    0x0(%r13),%ebx
je     12e2 <main+0x142>
xchg   %ax,%ax
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%eax
je     12e2 <main+0x142>
cmp    0x0(%r13),%eax
jne    12d0 <main+0x130>
cmp    $0x79,%ebx
jne    130f <main+0x16f>
mov    %rbp,%rdi
mov    %rsp,%rsi
call   1050 <copy@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1270 <main+0xd0>
xor    %eax,%eax
call   10b0 <error@plt>
jmp    1270 <main+0xd0>
mov    %ebp,%edi
call   10c0 <exit@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@__const.main.target = [5 x i8] c"/bin\00"
@.str = [3 x i8] c"-?\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [34 x i8] c"Are you sure you want to install \00"
@stdout = global i32 0
@.str.2 = [9 x i8] c"? (y/n) \00"
@EOF = 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 i32
%9 = alloca i32
%10 = alloca [5 x i8]
%11 = alloca i8*
%12 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast [5 x i8]* %10 to i8*
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (...) @usage()
br label %18
18: ; preds = %16, %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @strcmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%23 = icmp ne i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %18
%25 = call i32 (...) @usage()
br label %26
26: ; preds = %24, %18
%27 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 0
%28 = call i32 @stat(i8* %27, %struct.stat* %12)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %37
31: ; preds = %26
%32 = load i64, i64* @errno
%33 = load i64, i64* @ENOENT
%34 = icmp ne i64 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (...) @error()
br label %37
37: ; preds = %35, %31, %26
%38 = load i32, i32* %6
%39 = icmp eq i32 %38, -1
br i1 %39, label %45, label %40
40: ; preds = %37
%41 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%42 = load i32, i32* %41
%43 = call i32 @S_ISDIR(i32 %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %47, label %45
45: ; preds = %40, %37
%46 = call i32 (...) @error()
br label %96
47: ; preds = %40
store i32 0, i32* %6
store i32 1, i32* %9
br label %48
48: ; preds = %92, %47
%49 = load i32, i32* %9
%50 = load i32, i32* %4
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %95
52: ; preds = %48
%53 = load i8**, i8*** %5
%54 = load i32, i32* %9
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
store i8* %57, i8** %11
%58 = load i32, i32* @stdout
%59 = call i32 @fputs(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %58)
%60 = load i8*, i8** %11
%61 = call i8* @basename(i8* %60)
%62 = load i32, i32* @stdout
%63 = call i32 @fputs(i8* %61, i32 %62)
%64 = load i32, i32* @stdout
%65 = call i32 @fputs(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %64)
%66 = call i32 (...) @getchar()
store i32 %66, i32* %7
store i32 %66, i32* %8
br label %67
67: ; preds = %76, %52
%68 = load i32, i32* %7
%69 = icmp ne i32 %68, 10
br i1 %69, label %70, label %74
70: ; preds = %67
%71 = load i32, i32* %7
%72 = load i32, i32* @EOF
%73 = icmp ne i32 %71, %72
br label %74
74: ; preds = %70, %67
%75 = phi i1 [ false, %67 ], [ %73, %70 ]
br i1 %75, label %76, label %78
76: ; preds = %74
%77 = call i32 (...) @getchar()
store i32 %77, i32* %7
br label %67
78: ; preds = %74
%79 = load i32, i32* %8
%80 = icmp ne i32 %79, 121
br i1 %80, label %81, label %83
81: ; preds = %78
%82 = call i32 @exit(i32 0)
unreachable
83: ; preds = %78
%84 = load i8*, i8** %11
%85 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 0
%86 = call i32 @copy(i8* %84, i8* %85)
store i32 %86, i32* %6
%87 = load i32, i32* %6
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %83
%90 = call i32 (...) @error()
br label %91
91: ; preds = %89, %83
br label %92
92: ; preds = %91
%93 = load i32, i32* %9
%94 = add nsw i32 %93, 1
store i32 %94, i32* %9
br label %48
95: ; preds = %48
br label %96
96: ; preds = %95, %45
%97 = load i32, i32* %6
%98 = call i32 @exit(i32 %97)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@__const.main.target = [5 x i8] c"/bin\00"
@.str = [3 x i8] c"-?\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [34 x i8] c"Are you sure you want to install \00"
@stdout = global i32 0
@.str.2 = [9 x i8] c"? (y/n) \00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [5 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 (...) @usage()
br label %10
10: ; preds = %8, %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %12, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 (...) @usage()
br label %17
17: ; preds = %15, %10
%18 = call i32 @stat(i8* %5, %struct.stat* %4)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = load i64, i64* @errno
%22 = load i64, i64* @ENOENT
%23 = icmp eq i64 %21, %22
br i1 %23, label %35, label %24
24: ; preds = %20
%25 = tail call i32 (...) @error()
br label %35
26: ; preds = %17
%27 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%28 = load i32, i32* %27
%29 = tail call i32 @S_ISDIR(i32 %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %26
%32 = icmp sgt i32 %0, 1
br i1 %32, label %33, label %71
33: ; preds = %31
%34 = zext i32 %0 to i64
br label %37
35: ; preds = %20, %24, %26
%36 = tail call i32 (...) @error()
br label %71
37: ; preds = %33, %68
%38 = phi i64 [ 1, %33 ], [ %69, %68 ]
%39 = getelementptr inbounds i8*, i8** %1, i64 %38
%40 = load i8*, i8** %39
%41 = load i32, i32* @stdout
%42 = call i32 @fputs(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %41)
%43 = call i8* @basename(i8* %40)
%44 = load i32, i32* @stdout
%45 = call i32 @fputs(i8* %43, i32 %44)
%46 = load i32, i32* @stdout
%47 = call i32 @fputs(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %46)
%48 = call i32 (...) @getchar()
%49 = icmp ne i32 %48, 10
%50 = load i32, i32* @EOF
%51 = icmp ne i32 %48, %50
%52 = select i1 %49, i1 %51, i1 false
br i1 %52, label %53, label %59
53: ; preds = %37, %53
%54 = call i32 (...) @getchar()
%55 = icmp ne i32 %54, 10
%56 = load i32, i32* @EOF
%57 = icmp ne i32 %54, %56
%58 = select i1 %55, i1 %57, i1 false
br i1 %58, label %53, label %59
59: ; preds = %53, %37
%60 = icmp eq i32 %48, 121
br i1 %60, label %63, label %61
61: ; preds = %59
%62 = call i32 @exit(i32 0)
unreachable
63: ; preds = %59
%64 = call i32 @copy(i8* %40, i8* %5)
%65 = icmp eq i32 %64, 0
br i1 %65, label %68, label %66
66: ; preds = %63
%67 = call i32 (...) @error()
br label %68
68: ; preds = %63, %66
%69 = add nuw nsw i64 %38, 1
%70 = icmp eq i64 %69, %34
br i1 %70, label %71, label %37
71: ; preds = %68, %31, %35
%72 = phi i32 [ %18, %35 ], [ 0, %31 ], [ %64, %68 ]
%73 = call i32 @exit(i32 %72)
unreachable
}