#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 /*<<< orphan*/ gen(char **, int);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *);
int main() {
  char text[3][100], string[100];
  int i, j, index, count = 0;
  printf("Sample if-statements :\n");
  printf("\t1) if (a>b) then (s=a);\n");
  printf("\t2) if (a>b) then (s=a) else (s=b);\n");
  printf("\nEnter an if statement :\n");
  gets(string);
  for (i = 0; string[i] != '\0' && string[i] != ';'; i++) {
    if (string[i] == '(') {
      index = 0;
      for (j = i; string[j - 1] != ')'; j++) {
        if (string[j] == '\0') {
          printf("\nIllegal if statement. Exiting...\n");
          return 1;
        }
        text[count][index++] = string[j];
      }
      i = j - 1;
      count++;
    }
  }
  if (count < 2) {
    printf("\nIllegal if statement!! Exiting...");
    return 0;
  }
  gen(text, count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1b0(%rbp)
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
call   1030 <printf@plt>
lea    0xee0(%rip),%rdi
call   1030 <printf@plt>
lea    -0x1a0(%rbp),%rdi
call   1040 <gets@plt>
movl   $0x0,-0x1a4(%rbp)
movslq -0x1a4(%rbp),%rax
movsbl -0x1a0(%rbp,%rax,1),%ecx
ff
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1b1(%rbp)
je     11cd <main+0x9d>
movslq -0x1a4(%rbp),%rax
movsbl -0x1a0(%rbp,%rax,1),%eax
ff
cmp    $0x3b,%eax
setne  %al
mov    %al,-0x1b1(%rbp)
mov    -0x1b1(%rbp),%al
test   $0x1,%al
jne    11e0 <main+0xb0>
jmp    12df <main+0x1af>
movslq -0x1a4(%rbp),%rax
movsbl -0x1a0(%rbp,%rax,1),%eax
ff
cmp    $0x28,%eax
jne    12c6 <main+0x196>
movl   $0x0,-0x1ac(%rbp)
mov    -0x1a4(%rbp),%eax
mov    %eax,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x1a0(%rbp,%rax,1),%eax
ff
cmp    $0x29,%eax
je     12a8 <main+0x178>
movslq -0x1a8(%rbp),%rax
movsbl -0x1a0(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
jne    125a <main+0x12a>
lea    0xe28(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    131d <main+0x1ed>
movslq -0x1a8(%rbp),%rax
mov    -0x1a0(%rbp,%rax,1),%dl
movslq -0x1b0(%rbp),%rcx
lea    -0x130(%rbp),%rax
imul   $0x64,%rcx,%rcx
add    %rcx,%rax
mov    -0x1ac(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1ac(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    120e <main+0xde>
mov    -0x1a8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
mov    -0x1b0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b0(%rbp)
jmp    12cb <main+0x19b>
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    1192 <main+0x62>
cmpl   $0x2,-0x1b0(%rbp)
jge    1304 <main+0x1d4>
lea    0xda1(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    131d <main+0x1ed>
lea    -0x130(%rbp),%rdi
mov    -0x1b0(%rbp),%esi
call   1050 <gen@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x1a8,%rsp
lea    0xed5(%rip),%rdi
call   1030 <puts@plt>
lea    0xee0(%rip),%rdi
call   1030 <puts@plt>
lea    0xeed(%rip),%rdi
call   1030 <puts@plt>
lea    0xf05(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1050 <gets@plt>
xor    %r9d,%r9d
lea    0x1(%rsp),%r8
xor    %esi,%esi
jmp    119e <main+0x5e>
nopl   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rdx
mov    %edx,%r9d
add    $0x1,%esi
add    $0x1,%r9d
movslq %r9d,%rdx
mov    (%rsp,%rdx,1),%al
cmp    $0x28,%al
je     11c0 <main+0x80>
test   %al,%al
je     1214 <main+0xd4>
cmp    $0x3b,%al
jne    119a <main+0x5a>
jmp    1214 <main+0xd4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpb   $0x29,-0x1(%rsp,%rdx,1)
je     1190 <main+0x50>
movslq %esi,%rax
imul   $0x64,%rax,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x70,%rdi
add    %r8,%rdx
mov    $0x28,%cl
xor    %eax,%eax
nopl   (%rax)
mov    %cl,(%rdi,%rax,1)
cmp    $0x29,%cl
je     11f6 <main+0xb6>
movzbl (%rdx,%rax,1),%ecx
add    $0x1,%rax
test   %cl,%cl
jne    11e0 <main+0xa0>
jmp    11fb <main+0xbb>
add    %eax,%r9d
jmp    1197 <main+0x57>
lea    0xe8e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x1a8,%rsp
ret
cmp    $0x1,%esi
jg     1227 <main+0xe7>
lea    0xde0(%rip),%rdi
call   1040 <printf@plt>
jmp    1231 <main+0xf1>
lea    0x70(%rsp),%rdi
call   1060 <gen@plt>
xor    %eax,%eax
add    $0x1a8,%rsp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Sample if-statements :\0A\00"
@.str.1 = [26 x i8] c"\091) if (a>b) then (s=a);\0A\00"
@.str.2 = [37 x i8] c"\092) if (a>b) then (s=a) else (s=b);\0A\00"
@.str.3 = [26 x i8] c"\0AEnter an if statement :\0A\00"
@.str.4 = [35 x i8] c"\0AIllegal if statement. Exiting...\0A\00"
@.str.5 = [35 x i8] c"\0AIllegal if statement!! Exiting...\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x [100 x i8]]
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %7
%8 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%13 = call i32 @gets(i8* %12)
store i32 0, i32* %4
br label %14
14: ; preds = %77, %0
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %14
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 59
br label %28
28: ; preds = %21, %14
%29 = phi i1 [ false, %14 ], [ %27, %21 ]
br i1 %29, label %30, label %80
30: ; preds = %28
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 40
br i1 %36, label %37, label %76
37: ; preds = %30
store i32 0, i32* %6
%38 = load i32, i32* %4
store i32 %38, i32* %5
br label %39
39: ; preds = %68, %37
%40 = load i32, i32* %5
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 41
br i1 %46, label %47, label %71
47: ; preds = %39
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %47
%55 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %90
56: ; preds = %47
%57 = load i32, i32* %5
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [3 x [100 x i8]], [3 x [100 x i8]]* %2, i64 0, i64 %62
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
%66 = sext i32 %64 to i64
%67 = getelementptr inbounds [100 x i8], [100 x i8]* %63, i64 0, i64 %66
store i8 %60, i8* %67
br label %68
68: ; preds = %56
%69 = load i32, i32* %5
%70 = add nsw i32 %69, 1
store i32 %70, i32* %5
br label %39
71: ; preds = %39
%72 = load i32, i32* %5
%73 = sub nsw i32 %72, 1
store i32 %73, i32* %4
%74 = load i32, i32* %7
%75 = add nsw i32 %74, 1
store i32 %75, i32* %7
br label %76
76: ; preds = %71, %30
br label %77
77: ; preds = %76
%78 = load i32, i32* %4
%79 = add nsw i32 %78, 1
store i32 %79, i32* %4
br label %14
80: ; preds = %28
%81 = load i32, i32* %7
%82 = icmp slt i32 %81, 2
br i1 %82, label %83, label %85
83: ; preds = %80
%84 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %90
85: ; preds = %80
%86 = getelementptr inbounds [3 x [100 x i8]], [3 x [100 x i8]]* %2, i64 0, i64 0
%87 = bitcast [100 x i8]* %86 to i8**
%88 = load i32, i32* %7
%89 = call i32 @gen(i8** %87, i32 %88)
store i32 0, i32* %1
br label %90
90: ; preds = %85, %83, %54
%91 = load i32, i32* %1
ret i32 %91
}

LLVM IR (-O2):
@.str.5 = [35 x i8] c"\0AIllegal if statement!! Exiting...\00"
@str = [23 x i8] c"Sample if-statements :\00"
@str.6 = [25 x i8] c"\091) if (a>b) then (s=a);\00"
@str.7 = [36 x i8] c"\092) if (a>b) then (s=a) else (s=b);\00"
@str.8 = [25 x i8] c"\0AEnter an if statement :\00"
@str.9 = [34 x i8] c"\0AIllegal if statement. Exiting...\00"
define i32 @main() {
%1 = alloca [3 x [100 x i8]]
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [3 x [100 x i8]], [3 x [100 x i8]]* %1, i64 0, i64 0, i64 0
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.7, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.8, i64 0, i64 0))
%9 = call i32 @gets(i8* %4)
br label %10
10: ; preds = %43, %0
%11 = phi i32 [ 0, %0 ], [ %46, %43 ]
%12 = phi i32 [ 0, %0 ], [ %45, %43 ]
%13 = sext i32 %11 to i64
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %13
%15 = load i8, i8* %14
switch i8 %15, label %43 [
i8 0, label %47
i8 59, label %47
i8 40, label %16
]
16: ; preds = %10
%17 = add nsw i32 %11, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 41
br i1 %21, label %40, label %22
22: ; preds = %16
%23 = sext i32 %12 to i64
br label %26
24: ; preds = %33
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.9, i64 0, i64 0))
br label %54
26: ; preds = %22, %33
%27 = phi i64 [ 0, %22 ], [ %34, %33 ]
%28 = phi i64 [ %13, %22 ], [ %31, %33 ]
%29 = phi i8 [ 40, %22 ], [ %36, %33 ]
%30 = getelementptr inbounds [3 x [100 x i8]], [3 x [100 x i8]]* %1, i64 0, i64 %23, i64 %27
store i8 %29, i8* %30
%31 = add i64 %28, 1
%32 = icmp eq i8 %29, 41
br i1 %32, label %38, label %33
33: ; preds = %26
%34 = add nuw i64 %27, 1
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %31
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 0
br i1 %37, label %24, label %26
38: ; preds = %26
%39 = trunc i64 %28 to i32
br label %40
40: ; preds = %38, %16
%41 = phi i32 [ %17, %16 ], [ %39, %38 ]
%42 = add nsw i32 %12, 1
br label %43
43: ; preds = %10, %40
%44 = phi i32 [ %41, %40 ], [ %11, %10 ]
%45 = phi i32 [ %42, %40 ], [ %12, %10 ]
%46 = add nsw i32 %44, 1
br label %10
47: ; preds = %10, %10
%48 = icmp slt i32 %12, 2
br i1 %48, label %49, label %51
49: ; preds = %47
%50 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %54
51: ; preds = %47
%52 = bitcast [3 x [100 x i8]]* %1 to i8**
%53 = call i32 @gen(i8** %52, i32 %12)
br label %54
54: ; preds = %51, %49, %24
%55 = phi i32 [ 1, %24 ], [ 0, %49 ], [ 0, %51 ]
ret i32 %55
}