#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 *allocHolderMemory(int);
char **allocateGridMemory(int);
int /*<<< orphan*/ binaryPrint(char, int);
int /*<<< orphan*/ fillGrid(char **, int);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ getchar();
char nextState(char **, char **, int);
int /*<<< orphan*/ printGrid(char **, int);
int /*<<< orphan*/ printf(char *, ...);
int progArguments(char **, int);
int main(int argc, char *argv[]) {
  int i;
  int k;
  int gridSize;
  char flagVar = 0;
  char **grid;
  char **copyGrid;
  int *changeHolder;
  gridSize = progArguments(argv, argc);
  grid = allocateGridMemory(gridSize);
  copyGrid = allocateGridMemory(gridSize);
  changeHolder = allocHolderMemory(gridSize);
  printf("in main grid == 0x%08x\n", (unsigned int)grid);
  fillGrid(grid, gridSize);
  fillGrid(copyGrid, gridSize);
  printGrid(grid, gridSize);
  do {
    getchar();
    if (0 == (flagVar & 0b10000000)) {
      printf("***executing if***\n");
      flagVar = flagVar | nextState(grid, copyGrid, gridSize);
      flagVar = flagVar | 0b10000000;
      printGrid(copyGrid, gridSize);
      printf("Content of flagVar: ");
      binaryPrint(flagVar, 1);
    } else {
      printf("***executing else***\n");
      flagVar = flagVar | nextState(copyGrid, grid, gridSize);
      flagVar = flagVar & 0b00000001;
      printGrid(grid, gridSize);
      printf("Content of flagVar: ");
      binaryPrint(flagVar, 1);
    }
  } while (0 == (flagVar & 0b00000001));
  free(grid);
  free(copyGrid);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x1d(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   10b0 <progArguments@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <allocateGridMemory@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <allocateGridMemory@plt>
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <allocHolderMemory@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,%esi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1090 <fillGrid@plt>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1090 <fillGrid@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10c0 <printGrid@plt>
mov    $0x0,%al
call   10a0 <getchar@plt>
movsbl -0x1d(%rbp),%ecx
and    $0x80,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    12ab <main+0x10b>
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movsbl -0x1d(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <nextState@plt>
mov    %al,%cl
mov    -0x3c(%rbp),%eax
movsbl %cl,%ecx
or     %ecx,%eax
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
or     $0x80,%eax
mov    %al,-0x1d(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10c0 <printGrid@plt>
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%esi
movsbl -0x1d(%rbp),%edi
call   1030 <binaryPrint@plt>
jmp    130f <main+0x16f>
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movsbl -0x1d(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <nextState@plt>
mov    %al,%cl
mov    -0x40(%rbp),%eax
movsbl %cl,%ecx
or     %ecx,%eax
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
and    $0x1,%eax
mov    %al,-0x1d(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10c0 <printGrid@plt>
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%esi
movsbl -0x1d(%rbp),%edi
call   1030 <binaryPrint@plt>
jmp    1314 <main+0x174>
movsbl -0x1d(%rbp),%ecx
and    $0x1,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     1225 <main+0x85>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%eax
mov    %rsi,%rdi
mov    %eax,%esi
call   10c0 <progArguments@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <allocateGridMemory@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1060 <allocateGridMemory@plt>
mov    %rax,%r15
mov    %ebx,%edi
call   1080 <allocHolderMemory@plt>
lea    0xe15(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   10a0 <fillGrid@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   10a0 <fillGrid@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   10d0 <printGrid@plt>
lea    0xdfe(%rip),%r13
xor    %r12d,%r12d
jmp    126b <main+0xbb>
nop
lea    0xe06(%rip),%rdi
call   1070 <puts@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <nextState@plt>
or     %r12b,%al
and    $0x1,%al
mov    %r14,%rdi
mov    %eax,%r12d
mov    %ebx,%esi
call   10d0 <printGrid@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
movsbl %r12b,%ebp
mov    %ebp,%edi
mov    $0x1,%esi
call   1030 <binaryPrint@plt>
test   $0x1,%bpl
jne    129c <main+0xec>
xor    %eax,%eax
call   10b0 <getchar@plt>
test   %r12b,%r12b
js     1220 <main+0x70>
lea    0xdc4(%rip),%rdi
call   1070 <puts@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <nextState@plt>
or     %al,%r12b
or     $0x80,%r12b
mov    %r15,%rdi
jmp    1244 <main+0x94>
mov    %r14,%rdi
call   1040 <free@plt>
mov    %r15,%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"in main grid == 0x%08x\0A\00"
@.str.1 = [20 x i8] c"***executing if***\0A\00"
@.str.2 = [21 x i8] c"Content of flagVar: \00"
@.str.3 = [22 x i8] c"***executing else***\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca i8**
%11 = alloca i8**
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8 0, i8* %9
%13 = load i8**, i8*** %5
%14 = load i32, i32* %4
%15 = call i32 @progArguments(i8** %13, i32 %14)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = call i8** @allocateGridMemory(i32 %16)
store i8** %17, i8*** %10
%18 = load i32, i32* %8
%19 = call i8** @allocateGridMemory(i32 %18)
store i8** %19, i8*** %11
%20 = load i32, i32* %8
%21 = call i32* @allocHolderMemory(i32 %20)
store i32* %21, i32** %12
%22 = load i8**, i8*** %10
%23 = ptrtoint i8** %22 to i32
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load i8**, i8*** %10
%26 = load i32, i32* %8
%27 = call i32 @fillGrid(i8** %25, i32 %26)
%28 = load i8**, i8*** %11
%29 = load i32, i32* %8
%30 = call i32 @fillGrid(i8** %28, i32 %29)
%31 = load i8**, i8*** %10
%32 = load i32, i32* %8
%33 = call i32 @printGrid(i8** %31, i32 %32)
br label %34
34: ; preds = %83, %2
%35 = call i32 (...) @getchar()
%36 = load i8, i8* %9
%37 = sext i8 %36 to i32
%38 = and i32 %37, 128
%39 = icmp eq i32 0, %38
br i1 %39, label %40, label %61
40: ; preds = %34
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%42 = load i8, i8* %9
%43 = sext i8 %42 to i32
%44 = load i8**, i8*** %10
%45 = load i8**, i8*** %11
%46 = load i32, i32* %8
%47 = call signext i8 @nextState(i8** %44, i8** %45, i32 %46)
%48 = sext i8 %47 to i32
%49 = or i32 %43, %48
%50 = trunc i32 %49 to i8
store i8 %50, i8* %9
%51 = load i8, i8* %9
%52 = sext i8 %51 to i32
%53 = or i32 %52, 128
%54 = trunc i32 %53 to i8
store i8 %54, i8* %9
%55 = load i8**, i8*** %11
%56 = load i32, i32* %8
%57 = call i32 @printGrid(i8** %55, i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%59 = load i8, i8* %9
%60 = call i32 @binaryPrint(i8 signext %59, i32 1)
br label %82
61: ; preds = %34
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%63 = load i8, i8* %9
%64 = sext i8 %63 to i32
%65 = load i8**, i8*** %11
%66 = load i8**, i8*** %10
%67 = load i32, i32* %8
%68 = call signext i8 @nextState(i8** %65, i8** %66, i32 %67)
%69 = sext i8 %68 to i32
%70 = or i32 %64, %69
%71 = trunc i32 %70 to i8
store i8 %71, i8* %9
%72 = load i8, i8* %9
%73 = sext i8 %72 to i32
%74 = and i32 %73, 1
%75 = trunc i32 %74 to i8
store i8 %75, i8* %9
%76 = load i8**, i8*** %10
%77 = load i32, i32* %8
%78 = call i32 @printGrid(i8** %76, i32 %77)
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%80 = load i8, i8* %9
%81 = call i32 @binaryPrint(i8 signext %80, i32 1)
br label %82
82: ; preds = %61, %40
br label %83
83: ; preds = %82
%84 = load i8, i8* %9
%85 = sext i8 %84 to i32
%86 = and i32 %85, 1
%87 = icmp eq i32 0, %86
br i1 %87, label %34, label %88
88: ; preds = %83
%89 = load i8**, i8*** %10
%90 = call i32 @free(i8** %89)
%91 = load i8**, i8*** %11
%92 = call i32 @free(i8** %91)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"in main grid == 0x%08x\0A\00"
@.str.2 = [21 x i8] c"Content of flagVar: \00"
@str = [21 x i8] c"***executing else***\00"
@str.4 = [19 x i8] c"***executing if***\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @progArguments(i8** %1, i32 %0)
%4 = tail call i8** @allocateGridMemory(i32 %3)
%5 = tail call i8** @allocateGridMemory(i32 %3)
%6 = tail call i32* @allocHolderMemory(i32 %3)
%7 = ptrtoint i8** %4 to i64
%8 = trunc i64 %7 to i32
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = tail call i32 @fillGrid(i8** %4, i32 %3)
%11 = tail call i32 @fillGrid(i8** %5, i32 %3)
%12 = tail call i32 @printGrid(i8** %4, i32 %3)
br label %13
13: ; preds = %27, %2
%14 = phi i8 [ 0, %2 ], [ %29, %27 ]
%15 = tail call i32 (...) @getchar()
%16 = icmp sgt i8 %14, -1
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.4, i64 0, i64 0))
%19 = tail call signext i8 @nextState(i8** %4, i8** %5, i32 %3)
%20 = or i8 %14, %19
%21 = or i8 %20, -128
br label %27
22: ; preds = %13
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%24 = tail call signext i8 @nextState(i8** %5, i8** %4, i32 %3)
%25 = or i8 %24, %14
%26 = and i8 %25, 1
br label %27
27: ; preds = %17, %22
%28 = phi i8** [ %5, %17 ], [ %4, %22 ]
%29 = phi i8 [ %21, %17 ], [ %26, %22 ]
%30 = tail call i32 @printGrid(i8** %28, i32 %3)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%32 = tail call i32 @binaryPrint(i8 signext %29, i32 1)
%33 = and i8 %29, 1
%34 = icmp eq i8 %33, 0
br i1 %34, label %13, label %35
35: ; preds = %27
%36 = tail call i32 @free(i8** %4)
%37 = tail call i32 @free(i8** %5)
ret i32 0
}