#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 EXIT_FAILURE;
scalar_t__ malloc(long);
void *sbrk(long);
int /*<<< orphan*/ strcmp(char const *, char *);
long strtol(char const *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, const char **argv) {
  if (argc == 2) {
    long func_arg = strtol(argv[1], NULL, 0);
    if (!strcmp(argv[0], "sbrk")) {
      if (sbrk(func_arg) == (void *)-1)
        return -1;
      return (int)sbrk(0);
    }
    if (!strcmp(argv[0], "malloc"))
      return (int)malloc(func_arg);
  }
  return EXIT_FAILURE;
}


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)
cmpl   $0x2,-0x8(%rbp)
jne    11fb <main+0xbb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe7b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11c9 <main+0x89>
mov    -0x18(%rbp),%rdi
call   1030 <sbrk@plt>
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    11b8 <main+0x78>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <main+0xc7>
xor    %eax,%eax
mov    %eax,%edi
call   1030 <sbrk@plt>
mov    %eax,-0x4(%rbp)
jmp    1207 <main+0xc7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe2e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11f6 <main+0xb6>
mov    -0x18(%rbp),%rdi
call   1060 <malloc@plt>
mov    %eax,-0x4(%rbp)
jmp    1207 <main+0xc7>
jmp    11fb <main+0xbb>
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1185 <main+0x45>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,%r14
mov    (%rbx),%rbx
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1196 <main+0x56>
lea    0xe8c(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11ad <main+0x6d>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
call   1030 <sbrk@plt>
cmp    $0xffffffffffffffff,%rax
je     11b7 <main+0x77>
xor    %edi,%edi
call   1030 <sbrk@plt>
jmp    118e <main+0x4e>
mov    %r14,%rdi
call   1060 <malloc@plt>
jmp    118e <main+0x4e>
mov    $0xffffffff,%eax
jmp    118e <main+0x4e>

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

LLVM IR (-O2):
@.str = [5 x i8] c"sbrk\00"
@.str.1 = [7 x i8] c"malloc\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %24
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strtol(i8* nocapture %6, i32* null, i32 0)
%8 = load i8*, i8** %1
%9 = tail call i32 @strcmp(i8* dereferenceable(1) %8, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %4
%12 = tail call i8* @sbrk(i64 %7)
%13 = icmp eq i8* %12, inttoptr (i64 -1 to i8*)
br i1 %13, label %26, label %14
14: ; preds = %11
%15 = tail call i8* @sbrk(i64 0)
%16 = ptrtoint i8* %15 to i64
%17 = trunc i64 %16 to i32
br label %26
18: ; preds = %4
%19 = tail call i32 @strcmp(i8* dereferenceable(1) %8, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = tail call i64 @malloc(i64 %7)
%23 = trunc i64 %22 to i32
br label %26
24: ; preds = %18, %2
%25 = load i32, i32* @EXIT_FAILURE
br label %26
26: ; preds = %11, %14, %21, %24
%27 = phi i32 [ %25, %24 ], [ -1, %11 ], [ %17, %14 ], [ %23, %21 ]
ret i32 %27
}