#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 INT_MAX;
int LONG_MAX;
int SHRT_MAX;
short *calloc(long, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
long strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  long x;
  short *y;
  x = strtol(argv[1], NULL, 10);
  fprintf(stderr, "x=%ld\n", x);
  y = calloc(x, sizeof(short));
  if (y != NULL) {
    fprintf(stderr, "ok\n");
  } else {
    fprintf(stderr, "failed\n");
  }
  fprintf(stderr, "long max=%ld (%ld)\n", LONG_MAX, sizeof(long));
  fprintf(stderr, "shrt max=%d (%ld)\n", SHRT_MAX, sizeof(short));
  fprintf(stderr, "int  max=%d (%ld)\n", INT_MAX, sizeof(int));
  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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe8c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    $0x2,%esi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b4 <main+0x84>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11cb <main+0x9b>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%edx
lea    0xe2f(%rip),%rsi
mov    $0x8,%ecx
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    0x2dc8(%rip),%rax
mov    (%rax),%edx
lea    0xe1e(%rip),%rsi
mov    $0x2,%ecx
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    0x2dc3(%rip),%rax
mov    (%rax),%edx
lea    0xe0c(%rip),%rsi
mov    $0x4,%ecx
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%rbx
mov    0x2e8a(%rip),%r14
mov    (%r14),%edi
lea    0xea8(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <calloc@plt>
test   %rax,%rax
mov    (%r14),%edi
lea    0xe8f(%rip),%rax
lea    0xe84(%rip),%rsi
cmove  %rax,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
lea    0xe72(%rip),%rsi
mov    $0x8,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
lea    0xe67(%rip),%rsi
mov    $0x2,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
lea    0xe5b(%rip),%rsi
mov    $0x4,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [7 x i8] c"x=%ld\0A\00"
@.str.1 = [4 x i8] c"ok\0A\00"
@.str.2 = [8 x i8] c"failed\0A\00"
@.str.3 = [20 x i8] c"long max=%ld (%ld)\0A\00"
@LONG_MAX = global i32 0
@.str.4 = [19 x i8] c"shrt max=%d (%ld)\0A\00"
@SHRT_MAX = global i32 0
@.str.5 = [19 x i8] c"int max=%d (%ld)\0A\00"
@INT_MAX = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i16*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = call i64 @strtol(i8* %10, i32* null, i32 10)
store i64 %11, i64* %6
%12 = load i32, i32* @stderr
%13 = load i64, i64* %6
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %13)
%15 = load i64, i64* %6
%16 = call i16* @calloc(i64 %15, i32 2)
store i16* %16, i16** %7
%17 = load i16*, i16** %7
%18 = icmp ne i16* %17, null
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %25
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %22, %19
%26 = load i32, i32* @stderr
%27 = load i32, i32* @LONG_MAX
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %27, i64 8)
%29 = load i32, i32* @stderr
%30 = load i32, i32* @SHRT_MAX
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %30, i64 2)
%32 = load i32, i32* @stderr
%33 = load i32, i32* @INT_MAX
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %33, i64 4)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [7 x i8] c"x=%ld\0A\00"
@.str.1 = [4 x i8] c"ok\0A\00"
@.str.2 = [8 x i8] c"failed\0A\00"
@.str.3 = [20 x i8] c"long max=%ld (%ld)\0A\00"
@LONG_MAX = global i32 0
@.str.4 = [19 x i8] c"shrt max=%d (%ld)\0A\00"
@SHRT_MAX = global i32 0
@.str.5 = [19 x i8] c"int max=%d (%ld)\0A\00"
@INT_MAX = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i64 @strtol(i8* nocapture %4, i32* null, i32 10)
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %5)
%8 = tail call i16* @calloc(i64 %5, i32 2)
%9 = icmp eq i16* %8, null
%10 = load i32, i32* @stderr
%11 = select i1 %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* %11)
%13 = load i32, i32* @stderr
%14 = load i32, i32* @LONG_MAX
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %14, i64 8)
%16 = load i32, i32* @stderr
%17 = load i32, i32* @SHRT_MAX
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %17, i64 2)
%19 = load i32, i32* @stderr
%20 = load i32, i32* @INT_MAX
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %20, i64 4)
ret i32 0
}