#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 /*<<< orphan*/ O_RDONLY;
int atoi(char *);
unsigned char calcCSum(unsigned char *);
int /*<<< orphan*/ dehexify(unsigned char *, char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
unsigned char getCSum(unsigned char *);
int getCode(unsigned char *);
int /*<<< orphan*/ hexify(unsigned char *, unsigned char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ setCSum(unsigned char *, unsigned char);
int /*<<< orphan*/ setCode(unsigned char *, int);
int /*<<< orphan*/ setCommand(unsigned char *, int);
int /*<<< orphan*/ *stderr;
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr,
            "usage, %s <command> [increment]\n\tcommand can be \"lock\", "
            "\"unlock\", \"trunk\" or \"panic\"\nincrement increments the "
            "rolling code by a certain amount. Defaults to 1\n",
            argv[0]);
    return -1;
  }
  int inc = 1;
  if (argc > 2) {
    inc = atoi(argv[2]);
  }
  int fd = open("latestcode.txt", O_RDONLY);
  if (fd == -1) {
    perror("Could not open latestcode.txt");
    return -1;
  }
  char hexString[21];
  if ((read(fd, hexString, 20)) < 20) {
    fprintf(stderr, "Couldn't read a full hex string from latestcode.txt\n");
    return -1;
  }
  hexString[20] = 0;
  int forceCommand;
  if (strcmp(argv[1], "lock") == 0)
    forceCommand = 0x1;
  else if (strcmp(argv[1], "unlock") == 0)
    forceCommand = 0x2;
  else if (strcmp(argv[1], "trunk") == 0)
    forceCommand = 0xb;
  else if (strcmp(argv[1], "panic") == 0)
    forceCommand = 0xa;
  else {
    fprintf(stderr,
            "Dunno what %s means, use \"lock\", \"unlock\" or \"trunk\"\n",
            argv[2]);
    return -1;
  }
  int n = 0;
  if (strlen(hexString) != 20) {
    fprintf(stderr, "hex string must be 20 digits (10 byte) long\n");
    return -1;
  }
  fprintf(stderr, "Current code: %s\n", hexString);
  unsigned char decoded[10];
  dehexify(decoded, hexString, 10);
  unsigned char mycsum = calcCSum(decoded);
  ;
  unsigned char csum = getCSum(decoded);
  int rollingCode = getCode(decoded);
  setCode(decoded, rollingCode + inc);
  setCommand(decoded, forceCommand);
  setCSum(decoded, calcCSum(decoded));
  unsigned char newHexString[21];
  hexify(newHexString, decoded, 10);
  fprintf(stderr, "New code    : %s\n", newHexString);
  FILE *f = fopen("latestcode.txt", "w");
  fprintf(f, "%s\n", newHexString);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    125b <main+0x4b>
