#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 atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stk_dump(int *);
scalar_t__ stk_init(int *);
int /*<<< orphan*/ stk_roll(int *, int, int, int);
void main(int argc, char **argv) {
  int stack[16], oldjob, newjob, base;
  oldjob = (argc > 1) ? atoi(argv[1]) : 5;
  newjob = (argc > 2) ? atoi(argv[2]) : 0;
  base = (argc > 3) ? atoi(argv[3]) : 0;
  if (stk_init(stack))
    stk_dump(stack);
  if (oldjob && newjob) {
    fprintf(stderr, "\n\nRolling stack from %d to %d:\n", oldjob, newjob);
    stk_roll(stack, oldjob, newjob, base);
    stk_dump(stack);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x4(%rbp)
jle    117e <main+0x2e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x60(%rbp)
jmp    118b <main+0x3b>
mov    $0x5,%eax
mov    %eax,-0x60(%rbp)
jmp    118b <main+0x3b>
mov    -0x60(%rbp),%eax
mov    %eax,-0x54(%rbp)
cmpl   $0x2,-0x4(%rbp)
jle    11b0 <main+0x60>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x64(%rbp)
jmp    11ba <main+0x6a>
xor    %eax,%eax
mov    %eax,-0x64(%rbp)
jmp    11ba <main+0x6a>
mov    -0x64(%rbp),%eax
mov    %eax,-0x58(%rbp)
cmpl   $0x3,-0x4(%rbp)
jle    11df <main+0x8f>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x68(%rbp)
jmp    11e9 <main+0x99>
xor    %eax,%eax
mov    %eax,-0x68(%rbp)
jmp    11e9 <main+0x99>
mov    -0x68(%rbp),%eax
mov    %eax,-0x5c(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <stk_init@plt>
cmp    $0x0,%rax
je     120b <main+0xbb>
lea    -0x50(%rbp),%rdi
call   1050 <stk_dump@plt>
cmpl   $0x0,-0x54(%rbp)
je     1255 <main+0x105>
cmpl   $0x0,-0x58(%rbp)
je     1255 <main+0x105>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    -0x54(%rbp),%edx
mov    -0x58(%rbp),%ecx
lea    0xdcb(%rip),%rsi
call   1030 <fprintf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    -0x58(%rbp),%edx
mov    -0x5c(%rbp),%ecx
call   1070 <stk_roll@plt>
lea    -0x50(%rbp),%rdi
call   1050 <stk_dump@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    $0x5,%r12d
xor    %r14d,%r14d
cmp    $0x2,%edi
jl     1180 <main+0x30>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%r12d
cmp    $0x2,%ebp
jne    11e6 <main+0x96>
xor    %r15d,%r15d
mov    %rsp,%rdi
call   1040 <stk_init@plt>
test   %rax,%rax
je     1198 <main+0x48>
mov    %rsp,%rdi
call   1050 <stk_dump@plt>
test   %r12d,%r12d
je     11d9 <main+0x89>
test   %r15d,%r15d
je     11d9 <main+0x89>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
mov    %r12d,%edx
mov    %r15d,%ecx
call   1030 <fprintf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1070 <stk_roll@plt>
mov    %rbx,%rdi
call   1050 <stk_dump@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%rbx),%rdi
call   1060 <atoi@plt>
mov    %eax,%r15d
cmp    $0x4,%ebp
jb     1183 <main+0x33>
mov    0x18(%rbx),%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
jmp    1183 <main+0x33>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"\0A\0ARolling stack from %d to %d:\0A\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [16 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %4
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
br label %17
16: ; preds = %2
br label %17
17: ; preds = %16, %11
%18 = phi i32 [ %15, %11 ], [ 5, %16 ]
store i32 %18, i32* %6
%19 = load i32, i32* %3
%20 = icmp sgt i32 %19, 2
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i8**, i8*** %4
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
br label %27
26: ; preds = %17
br label %27
27: ; preds = %26, %21
%28 = phi i32 [ %25, %21 ], [ 0, %26 ]
store i32 %28, i32* %7
%29 = load i32, i32* %3
%30 = icmp sgt i32 %29, 3
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load i8**, i8*** %4
%33 = getelementptr inbounds i8*, i8** %32, i64 3
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
br label %37
36: ; preds = %27
br label %37
37: ; preds = %36, %31
%38 = phi i32 [ %35, %31 ], [ 0, %36 ]
store i32 %38, i32* %8
%39 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%40 = call i64 @stk_init(i32* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%44 = call i32 @stk_dump(i32* %43)
br label %45
45: ; preds = %42, %37
%46 = load i32, i32* %6
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %63
48: ; preds = %45
%49 = load i32, i32* %7
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %63
51: ; preds = %48
%52 = load i32, i32* @stderr
%53 = load i32, i32* %6
%54 = load i32, i32* %7
%55 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %53, i32 %54)
%56 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%57 = load i32, i32* %6
%58 = load i32, i32* %7
%59 = load i32, i32* %8
%60 = call i32 @stk_roll(i32* %56, i32 %57, i32 %58, i32 %59)
%61 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%62 = call i32 @stk_dump(i32* %61)
br label %63
63: ; preds = %51, %48, %45
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"\0A\0ARolling stack from %d to %d:\0A\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca [16 x i32]
%4 = bitcast [16 x i32]* %3 to i8*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %20
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = icmp eq i32 %0, 2
br i1 %10, label %20, label %11
11: ; preds = %6
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = icmp ugt i32 %0, 3
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
br label %20
20: ; preds = %2, %6, %11, %16
%21 = phi i32 [ %14, %16 ], [ %14, %11 ], [ 0, %6 ], [ 0, %2 ]
%22 = phi i32 [ %9, %16 ], [ %9, %11 ], [ %9, %6 ], [ 5, %2 ]
%23 = phi i32 [ %19, %16 ], [ 0, %11 ], [ 0, %6 ], [ 0, %2 ]
%24 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 0
%25 = call i64 @stk_init(i32* %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %20
%28 = call i32 @stk_dump(i32* %24)
br label %29
29: ; preds = %27, %20
%30 = icmp ne i32 %22, 0
%31 = icmp ne i32 %21, 0
%32 = select i1 %30, i1 %31, i1 false
br i1 %32, label %33, label %38
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %21)
%36 = call i32 @stk_roll(i32* %24, i32 %22, i32 %21, i32 %23)
%37 = call i32 @stk_dump(i32* %24)
br label %38
38: ; preds = %33, %29
ret void
}