#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 /*<<< orphan*/ data_to_file_raw(unsigned char *, int, char *);
unsigned char *from_command_line_hex(char *, int *);
unsigned char *generate_key(int);
scalar_t__ strcmp(char *, char *);
int strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  int key_length = 0;
  unsigned char *key = 0;
  if (strcmp(argv[1], "random") == 0) {
    key_length = strtol(argv[2], NULL, 10);
    key = generate_key(key_length);
  }
  if (strcmp(argv[1], "preset") == 0) {
    key = from_command_line_hex(argv[2], &key_length);
  }
  data_to_file_raw(key, key_length, argv[3]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11b8 <main+0x68>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <generate_key@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe40(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11eb <main+0x9b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <from_command_line_hex@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
call   1030 <data_to_file_raw@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movl   $0x0,0xc(%rsp)
mov    0x8(%rsi),%rdi
lea    0xe91(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1181 <main+0x31>
xor    %r14d,%r14d
xor    %r15d,%r15d
jmp    11a2 <main+0x52>
mov    0x10(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%r14d
mov    %eax,0xc(%rsp)
mov    %eax,%edi
call   1060 <generate_key@plt>
mov    %rax,%r15
mov    0x8(%rbx),%rdi
lea    0xe5a(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11cd <main+0x7d>
mov    0x10(%rbx),%rdi
lea    0xc(%rsp),%rsi
call   1070 <from_command_line_hex@plt>
mov    %rax,%r15
mov    0xc(%rsp),%r14d
mov    0x18(%rbx),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
call   1030 <data_to_file_raw@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"random\00"
@.str.1 = [7 x i8] c"preset\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i8* null, i8** %7
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
%17 = call i32 @strtol(i8* %16, i32* null, i32 10)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = call i8* @generate_key(i32 %18)
store i8* %19, i8** %7
br label %20
20: ; preds = %13, %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %20
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i8* @from_command_line_hex(i8* %29, i32* %6)
store i8* %30, i8** %7
br label %31
31: ; preds = %26, %20
%32 = load i8*, i8** %7
%33 = load i32, i32* %6
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 3
%36 = load i8*, i8** %35
%37 = call i32 @data_to_file_raw(i8* %32, i32 %33, i8* %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"random\00"
@.str.1 = [7 x i8] c"preset\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @strtol(i8* nocapture %11, i32* null, i32 10)
store i32 %12, i32* %3
%13 = tail call i8* @generate_key(i32 %12)
br label %14
14: ; preds = %9, %2
%15 = phi i32 [ %12, %9 ], [ 0, %2 ]
%16 = phi i8* [ %13, %9 ], [ null, %2 ]
%17 = load i8*, i8** %5
%18 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = call i8* @from_command_line_hex(i8* %22, i32* %3)
%24 = load i32, i32* %3
br label %25
25: ; preds = %20, %14
%26 = phi i32 [ %24, %20 ], [ %15, %14 ]
%27 = phi i8* [ %23, %20 ], [ %16, %14 ]
%28 = getelementptr inbounds i8*, i8** %1, i64 3
%29 = load i8*, i8** %28
%30 = call i32 @data_to_file_raw(i8* %27, i32 %26, i8* %29)
ret i32 0
}