mov    0x2da1(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdb8(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    150d <main+0x2fd>
movl   $0x1,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    127c <main+0x6c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1120 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d65(%rip),%rax
mov    (%rax),%esi
lea    0xe22(%rip),%rdi
call   10f0 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    12b6 <main+0xa6>
lea    0xdfa(%rip),%rdi
call   1110 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    150d <main+0x2fd>
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x14,%edx
call   1070 <read@plt>
cmp    $0x14,%eax
jge    12f4 <main+0xe4>
mov    0x2d01(%rip),%rax
mov    (%rax),%rdi
lea    0xddc(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    150d <main+0x2fd>
movb   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xded(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1322 <main+0x112>
movl   $0x1,-0x34(%rbp)
jmp    13db <main+0x1cb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdc1(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    134c <main+0x13c>
movl   $0x2,-0x34(%rbp)
jmp    13d6 <main+0x1c6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd9e(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1376 <main+0x166>
movl   $0xb,-0x34(%rbp)
jmp    13d1 <main+0x1c1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd7a(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    13a0 <main+0x190>
movl   $0xa,-0x34(%rbp)
jmp    13cc <main+0x1bc>
mov    0x2c31(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd4c(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    150d <main+0x2fd>
jmp    13d1 <main+0x1c1>
jmp    13d6 <main+0x1c6>
jmp    13db <main+0x1cb>
movl   $0x0,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x14,%eax
je     1418 <main+0x208>
mov    0x2bdd(%rip),%rax
mov    (%rax),%rdi
lea    0xd36(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    150d <main+0x2fd>
mov    0x2bb9(%rip),%rax
mov    (%rax),%rdi
lea    -0x30(%rbp),%rdx
lea    0xd3b(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
lea    -0x42(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   10b0 <dehexify@plt>
lea    -0x42(%rbp),%rdi
call   1130 <calcCSum@plt>
mov    %al,-0x43(%rbp)
lea    -0x42(%rbp),%rdi
call   1030 <getCSum@plt>
mov    %al,-0x44(%rbp)
lea    -0x42(%rbp),%rdi
call   10e0 <getCode@plt>
mov    %eax,-0x48(%rbp)
lea    -0x42(%rbp),%rdi
mov    -0x48(%rbp),%esi
add    -0x14(%rbp),%esi
call   10d0 <setCode@plt>
lea    -0x42(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1080 <setCommand@plt>
lea    -0x42(%rbp),%rax
mov    %rax,-0x70(%rbp)
lea    -0x42(%rbp),%rdi
call   1130 <calcCSum@plt>
mov    -0x70(%rbp),%rdi
movzbl %al,%esi
call   1040 <setCSum@plt>
lea    -0x60(%rbp),%rdi
lea    -0x42(%rbp),%rsi
mov    $0xa,%edx
call   10c0 <hexify@plt>
mov    0x2b1d(%rip),%rax
mov    (%rax),%rdi
lea    -0x60(%rbp),%rdx
lea    0xcb1(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
lea    0xbd7(%rip),%rdi
lea    0xcae(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xc92(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x68(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbp
cmp    $0x1,%edi
jg     1257 <main+0x37>
mov    0x2d9b(%rip),%rax
mov    (%rax),%rdi
mov    0x0(%rbp),%rdx
lea    0xdb5(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    145f <main+0x23f>
mov    $0x1,%r15d
cmp    $0x2,%edi
je     126e <main+0x4e>
mov    0x10(%rbp),%rdi
call   1120 <atoi@plt>
mov    %eax,%r15d
mov    0x2d73(%rip),%rax
mov    (%rax),%esi
lea    0xe30(%rip),%rdi
call   10f0 <open@plt>
cmp    $0xffffffff,%eax
je     1346 <main+0x126>
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x14,%edx
call   1070 <read@plt>
cmp    $0x13,%eax
jg     12bb <main+0x9b>
mov    0x2d31(%rip),%rax
mov    (%rax),%rcx
lea    0xe0c(%rip),%rdi
mov    $0x34,%esi
jmp    1455 <main+0x235>
movb   $0x0,0x14(%rsp)
mov    0x8(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     132e <main+0x10e>
mov    0x8(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1336 <main+0x116>
mov    0x8(%rbp),%rdi
lea    0xe04(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     133e <main+0x11e>
mov    0x8(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1357 <main+0x137>
mov    0x2cbd(%rip),%rax
mov    (%rax),%rdi
mov    0x10(%rbp),%rdx
lea    0xddc(%rip),%rsi
jmp    124b <main+0x2b>
mov    $0x1,%r14d
jmp    135d <main+0x13d>
mov    $0x2,%r14d
jmp    135d <main+0x13d>
mov    $0xb,%r14d
jmp    135d <main+0x13d>
lea    0xd52(%rip),%rdi
call   1110 <perror@plt>
jmp    145f <main+0x23f>
mov    $0xa,%r14d
mov    %rsp,%rdi
call   1060 <strlen@plt>
mov    0x2c6c(%rip),%r13
mov    0x0(%r13),%rcx
cmp    $0x14,%eax
jne    1449 <main+0x229>
lea    0xde8(%rip),%rsi
xor    %ebp,%ebp
mov    %rsp,%r12
mov    %rcx,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
lea    0x16(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0xa,%edx
call   10b0 <dehexify@plt>
mov    %rbx,%rdi
call   1140 <calcCSum@plt>
mov    %rbx,%rdi
call   1030 <getCSum@plt>
mov    %rbx,%rdi
call   10e0 <getCode@plt>
add    %eax,%r15d
mov    %rbx,%rdi
mov    %r15d,%esi
call   10d0 <setCode@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1080 <setCommand@plt>
mov    %rbx,%rdi
call   1140 <calcCSum@plt>
movzbl %al,%esi
mov    %rbx,%rdi
call   1040 <setCSum@plt>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0xa,%edx
call   10c0 <hexify@plt>
mov    0x0(%r13),%rdi
lea    0xd6f(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
lea    0xc92(%rip),%rdi
lea    0xd69(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,%rbx
lea    0xd56(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    1464 <main+0x244>
lea    0xceb(%rip),%rdi
mov    $0x2c,%esi
mov    $0x1,%edx
call   1130 <fwrite@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32* null
@.str = [159 x i8] c"usage, %s <command> [increment]\0A\09command can be \22lock\22, \22unlock\22, \22trunk\22 or \22panic\22\0Aincrement increments the rolling code by a certain amount. Defaults to 1\0A\00"
@.str.1 = [15 x i8] c"latestcode.txt\00"
@O_RDONLY = global i32 0
@.str.2 = [30 x i8] c"Could not open latestcode.txt\00"
@.str.3 = [53 x i8] c"Couldn't read a full hex string from latestcode.txt\0A\00"
@.str.4 = [5 x i8] c"lock\00"
@.str.5 = [7 x i8] c"unlock\00"
@.str.6 = [6 x i8] c"trunk\00"
@.str.7 = [6 x i8] c"panic\00"
@.str.8 = [54 x i8] c"Dunno what %s means, use \22lock\22, \22unlock\22 or \22trunk\22\0A\00"
@.str.9 = [45 x i8] c"hex string must be 20 digits (10 byte) long\0A\00"
@.str.10 = [18 x i8] c"Current code: %s\0A\00"
@.str.11 = [18 x i8] c"New code : %s\0A\00"
@.str.12 = [2 x i8] c"w\00"
@.str.13 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [21 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca [10 x i8]
%12 = alloca i8
%13 = alloca i8
%14 = alloca i32
%15 = alloca [21 x i8]
%16 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 2
br i1 %18, label %19, label %25
19: ; preds = %2
%20 = load i32*, i32** @stderr
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str, i64 0, i64 0), i8* %23)
store i32 -1, i32* %3
br label %130
25: ; preds = %2
store i32 1, i32* %6
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 2
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %6
br label %33
33: ; preds = %28, %25
%34 = load i32, i32* @O_RDONLY
%35 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %34)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %130
40: ; preds = %33
%41 = load i32, i32* %7
%42 = getelementptr inbounds [21 x i8], [21 x i8]* %8, i64 0, i64 0
%43 = call i32 @read(i32 %41, i8* %42, i32 20)
%44 = icmp slt i32 %43, 20
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i32*, i32** @stderr
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %130
48: ; preds = %40
%49 = getelementptr inbounds [21 x i8], [21 x i8]* %8, i64 0, i64 20
store i8 0, i8* %49
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 1
%52 = load i8*, i8** %51
%53 = call i64 @strcmp(i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %48
store i32 1, i32* %9
br label %86
56: ; preds = %48
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %56
store i32 2, i32* %9
br label %85
63: ; preds = %56
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i8*, i8** %65
%67 = call i64 @strcmp(i8* %66, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %63
store i32 11, i32* %9
br label %84
70: ; preds = %63
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 1
%73 = load i8*, i8** %72
%74 = call i64 @strcmp(i8* %73, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%75 = icmp eq i64 %74, 0
br i1 %75, label %76, label %77
76: ; preds = %70
store i32 10, i32* %9
br label %83
77: ; preds = %70
%78 = load i32*, i32** @stderr
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 2
%81 = load i8*, i8** %80
%82 = call i32 (i32*, i8*, ...) @fprintf(i32* %78, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0), i8* %81)
store i32 -1, i32* %3
br label %130
83: ; preds = %76
br label %84
84: ; preds = %83, %69
br label %85
85: ; preds = %84, %62
br label %86
86: ; preds = %85, %55
store i32 0, i32* %10
%87 = getelementptr inbounds [21 x i8], [21 x i8]* %8, i64 0, i64 0
%88 = call i32 @strlen(i8* %87)
%89 = icmp ne i32 %88, 20
br i1 %89, label %90, label %93
90: ; preds = %86
%91 = load i32*, i32** @stderr
%92 = call i32 (i32*, i8*, ...) @fprintf(i32* %91, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.9, i64 0, i64 0))
store i32 -1, i32* %3
br label %130
93: ; preds = %86
%94 = load i32*, i32** @stderr
%95 = getelementptr inbounds [21 x i8], [21 x i8]* %8, i64 0, i64 0
%96 = call i32 (i32*, i8*, ...) @fprintf(i32* %94, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0), i8* %95)
%97 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%98 = getelementptr inbounds [21 x i8], [21 x i8]* %8, i64 0, i64 0
%99 = call i32 @dehexify(i8* %97, i8* %98, i32 10)
%100 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%101 = call zeroext i8 @calcCSum(i8* %100)
store i8 %101, i8* %12
%102 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%103 = call zeroext i8 @getCSum(i8* %102)
store i8 %103, i8* %13
%104 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%105 = call i32 @getCode(i8* %104)
store i32 %105, i32* %14
%106 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%107 = load i32, i32* %14
%108 = load i32, i32* %6
%109 = add nsw i32 %107, %108
%110 = call i32 @setCode(i8* %106, i32 %109)
%111 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%112 = load i32, i32* %9
%113 = call i32 @setCommand(i8* %111, i32 %112)
%114 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%115 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%116 = call zeroext i8 @calcCSum(i8* %115)
%117 = call i32 @setCSum(i8* %114, i8 zeroext %116)
%118 = getelementptr inbounds [21 x i8], [21 x i8]* %15, i64 0, i64 0
%119 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%120 = call i32 @hexify(i8* %118, i8* %119, i32 10)
%121 = load i32*, i32** @stderr
%122 = getelementptr inbounds [21 x i8], [21 x i8]* %15, i64 0, i64 0
%123 = call i32 (i32*, i8*, ...) @fprintf(i32* %121, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i8* %122)
%124 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
store i32* %124, i32** %16
%125 = load i32*, i32** %16
%126 = getelementptr inbounds [21 x i8], [21 x i8]* %15, i64 0, i64 0
%127 = call i32 (i32*, i8*, ...) @fprintf(i32* %125, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), i8* %126)
%128 = load i32*, i32** %16
%129 = call i32 @fclose(i32* %128)
store i32 0, i32* %3
br label %130
130: ; preds = %93, %90, %77, %45, %38, %19
%131 = load i32, i32* %3
ret i32 %131
}

LLVM IR (-O2):
@stderr = global i32* null
@.str = [159 x i8] c"usage, %s <command> [increment]\0A\09command can be \22lock\22, \22unlock\22, \22trunk\22 or \22panic\22\0Aincrement increments the rolling code by a certain amount. Defaults to 1\0A\00"
@.str.1 = [15 x i8] c"latestcode.txt\00"
@O_RDONLY = global i32 0
@.str.2 = [30 x i8] c"Could not open latestcode.txt\00"
@.str.3 = [53 x i8] c"Couldn't read a full hex string from latestcode.txt\0A\00"
@.str.4 = [5 x i8] c"lock\00"
@.str.5 = [7 x i8] c"unlock\00"
@.str.6 = [6 x i8] c"trunk\00"
@.str.7 = [6 x i8] c"panic\00"
@.str.8 = [54 x i8] c"Dunno what %s means, use \22lock\22, \22unlock\22 or \22trunk\22\0A\00"
@.str.9 = [45 x i8] c"hex string must be 20 digits (10 byte) long\0A\00"
@.str.10 = [18 x i8] c"Current code: %s\0A\00"
@.str.11 = [18 x i8] c"New code : %s\0A\00"
@.str.12 = [2 x i8] c"w\00"
@.str.13 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [21 x i8]
%4 = alloca [10 x i8]
%5 = alloca [21 x i8]
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32*, i32** @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %82
11: ; preds = %2
%12 = icmp eq i32 %0, 2
br i1 %12, label %17, label %13
13: ; preds = %11
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
br label %17
17: ; preds = %13, %11
%18 = phi i32 [ %16, %13 ], [ 1, %11 ]
%19 = load i32, i32* @O_RDONLY
%20 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %82
24: ; preds = %17
%25 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 0
%26 = call i32 @read(i32 %20, i8* %25, i32 20)
%27 = icmp slt i32 %26, 20
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32*, i32** @stderr
%30 = tail call i64 @fwrite(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i64 52, i64 1, i32* %29)
br label %80
31: ; preds = %24
%32 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 20
store i8 0, i8* %32
%33 = getelementptr inbounds i8*, i8** %1, i64 1
%34 = load i8*, i8** %33
%35 = tail call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %54, label %37
37: ; preds = %31
%38 = load i8*, i8** %33
%39 = tail call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %54, label %41
41: ; preds = %37
%42 = load i8*, i8** %33
%43 = tail call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %54, label %45
45: ; preds = %41
%46 = load i8*, i8** %33
%47 = tail call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %54, label %49
49: ; preds = %45
%50 = load i32*, i32** @stderr
%51 = getelementptr inbounds i8*, i8** %1, i64 2
%52 = load i8*, i8** %51
%53 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0), i8* %52)
br label %80
54: ; preds = %45, %41, %37, %31
%55 = phi i32 [ 1, %31 ], [ 2, %37 ], [ 11, %41 ], [ 10, %45 ]
%56 = call i32 @strlen(i8* %25)
%57 = icmp eq i32 %56, 20
%58 = load i32*, i32** @stderr
br i1 %57, label %61, label %59
59: ; preds = %54
%60 = call i64 @fwrite(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.9, i64 0, i64 0), i64 44, i64 1, i32* %58)
br label %80
61: ; preds = %54
%62 = call i32 (i32*, i8*, ...) @fprintf(i32* %58, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0), i8* %25)
%63 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%64 = call i32 @dehexify(i8* %63, i8* %25, i32 10)
%65 = call zeroext i8 @calcCSum(i8* %63)
%66 = call zeroext i8 @getCSum(i8* %63)
%67 = call i32 @getCode(i8* %63)
%68 = add nsw i32 %67, %18
%69 = call i32 @setCode(i8* %63, i32 %68)
%70 = call i32 @setCommand(i8* %63, i32 %55)
%71 = call zeroext i8 @calcCSum(i8* %63)
%72 = call i32 @setCSum(i8* %63, i8 zeroext %71)
%73 = getelementptr inbounds [21 x i8], [21 x i8]* %5, i64 0, i64 0
%74 = call i32 @hexify(i8* %73, i8* %63, i32 10)
%75 = load i32*, i32** @stderr
%76 = call i32 (i32*, i8*, ...) @fprintf(i32* %75, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i8* %73)
%77 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%78 = call i32 (i32*, i8*, ...) @fprintf(i32* %77, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), i8* %73)
%79 = call i32 @fclose(i32* %77)
br label %80
80: ; preds = %49, %61, %59, %28
%81 = phi i32 [ -1, %28 ], [ -1, %49 ], [ -1, %59 ], [ 0, %61 ]
br label %82
82: ; preds = %22, %80, %7
%83 = phi i32 [ -1, %7 ], [ -1, %22 ], [ %81, %80 ]
ret i32 %83
}