#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*/ mpz_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EOF;
int /*<<< orphan*/ SEEK_END;
char *ask_for_parameter(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ mpz_set_str(int /*<<< orphan*/, char *, int);
char *read_optional_parameter(int, char **, char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
char *sha1(char *);
int /*<<< orphan*/ stderr;
void get_message(mpz_t m, int argc, char *argv[]) {
  char *str_input = read_optional_parameter(argc, argv, "-I");
  if (str_input == NULL)
    str_input = read_optional_parameter(argc, argv, "--input");
  char *str_data;
  if (str_input != NULL) {
    FILE *f_input = fopen(str_input, "r");
    if (f_input == NULL) {
      fprintf(stderr, "%s: Can't open input file: %s\n", argv[0], str_input);
      exit(2);
    }
    free(str_input);
    fseek(f_input, 0, SEEK_END);
    int len = ftell(f_input);
    rewind(f_input);
    str_data = (char *)malloc(len + 1);
    str_data[len] = '\0';
    int read = fread(str_data, 1, len, f_input);
    if (read != len) {
      fprintf(
          stderr,
          "%s: Failed to read input file corretly %i of %i bytes were read.\n",
          argv[0], read, len);
      exit(2);
    }
    fclose(f_input);
  } else {
    str_data = ask_for_parameter("Message:", EOF);
  }
  char *hash = sha1(str_data);
  free(str_data);
  mpz_set_str(m, hash, 16);
  free(hash);
}


x86 assembly (clang, -O0):
<get_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe00(%rip),%rdx
call   10f0 <read_optional_parameter@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    122b <get_message+0x4b>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xde1(%rip),%rdx
call   10f0 <read_optional_parameter@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     132f <get_message+0x14f>
mov    -0x18(%rbp),%rdi
lea    0xdca(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1281 <get_message+0xa1>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rcx
lea    0xd9d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   1100 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
mov    0x2d53(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1090 <ftell@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <rewind@plt>
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
je     1321 <get_message+0x141>
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x30(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
lea    0xd1c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   1100 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
jmp    1348 <get_message+0x168>
mov    0x2caa(%rip),%rax
mov    (%rax),%esi
lea    0xd2f(%rip),%rdi
call   10a0 <ask_for_parameter@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <sha1@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    $0x10,%edx
call   10d0 <mpz_set_str@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_message>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %esi,%ebp
mov    %edi,%r14d
lea    0xe09(%rip),%rdx
mov    %esi,%edi
mov    %r15,%rsi
call   10f0 <read_optional_parameter@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1226 <get_message+0x46>
lea    0xdf3(%rip),%rdx
mov    %ebp,%edi
mov    %r15,%rsi
call   10f0 <read_optional_parameter@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12d6 <get_message+0xf6>
lea    0xdde(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     12f0 <get_message+0x110>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %rbp,%rdi
call   1090 <ftell@plt>
mov    %eax,%r12d
mov    %rbp,%rdi
call   1070 <rewind@plt>
lea    0x1(%r12),%edi
call   10b0 <malloc@plt>
mov    %rax,%rbx
movslq %r12d,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rbp,%rcx
call   1050 <fread@plt>
cmp    %r12d,%eax
jne    1317 <get_message+0x137>
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
call   1040 <sha1@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x10,%edx
call   10d0 <mpz_set_str@plt>
mov    %rbp,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
mov    0x2d03(%rip),%rax
mov    (%rax),%esi
lea    0xd88(%rip),%rdi
call   10a0 <ask_for_parameter@plt>
mov    %rax,%rbx
jmp    12a3 <get_message+0xc3>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xd0a(%rip),%rsi
mov    %rbx,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   1100 <exit@plt>
mov    0x2cb2(%rip),%rcx
mov    (%rcx),%edi
mov    (%r15),%rdx
lea    0xd02(%rip),%rsi
mov    %eax,%ecx
mov    %r12d,%r8d
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"-I\00"
@.str.1 = [8 x i8] c"--input\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [31 x i8] c"%s: Can't open input file: %s\0A\00"
@SEEK_END = global i32 0
@.str.4 = [66 x i8] c"%s: Failed to read input file corretly %i of %i bytes were read.\0A\00"
@.str.5 = [9 x i8] c"Message:\00"
@EOF = global i32 0
define void @get_message(i32 %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
%13 = load i32, i32* %5
%14 = load i8**, i8*** %6
%15 = call i8* @read_optional_parameter(i32 %13, i8** %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %3
%19 = load i32, i32* %5
%20 = load i8**, i8*** %6
%21 = call i8* @read_optional_parameter(i32 %19, i8** %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i8* %21, i8** %7
br label %22
22: ; preds = %18, %3
%23 = load i8*, i8** %7
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %75
25: ; preds = %22
%26 = load i8*, i8** %7
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %27, i32** %9
%28 = load i32*, i32** %9
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %38
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = load i8**, i8*** %6
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = load i8*, i8** %7
%36 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %34, i8* %35)
%37 = call i32 @exit(i32 2)
unreachable
38: ; preds = %25
%39 = load i8*, i8** %7
%40 = call i32 @free(i8* %39)
%41 = load i32*, i32** %9
%42 = load i32, i32* @SEEK_END
%43 = call i32 @fseek(i32* %41, i32 0, i32 %42)
%44 = load i32*, i32** %9
%45 = call i32 @ftell(i32* %44)
store i32 %45, i32* %10
%46 = load i32*, i32** %9
%47 = call i32 @rewind(i32* %46)
%48 = load i32, i32* %10
%49 = add nsw i32 %48, 1
%50 = call i64 @malloc(i32 %49)
%51 = inttoptr i64 %50 to i8*
store i8* %51, i8** %8
%52 = load i8*, i8** %8
%53 = load i32, i32* %10
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
store i8 0, i8* %55
%56 = load i8*, i8** %8
%57 = load i32, i32* %10
%58 = load i32*, i32** %9
%59 = call i32 @fread(i8* %56, i32 1, i32 %57, i32* %58)
store i32 %59, i32* %11
%60 = load i32, i32* %11
%61 = load i32, i32* %10
%62 = icmp ne i32 %60, %61
br i1 %62, label %63, label %72
63: ; preds = %38
%64 = load i32, i32* @stderr
%65 = load i8**, i8*** %6
%66 = getelementptr inbounds i8*, i8** %65, i64 0
%67 = load i8*, i8** %66
%68 = load i32, i32* %11
%69 = load i32, i32* %10
%70 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0), i8* %67, i32 %68, i32 %69)
%71 = call i32 @exit(i32 2)
unreachable
72: ; preds = %38
%73 = load i32*, i32** %9
%74 = call i32 @fclose(i32* %73)
br label %78
75: ; preds = %22
%76 = load i32, i32* @EOF
%77 = call i8* @ask_for_parameter(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %76)
store i8* %77, i8** %8
br label %78
78: ; preds = %75, %72
%79 = load i8*, i8** %8
%80 = call i8* @sha1(i8* %79)
store i8* %80, i8** %12
%81 = load i8*, i8** %8
%82 = call i32 @free(i8* %81)
%83 = load i32, i32* %4
%84 = load i8*, i8** %12
%85 = call i32 @mpz_set_str(i32 %83, i8* %84, i32 16)
%86 = load i8*, i8** %12
%87 = call i32 @free(i8* %86)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"-I\00"
@.str.1 = [8 x i8] c"--input\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [31 x i8] c"%s: Can't open input file: %s\0A\00"
@SEEK_END = global i32 0
@.str.4 = [66 x i8] c"%s: Failed to read input file corretly %i of %i bytes were read.\0A\00"
@.str.5 = [9 x i8] c"Message:\00"
@EOF = global i32 0
define void @get_message(i32 %0, i32 %1, i8** %2) {
%4 = tail call i8* @read_optional_parameter(i32 %1, i8** %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i8* @read_optional_parameter(i32 %1, i8** %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %38, label %9
9: ; preds = %3, %6
%10 = phi i8* [ %7, %6 ], [ %4, %3 ]
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %2
%16 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %15, i8* %10)
%17 = tail call i32 @exit(i32 2)
unreachable
18: ; preds = %9
%19 = tail call i32 @free(i8* %10)
%20 = load i32, i32* @SEEK_END
%21 = tail call i32 @fseek(i32* %11, i32 0, i32 %20)
%22 = tail call i32 @ftell(i32* %11)
%23 = tail call i32 @rewind(i32* %11)
%24 = add nsw i32 %22, 1
%25 = tail call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i8*
%27 = sext i32 %22 to i64
%28 = getelementptr inbounds i8, i8* %26, i64 %27
store i8 0, i8* %28
%29 = tail call i32 @fread(i8* %26, i32 1, i32 %22, i32* %11)
%30 = icmp eq i32 %29, %22
br i1 %30, label %36, label %31
31: ; preds = %18
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %2
%34 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0), i8* %33, i32 %29, i32 %22)
%35 = tail call i32 @exit(i32 2)
unreachable
36: ; preds = %18
%37 = tail call i32 @fclose(i32* %11)
br label %41
38: ; preds = %6
%39 = load i32, i32* @EOF
%40 = tail call i8* @ask_for_parameter(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %38, %36
%42 = phi i8* [ %26, %36 ], [ %40, %38 ]
%43 = tail call i8* @sha1(i8* %42)
%44 = tail call i32 @free(i8* %42)
%45 = tail call i32 @mpz_set_str(i32 %0, i8* %43, i32 16)
%46 = tail call i32 @free(i8* %43)
ret void
}