#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 EINVAL;
int /*<<< orphan*/ assert(int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
int iam(char const *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ print_message(char *, char const *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char const *);
int strlen(char const *);
int whoami(char *, int);
int test(const char *name, int max_score, int expected_rval1, int size,
         int expected_rval2) {
  int rval;
  int len;
  char *gotname;
  int score = -1;
  assert(name != NULL);
  print_message("name = \"%s\", length = %d...", name);
  len = strlen(name);
  rval = iam(name);
  if (rval == expected_rval1) {
    if (rval == -1 && errno == EINVAL) {
      printf("PASS\n");
      score = max_score;
    } else if (rval == -1 && errno != EINVAL) {
      printf("\nERROR iam(): Bad errno %d. It should be %d(EINVAL).\n", errno,
             EINVAL);
      score = 0;
    }
  } else {
    printf("\nERROR iam(): Return value is %d. It should be %d.\n", rval,
           expected_rval1);
    score = 0;
  }
  if (score != -1)
    return score;
  gotname = (char *)malloc(len + 1);
  if (gotname == NULL)
    exit(-1);
  memset(gotname, 0, len + 1);
  rval = whoami(gotname, size);
  if (rval == expected_rval2) {
    if (rval == -1) {
      printf("PASS\n");
      score = max_score;
    } else {
      if (strcmp(gotname, name) == 0) {
        printf("PASS\n");
        score = max_score;
      } else {
        print_message("\nERROR whoami(): we got %s(%d). ", gotname);
        print_message("It should be %s(%d).\n", name);
        score = 0;
      }
    }
  } else if (rval == -1) {
    printf("\nERROR whoami(): Return value is -1 and errno is %d. Why?\n",
           errno);
    score = 0;
  } else {
    printf("\nERROR whoami(): Return value should be %d, not %d.\n",
           expected_rval2, rval);
    score = 0;
  }
  free(gotname);
  assert(score != -1);
  return score;
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movl   $0xffffffff,-0x34(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
mov    -0x10(%rbp),%rsi
lea    0xe13(%rip),%rdi
call   1060 <print_message@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <iam@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    12a4 <test+0xf4>
cmpl   $0xffffffff,-0x24(%rbp)
jne    1251 <test+0xa1>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    0x2da8(%rip),%rcx
cmp    (%rcx),%eax
jne    1251 <test+0xa1>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    129f <test+0xef>
cmpl   $0xffffffff,-0x24(%rbp)
jne    129a <test+0xea>
mov    0x2d7e(%rip),%rax
mov    (%rax),%eax
mov    0x2d6d(%rip),%rcx
cmp    (%rcx),%eax
je     129a <test+0xea>
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
mov    0x2d55(%rip),%rax
mov    (%rax),%edx
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x34(%rbp)
jmp    129f <test+0xef>
jmp    12bf <test+0x10f>
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
je     12d4 <test+0x124>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1415 <test+0x265>
mov    -0x28(%rbp),%edi
add    $0x1,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12f8 <test+0x148>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1090 <whoami@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    13a8 <test+0x1f8>
cmpl   $0xffffffff,-0x24(%rbp)
jne    1347 <test+0x197>
lea    0xce7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    13a3 <test+0x1f3>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1377 <test+0x1c7>
lea    0xcb7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    139e <test+0x1ee>
mov    -0x30(%rbp),%rsi
lea    0xd0a(%rip),%rdi
call   1060 <print_message@plt>
mov    -0x10(%rbp),%rsi
lea    0xd1b(%rip),%rdi
call   1060 <print_message@plt>
movl   $0x0,-0x34(%rbp)
jmp    13a3 <test+0x1f3>
jmp    13f5 <test+0x245>
cmpl   $0xffffffff,-0x24(%rbp)
jne    13d5 <test+0x225>
mov    0x2c27(%rip),%rax
mov    (%rax),%esi
lea    0xd01(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x34(%rbp)
jmp    13f0 <test+0x240>
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xd1c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x34(%rbp)
jmp    13f5 <test+0x245>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0xffffffff,-0x34(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %esi,%r13d
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   10c0 <assert@plt>
lea    0xe12(%rip),%rdi
mov    %rbx,%rsi
call   1070 <print_message@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1050 <iam@plt>
cmp    %ebp,%eax
jne    1299 <test+0xd9>
cmp    $0xffffffff,%ebp
je     12b3 <test+0xf3>
mov    %r14d,%ebp
add    $0x1,%r12d
mov    %r12d,%edi
call   10d0 <malloc@plt>
test   %rax,%rax
je     135a <test+0x19a>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12d,%edx
call   1090 <memset@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   10a0 <whoami@plt>
cmp    %r15d,%eax
jne    12e0 <test+0x120>
cmp    $0xffffffff,%r15d
je     12fd <test+0x13d>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     12fd <test+0x13d>
lea    0xe0c(%rip),%rdi
mov    %r14,%rsi
call   1070 <print_message@plt>
lea    0xe1e(%rip),%rdi
mov    %rbx,%rsi
call   1070 <print_message@plt>
xor    %r13d,%r13d
jmp    1331 <test+0x171>
lea    0xdb2(%rip),%rdi
xor    %r13d,%r13d
mov    %eax,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1348 <test+0x188>
mov    0x2d26(%rip),%rax
mov    (%rax),%esi
mov    0x2d15(%rip),%rax
mov    (%rax),%edx
cmp    %edx,%esi
jne    130b <test+0x14b>
lea    0xe5d(%rip),%rdi
call   1040 <puts@plt>
cmp    $0xffffffff,%r13d
jne    1348 <test+0x188>
jmp    121a <test+0x5a>
cmp    $0xffffffff,%eax
je     1317 <test+0x157>
lea    0xe0c(%rip),%rdi
xor    %r13d,%r13d
mov    %r15d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1331 <test+0x171>
lea    0xe29(%rip),%rdi
call   1040 <puts@plt>
jmp    1331 <test+0x171>
lea    0xd0a(%rip),%rdi
xor    %r13d,%r13d
jmp    12a7 <test+0xe7>
mov    0x2cc2(%rip),%rax
mov    (%rax),%esi
lea    0xd96(%rip),%rdi
xor    %r13d,%r13d
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %edi,%edi
cmp    $0xffffffff,%r13d
setne  %dil
call   10c0 <assert@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"name = \22%s\22, length = %d...\00"
@errno = global i32 0
@EINVAL = global i32 0
@.str.1 = [6 x i8] c"PASS\0A\00"
@.str.2 = [54 x i8] c"\0AERROR iam(): Bad errno %d. It should be %d(EINVAL).\0A\00"
@.str.3 = [52 x i8] c"\0AERROR iam(): Return value is %d. It should be %d.\0A\00"
@.str.4 = [33 x i8] c"\0AERROR whoami(): we got %s(%d). \00"
@.str.5 = [22 x i8] c"It should be %s(%d).\0A\00"
@.str.6 = [59 x i8] c"\0AERROR whoami(): Return value is -1 and errno is %d. Why?\0A\00"
@.str.7 = [53 x i8] c"\0AERROR whoami(): Return value should be %d, not %d.\0A\00"
define i32 @test(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 -1, i32* %15
%16 = load i8*, i8** %7
%17 = icmp ne i8* %16, null
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i8*, i8** %7
%21 = call i32 @print_message(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %7
%23 = call i32 @strlen(i8* %22)
store i32 %23, i32* %13
%24 = load i8*, i8** %7
%25 = call i32 @iam(i8* %24)
store i32 %25, i32* %12
%26 = load i32, i32* %12
%27 = load i32, i32* %9
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %52
29: ; preds = %5
%30 = load i32, i32* %12
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %39
32: ; preds = %29
%33 = load i32, i32* @errno
%34 = load i32, i32* @EINVAL
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%38 = load i32, i32* %8
store i32 %38, i32* %15
br label %51
39: ; preds = %32, %29
%40 = load i32, i32* %12
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %50
42: ; preds = %39
%43 = load i32, i32* @errno
%44 = load i32, i32* @EINVAL
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = load i32, i32* @errno
%48 = load i32, i32* @EINVAL
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %47, i32 %48)
store i32 0, i32* %15
br label %50
50: ; preds = %46, %42, %39
br label %51
51: ; preds = %50, %36
br label %56
52: ; preds = %5
%53 = load i32, i32* %12
%54 = load i32, i32* %9
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 %53, i32 %54)
store i32 0, i32* %15
br label %56
56: ; preds = %52, %51
%57 = load i32, i32* %15
%58 = icmp ne i32 %57, -1
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = load i32, i32* %15
store i32 %60, i32* %6
br label %121
61: ; preds = %56
%62 = load i32, i32* %13
%63 = add nsw i32 %62, 1
%64 = call i64 @malloc(i32 %63)
%65 = inttoptr i64 %64 to i8*
store i8* %65, i8** %14
%66 = load i8*, i8** %14
%67 = icmp eq i8* %66, null
br i1 %67, label %68, label %70
68: ; preds = %61
%69 = call i32 @exit(i32 -1)
unreachable
70: ; preds = %61
%71 = load i8*, i8** %14
%72 = load i32, i32* %13
%73 = add nsw i32 %72, 1
%74 = call i32 @memset(i8* %71, i32 0, i32 %73)
%75 = load i8*, i8** %14
%76 = load i32, i32* %10
%77 = call i32 @whoami(i8* %75, i32 %76)
store i32 %77, i32* %12
%78 = load i32, i32* %12
%79 = load i32, i32* %11
%80 = icmp eq i32 %78, %79
br i1 %80, label %81, label %102
81: ; preds = %70
%82 = load i32, i32* %12
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %87
84: ; preds = %81
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%86 = load i32, i32* %8
store i32 %86, i32* %15
br label %101
87: ; preds = %81
%88 = load i8*, i8** %14
%89 = load i8*, i8** %7
%90 = call i64 @strcmp(i8* %88, i8* %89)
%91 = icmp eq i64 %90, 0
br i1 %91, label %92, label %95
92: ; preds = %87
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%94 = load i32, i32* %8
store i32 %94, i32* %15
br label %100
95: ; preds = %87
%96 = load i8*, i8** %14
%97 = call i32 @print_message(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %96)
%98 = load i8*, i8** %7
%99 = call i32 @print_message(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %98)
store i32 0, i32* %15
br label %100
100: ; preds = %95, %92
br label %101
101: ; preds = %100, %84
br label %113
102: ; preds = %70
%103 = load i32, i32* %12
%104 = icmp eq i32 %103, -1
br i1 %104, label %105, label %108
105: ; preds = %102
%106 = load i32, i32* @errno
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.6, i64 0, i64 0), i32 %106)
store i32 0, i32* %15
br label %112
108: ; preds = %102
%109 = load i32, i32* %11
%110 = load i32, i32* %12
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0), i32 %109, i32 %110)
store i32 0, i32* %15
br label %112
112: ; preds = %108, %105
br label %113
113: ; preds = %112, %101
%114 = load i8*, i8** %14
%115 = call i32 @free(i8* %114)
%116 = load i32, i32* %15
%117 = icmp ne i32 %116, -1
%118 = zext i1 %117 to i32
%119 = call i32 @assert(i32 %118)
%120 = load i32, i32* %15
store i32 %120, i32* %6
br label %121
121: ; preds = %113, %59
%122 = load i32, i32* %6
ret i32 %122
}

LLVM IR (-O2):
@.str = [28 x i8] c"name = \22%s\22, length = %d...\00"
@errno = global i32 0
@EINVAL = global i32 0
@.str.2 = [54 x i8] c"\0AERROR iam(): Bad errno %d. It should be %d(EINVAL).\0A\00"
@.str.3 = [52 x i8] c"\0AERROR iam(): Return value is %d. It should be %d.\0A\00"
@.str.4 = [33 x i8] c"\0AERROR whoami(): we got %s(%d). \00"
@.str.5 = [22 x i8] c"It should be %s(%d).\0A\00"
@.str.6 = [59 x i8] c"\0AERROR whoami(): Return value is -1 and errno is %d. Why?\0A\00"
@.str.7 = [53 x i8] c"\0AERROR whoami(): Return value should be %d, not %d.\0A\00"
@str.9 = [5 x i8] c"PASS\00"
define i32 @test(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp ne i8* %0, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i32 @print_message(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = tail call i32 @strlen(i8* %0)
%11 = tail call i32 @iam(i8* %0)
%12 = icmp eq i32 %11, %2
br i1 %12, label %13, label %21
13: ; preds = %5
%14 = icmp eq i32 %2, -1
br i1 %14, label %15, label %26
15: ; preds = %13
%16 = load i32, i32* @errno
%17 = load i32, i32* @EINVAL
%18 = icmp eq i32 %16, %17
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 %17)
br label %62
21: ; preds = %5
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 %11, i32 %2)
br label %62
23: ; preds = %15
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.9, i64 0, i64 0))
%25 = icmp eq i32 %1, -1
br i1 %25, label %26, label %62
26: ; preds = %13, %23
%27 = add nsw i32 %10, 1
%28 = tail call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i8*
%30 = icmp eq i64 %28, 0
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = tail call i32 @exit(i32 -1)
unreachable
33: ; preds = %26
%34 = tail call i32 @memset(i8* %29, i32 0, i32 %27)
%35 = tail call i32 @whoami(i8* %29, i32 %3)
%36 = icmp eq i32 %35, %4
br i1 %36, label %37, label %49
37: ; preds = %33
%38 = icmp eq i32 %4, -1
br i1 %38, label %39, label %41
39: ; preds = %37
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.9, i64 0, i64 0))
br label %56
41: ; preds = %37
%42 = tail call i64 @strcmp(i8* %29, i8* %0)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.9, i64 0, i64 0))
br label %56
46: ; preds = %41
%47 = tail call i32 @print_message(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %29)
%48 = tail call i32 @print_message(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %0)
br label %56
49: ; preds = %33
%50 = icmp eq i32 %35, -1
br i1 %50, label %51, label %54
51: ; preds = %49
%52 = load i32, i32* @errno
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.6, i64 0, i64 0), i32 %52)
br label %56
54: ; preds = %49
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0), i32 %4, i32 %35)
br label %56
56: ; preds = %51, %54, %39, %46, %44
%57 = phi i32 [ %1, %39 ], [ %1, %44 ], [ 0, %46 ], [ 0, %51 ], [ 0, %54 ]
%58 = tail call i32 @free(i8* %29)
%59 = icmp ne i32 %57, -1
%60 = zext i1 %59 to i32
%61 = tail call i32 @assert(i32 %60)
br label %62
62: ; preds = %21, %19, %23, %56
%63 = phi i32 [ %57, %56 ], [ %1, %23 ], [ 0, %19 ], [ 0, %21 ]
ret i32 %63
}