#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 */
scalar_t__ canvasGetFormat(int, char *);
char *getenv(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
long strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  printf("Content-Type: text/plain;charset=us-ascii\n\n");
  char *value = NULL;
  long number = 0;
  value = getenv("NB");
  if (!value)
    return 0;
  number = strtol(value, NULL, 0);
  if (!number)
    return 0;
  char buffer[64];
  memset(buffer, 0, 64);
  if (canvasGetFormat((int)number, buffer)) {
    printf("0\n");
    return 0;
  }
  printf("%s", buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xea1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ab <main+0x5b>
movl   $0x0,-0x4(%rbp)
jmp    1231 <main+0xe1>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d5 <main+0x85>
movl   $0x0,-0x4(%rbp)
jmp    1231 <main+0xe1>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1060 <memset@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%edi
lea    -0x60(%rbp),%rsi
call   1040 <canvasGetFormat@plt>
cmp    $0x0,%rax
je     1218 <main+0xc8>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1231 <main+0xe1>
lea    -0x60(%rbp),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
lea    0xe98(%rip),%rdi
call   1040 <puts@plt>
lea    0xe86(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11d8 <main+0x78>
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <strtol@plt>
test   %rax,%rax
je     11d8 <main+0x78>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <canvasGetFormat@plt>
test   %rax,%rax
je     11c7 <main+0x67>
lea    0xe71(%rip),%rdi
call   1040 <puts@plt>
jmp    11d8 <main+0x78>
lea    0xe35(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Content-Type: text/plain;charset=us-ascii\0A\0A\00"
@.str.1 = [3 x i8] c"NB\00"
@.str.2 = [3 x i8] c"0\0A\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [64 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %6
store i64 0, i64* %7
%10 = call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %2
store i32 0, i32* %3
br label %33
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = call i64 @strtol(i8* %15, i32* null, i32 0)
store i64 %16, i64* %7
%17 = load i64, i64* %7
%18 = icmp ne i64 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %14
store i32 0, i32* %3
br label %33
20: ; preds = %14
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%22 = call i32 @memset(i8* %21, i32 0, i32 64)
%23 = load i64, i64* %7
%24 = trunc i64 %23 to i32
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%26 = call i64 @canvasGetFormat(i32 %24, i8* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %33
30: ; preds = %20
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %31)
store i32 0, i32* %3
br label %33
33: ; preds = %30, %28, %19, %13
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"NB\00"
@.str.3 = [3 x i8] c"%s\00"
@str = [43 x i8] c"Content-Type: text/plain;charset=us-ascii\0A\00"
@str.4 = [2 x i8] c"0\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [64 x i8]
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %21, label %7
7: ; preds = %2
%8 = tail call i64 @strtol(i8* nocapture %5, i32* null, i32 0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %21, label %10
10: ; preds = %7
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 64)
%13 = trunc i64 %8 to i32
%14 = call i64 @canvasGetFormat(i32 %13, i8* %11)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %10
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.4, i64 0, i64 0))
br label %20
18: ; preds = %10
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %11)
br label %20
20: ; preds = %18, %16
br label %21
21: ; preds = %7, %2, %20
ret i32 0
}