#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 */
long atol(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(long *);
long getmax(long *, long);
scalar_t__ malloc(long);
int /*<<< orphan*/ printf(char *, ...);
long rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  long size = 0;
  long i;
  long *numbers;
  if (argc != 2) {
    printf("usage: maxseq num\n");
    printf("num = size of the array\n");
    exit(1);
  }
  size = atol(argv[1]);
  numbers = (long *)malloc(size * sizeof(long));
  if (!numbers) {
    printf("Unable to allocate mem for an array of size %ld\n", size);
    exit(1);
  }
  srand(time(NULL));
  for (i = 0; i < size; i++)
    numbers[i] = rand() % size;
  printf(" The maximum number in the array is: %ld\n", getmax(numbers, size));
  free(numbers);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11de <main+0x4e>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
shl    $0x3,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1227 <main+0x97>
mov    -0x18(%rbp),%rsi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    1277 <main+0xe7>
mov    $0x0,%al
call   10b0 <rand@plt>
cqto
idivq  -0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    123f <main+0xaf>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <getmax@plt>
mov    %rax,%rsi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11e3 <main+0x43>
mov    0x8(%rsi),%rdi
call   10a0 <atol@plt>
mov    %rax,%r15
lea    0x0(,%rax,8),%rdi
call   1090 <malloc@plt>
test   %rax,%rax
jne    1205 <main+0x65>
lea    0xe31(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xe71(%rip),%rdi
call   1040 <puts@plt>
lea    0xe77(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %rax,%r14
xor    %ebx,%ebx
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
test   %r15,%r15
jg     1262 <main+0xc2>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <getmax@plt>
lea    0xe02(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
nopl   0x0(%rax,%rax,1)
cqto
idiv   %r15
mov    %rdx,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
je     121d <main+0x7d>
xor    %eax,%eax
call   10c0 <rand@plt>
mov    %rax,%rcx
or     %r15,%rcx
shr    $0x20,%rcx
jne    1250 <main+0xb0>
xor    %edx,%edx
div    %r15d
jmp    1255 <main+0xb5>

LLVM IR (-O0):
@.str = [19 x i8] c"usage: maxseq num\0A\00"
@.str.1 = [25 x i8] c"num = size of the array\0A\00"
@.str.2 = [49 x i8] c"Unable to allocate mem for an array of size %ld\0A\00"
@.str.3 = [42 x i8] c" The maximum number in the array is: %ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @atol(i8* %18)
store i64 %19, i64* %6
%20 = load i64, i64* %6
%21 = mul i64 %20, 8
%22 = call i64 @malloc(i64 %21)
%23 = inttoptr i64 %22 to i64*
store i64* %23, i64** %8
%24 = load i64*, i64** %8
%25 = icmp ne i64* %24, null
br i1 %25, label %30, label %26
26: ; preds = %15
%27 = load i64, i64* %6
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i64 %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %15
%31 = call i32 @time(i32* null)
%32 = call i32 @srand(i32 %31)
store i64 0, i64* %7
br label %33
33: ; preds = %44, %30
%34 = load i64, i64* %7
%35 = load i64, i64* %6
%36 = icmp slt i64 %34, %35
br i1 %36, label %37, label %47
37: ; preds = %33
%38 = call i64 (...) @rand()
%39 = load i64, i64* %6
%40 = srem i64 %38, %39
%41 = load i64*, i64** %8
%42 = load i64, i64* %7
%43 = getelementptr inbounds i64, i64* %41, i64 %42
store i64 %40, i64* %43
br label %44
44: ; preds = %37
%45 = load i64, i64* %7
%46 = add nsw i64 %45, 1
store i64 %46, i64* %7
br label %33
47: ; preds = %33
%48 = load i64*, i64** %8
%49 = load i64, i64* %6
%50 = call i64 @getmax(i64* %48, i64 %49)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i64 %50)
%52 = load i64*, i64** %8
%53 = call i32 @free(i64* %52)
%54 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.2 = [49 x i8] c"Unable to allocate mem for an array of size %ld\0A\00"
@.str.3 = [42 x i8] c" The maximum number in the array is: %ld\0A\00"
@str = [18 x i8] c"usage: maxseq num\00"
@str.4 = [24 x i8] c"num = size of the array\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.4, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @atol(i8* %10)
%12 = shl i64 %11, 3
%13 = tail call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i64*
%15 = icmp eq i64 %13, 0
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i64 %11)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %8
%20 = tail call i32 @time(i32* null)
%21 = tail call i32 @srand(i32 %20)
%22 = icmp sgt i64 %11, 0
br i1 %22, label %23, label %30
23: ; preds = %19, %23
%24 = phi i64 [ %28, %23 ], [ 0, %19 ]
%25 = tail call i64 (...) @rand()
%26 = srem i64 %25, %11
%27 = getelementptr inbounds i64, i64* %14, i64 %24
store i64 %26, i64* %27
%28 = add nuw nsw i64 %24, 1
%29 = icmp eq i64 %28, %11
br i1 %29, label %30, label %23
30: ; preds = %23, %19
%31 = tail call i64 @getmax(i64* %14, i64 %11)
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i64 %31)
%33 = tail call i32 @free(i64* %14)
%34 = tail call i32 @exit(i32 0)
unreachable
}