#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 EXIT_FAILURE;
scalar_t__ EXIT_SUCCESS;
char *check_diversion(char *);
scalar_t__ check_predepends();
scalar_t__ dpkg_compare_versions(char *, char *, char *);
int /*<<< orphan*/ dpkg_divert_add(char *, char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ symlink(char *, char *);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char *argv[]) {
  int targetlen;
  char target[4096 + 1], answer[1024];
  if (argc < 2) {
    printf("\nbash/preinst: expected at least one argument\n\n");
    return EXIT_FAILURE;
  }
  if (check_predepends() != EXIT_SUCCESS) {
    printf("\nPlease upgrade to a new version of dpkg\n\n");
    return EXIT_FAILURE;
  }
  if (strcmp(argv[1], "upgrade") == 0) {
    if (argc < 3) {
      printf("\nbash/preinst upgrade: expected at least two arguments\n\n");
      return EXIT_FAILURE;
    }
    if (dpkg_compare_versions(argv[2], "lt", "2.05b-4") == EXIT_SUCCESS) {
      char *diversion = check_diversion("/bin/sh");
      if (diversion == NULL)
        return EXIT_FAILURE;
      if (strcmp(diversion, "") == 0) {
        dpkg_divert_add("bash", "/bin/sh");
        unlink("/bin/sh");
        symlink("dash", "/bin/sh");
      }
      diversion = check_diversion("/usr/share/man/man1/sh.1.gz");
      if (diversion == NULL)
        return EXIT_FAILURE;
      if (strcmp(diversion, "") == 0) {
        dpkg_divert_add("bash", "/usr/share/man/man1/sh.1.gz");
        unlink("/usr/share/man/man1/sh.1.gz");
        symlink("dash.1.gz", "/usr/share/man/man1/sh.1.gz");
      }
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c0 <main+0x40>
lea    0xe56(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    137d <main+0x1fd>
mov    $0x0,%al
call   1090 <check_predepends@plt>
mov    0x2e0a(%rip),%rcx
cmp    (%rcx),%rax
je     11f4 <main+0x74>
lea    0xe52(%rip),%rdi
call   1050 <printf@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    137d <main+0x1fd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe58(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1370 <main+0x1f0>
cmpl   $0x3,-0x8(%rbp)
jge    1239 <main+0xb9>
lea    0xe40(%rip),%rdi
call   1050 <printf@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    137d <main+0x1fd>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe54(%rip),%rsi
lea    0xe50(%rip),%rdx
call   1030 <dpkg_compare_versions@plt>
mov    0x2d7d(%rip),%rcx
cmp    (%rcx),%rax
jne    136b <main+0x1eb>
lea    0xe3c(%rip),%rdi
call   10a0 <check_diversion@plt>
mov    %rax,-0x1428(%rbp)
cmpq   $0x0,-0x1428(%rbp)
jne    1296 <main+0x116>
mov    0x2d54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    137d <main+0x1fd>
mov    -0x1428(%rbp),%rdi
lea    0xdb6(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12e5 <main+0x165>
lea    0xdf5(%rip),%rdi
lea    0xde6(%rip),%rsi
call   1070 <dpkg_divert_add@plt>
lea    0xdda(%rip),%rdi
call   1040 <unlink@plt>
lea    0xddb(%rip),%rdi
lea    0xdc7(%rip),%rsi
call   1060 <symlink@plt>
lea    0xdcd(%rip),%rdi
call   10a0 <check_diversion@plt>
mov    %rax,-0x1428(%rbp)
cmpq   $0x0,-0x1428(%rbp)
jne    1317 <main+0x197>
mov    0x2cd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    137d <main+0x1fd>
mov    -0x1428(%rbp),%rdi
lea    0xd35(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1366 <main+0x1e6>
lea    0xd74(%rip),%rdi
lea    0xd77(%rip),%rsi
call   1070 <dpkg_divert_add@plt>
lea    0xd6b(%rip),%rdi
call   1040 <unlink@plt>
lea    0xd7b(%rip),%rdi
lea    0xd58(%rip),%rsi
call   1060 <symlink@plt>
jmp    136b <main+0x1eb>
jmp    1370 <main+0x1f0>
mov    0x2c61(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x1,%edi
jg     1192 <main+0x12>
lea    0xf1d(%rip),%rdi
jmp    11cb <main+0x4b>
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1090 <check_predepends@plt>
mov    0x2e33(%rip),%r14
cmp    (%r14),%rax
jne    11c4 <main+0x44>
mov    0x8(%rbx),%rdi
lea    0xe4b(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     11de <main+0x5e>
mov    (%r14),%eax
jmp    11d9 <main+0x59>
lea    0xeb8(%rip),%rdi
call   1050 <puts@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
cmp    $0x2,%ebp
ja     11ec <main+0x6c>
lea    0xe61(%rip),%rdi
jmp    11cb <main+0x4b>
mov    0x10(%rbx),%rdi
lea    0xe11(%rip),%rsi
lea    0xe0d(%rip),%rdx
call   1030 <dpkg_compare_versions@plt>
cmp    (%r14),%rax
jne    11bf <main+0x3f>
lea    0xe04(%rip),%rdi
call   10a0 <check_diversion@plt>
test   %rax,%rax
je     11d0 <main+0x50>
lea    0xe8c(%rip),%rsi
mov    %rax,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    125a <main+0xda>
lea    0xde7(%rip),%rdi
lea    0xdd8(%rip),%rbx
mov    %rbx,%rsi
call   1070 <dpkg_divert_add@plt>
mov    %rbx,%rdi
call   1040 <unlink@plt>
lea    0xdce(%rip),%rdi
mov    %rbx,%rsi
call   1060 <symlink@plt>
lea    0xdc4(%rip),%rdi
call   10a0 <check_diversion@plt>
test   %rax,%rax
je     11d0 <main+0x50>
lea    0xe36(%rip),%rsi
mov    %rax,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    11bf <main+0x3f>
lea    0xd8d(%rip),%rdi
lea    0xd90(%rip),%rbx
mov    %rbx,%rsi
call   1070 <dpkg_divert_add@plt>
mov    %rbx,%rdi
call   1040 <unlink@plt>
lea    0xd95(%rip),%rdi
mov    %rbx,%rsi
call   1060 <symlink@plt>
jmp    11bf <main+0x3f>

LLVM IR (-O0):
@.str = [48 x i8] c"\0Abash/preinst: expected at least one argument\0A\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i64 0
@.str.1 = [43 x i8] c"\0APlease upgrade to a new version of dpkg\0A\0A\00"
@.str.2 = [8 x i8] c"upgrade\00"
@.str.3 = [57 x i8] c"\0Abash/preinst upgrade: expected at least two arguments\0A\0A\00"
@.str.4 = [3 x i8] c"lt\00"
@.str.5 = [8 x i8] c"2.05b-4\00"
@.str.6 = [8 x i8] c"/bin/sh\00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [5 x i8] c"bash\00"
@.str.9 = [5 x i8] c"dash\00"
@.str.10 = [28 x i8] c"/usr/share/man/man1/sh.1.gz\00"
@.str.11 = [10 x i8] c"dash.1.gz\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [4097 x i8]
%8 = alloca [1024 x i8]
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %3
br label %74
15: ; preds = %2
%16 = call i64 (...) @check_predepends()
%17 = load i64, i64* @EXIT_SUCCESS
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
store i32 %21, i32* %3
br label %74
22: ; preds = %15
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %71
28: ; preds = %22
%29 = load i32, i32* %4
%30 = icmp slt i32 %29, 3
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
store i32 %33, i32* %3
br label %74
34: ; preds = %28
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i64 @dpkg_compare_versions(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%39 = load i64, i64* @EXIT_SUCCESS
%40 = icmp eq i64 %38, %39
br i1 %40, label %41, label %70
41: ; preds = %34
%42 = call i8* @check_diversion(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
store i8* %42, i8** %9
%43 = load i8*, i8** %9
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = load i32, i32* @EXIT_FAILURE
store i32 %46, i32* %3
br label %74
47: ; preds = %41
%48 = load i8*, i8** %9
%49 = call i64 @strcmp(i8* %48, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %47
%52 = call i32 @dpkg_divert_add(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%53 = call i32 @unlink(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%54 = call i32 @symlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %55
55: ; preds = %51, %47
%56 = call i8* @check_diversion(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
store i8* %56, i8** %9
%57 = load i8*, i8** %9
%58 = icmp eq i8* %57, null
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = load i32, i32* @EXIT_FAILURE
store i32 %60, i32* %3
br label %74
61: ; preds = %55
%62 = load i8*, i8** %9
%63 = call i64 @strcmp(i8* %62, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %61
%66 = call i32 @dpkg_divert_add(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
%67 = call i32 @unlink(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
%68 = call i32 @symlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
br label %69
69: ; preds = %65, %61
br label %70
70: ; preds = %69, %34
br label %71
71: ; preds = %70, %22
%72 = load i64, i64* @EXIT_SUCCESS
%73 = trunc i64 %72 to i32
store i32 %73, i32* %3
br label %74
74: ; preds = %71, %59, %45, %31, %19, %12
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i64 0
@.str.2 = [8 x i8] c"upgrade\00"
@.str.4 = [3 x i8] c"lt\00"
@.str.5 = [8 x i8] c"2.05b-4\00"
@.str.6 = [8 x i8] c"/bin/sh\00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [5 x i8] c"bash\00"
@.str.9 = [5 x i8] c"dash\00"
@.str.10 = [28 x i8] c"/usr/share/man/man1/sh.1.gz\00"
@.str.11 = [10 x i8] c"dash.1.gz\00"
@str = [56 x i8] c"\0Abash/preinst upgrade: expected at least two arguments\0A\00"
@str.12 = [42 x i8] c"\0APlease upgrade to a new version of dpkg\0A\00"
@str.13 = [47 x i8] c"\0Abash/preinst: expected at least one argument\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.13, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
br label %57
7: ; preds = %2
%8 = tail call i64 (...) @check_predepends()
%9 = load i64, i64* @EXIT_SUCCESS
%10 = icmp eq i64 %8, %9
br i1 %10, label %14, label %11
11: ; preds = %7
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.12, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
br label %57
14: ; preds = %7
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %54
19: ; preds = %14
%20 = icmp ult i32 %0, 3
br i1 %20, label %21, label %24
21: ; preds = %19
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
br label %57
24: ; preds = %19
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = tail call i64 @dpkg_compare_versions(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%28 = load i64, i64* @EXIT_SUCCESS
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %54
30: ; preds = %24
%31 = tail call i8* @check_diversion(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = load i32, i32* @EXIT_FAILURE
br label %57
35: ; preds = %30
%36 = tail call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = tail call i32 @dpkg_divert_add(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%40 = tail call i32 @unlink(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%41 = tail call i32 @symlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %42
42: ; preds = %38, %35
%43 = tail call i8* @check_diversion(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = load i32, i32* @EXIT_FAILURE
br label %57
47: ; preds = %42
%48 = tail call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %47
%51 = tail call i32 @dpkg_divert_add(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
%52 = tail call i32 @unlink(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
%53 = tail call i32 @symlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
br label %54
54: ; preds = %47, %50, %24, %14
%55 = load i64, i64* @EXIT_SUCCESS
%56 = trunc i64 %55 to i32
br label %57
57: ; preds = %33, %45, %54, %21, %11, %4
%58 = phi i32 [ %6, %4 ], [ %13, %11 ], [ %23, %21 ], [ %56, %54 ], [ %34, %33 ], [ %46, %45 ]
ret i32 %58
}