#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 atoi(char *);
int /*<<< orphan*/ checkerboard(int);
int /*<<< orphan*/ disk(int);
int /*<<< orphan*/ h(int);
int /*<<< orphan*/ noise(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rectangle(int);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ writePGM(char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    printf("usage: se_gen (disk|rectangle|h|checkerboard|noise) size\n");
    return 0;
  }
  int d = atoi(argv[2]);
  if (!strcmp(argv[1], "disk")) {
    writePGM("disk.pgm", disk(d));
  } else if (!strcmp(argv[1], "rectangle")) {
    writePGM("rectangle.pgm", rectangle(d));
  } else if (!strcmp(argv[1], "h")) {
    writePGM("h.pgm", h(d));
  } else if (!strcmp(argv[1], "checkerboard")) {
    writePGM("checkerboard.pgm", checkerboard(d));
  } else if (!strcmp(argv[1], "noise")) {
    writePGM("noise.pgm", noise(d));
  } else {
    printf("ERROR: shape '%s' not supported", argv[1]);
  }
  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)
cmpl   $0x3,-0x8(%rbp)
jge    11ca <main+0x3a>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1323 <main+0x193>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe51(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1212 <main+0x82>
mov    -0x14(%rbp),%edi
call   1030 <disk@plt>
mov    %eax,%esi
lea    0xe37(%rip),%rdi
call   1070 <writePGM@plt>
jmp    131c <main+0x18c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe27(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    124a <main+0xba>
mov    -0x14(%rbp),%edi
call   1040 <rectangle@plt>
mov    %eax,%esi
lea    0xe12(%rip),%rdi
call   1070 <writePGM@plt>
jmp    1317 <main+0x187>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe07(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1282 <main+0xf2>
mov    -0x14(%rbp),%edi
call   1050 <h@plt>
mov    %eax,%esi
lea    0xdea(%rip),%rdi
call   1070 <writePGM@plt>
jmp    1312 <main+0x182>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd7(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    12ba <main+0x12a>
mov    -0x14(%rbp),%edi
call   10b0 <checkerboard@plt>
mov    %eax,%esi
lea    0xdc5(%rip),%rdi
call   1070 <writePGM@plt>
jmp    130d <main+0x17d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdbd(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    12f2 <main+0x162>
mov    -0x14(%rbp),%edi
call   1090 <noise@plt>
mov    %eax,%esi
lea    0xda4(%rip),%rdi
call   1070 <writePGM@plt>
jmp    1308 <main+0x178>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    130d <main+0x17d>
jmp    1312 <main+0x182>
jmp    1317 <main+0x187>
jmp    131c <main+0x18c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     11b9 <main+0x19>
lea    0xecd(%rip),%rdi
call   1030 <puts@plt>
jmp    1292 <main+0xf2>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%rbx
lea    0xe2e(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
je     123d <main+0x9d>
lea    0xe29(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
je     124d <main+0xad>
lea    0xe2e(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
je     125d <main+0xbd>
lea    0xe23(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
je     126d <main+0xcd>
lea    0xe2e(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
je     127d <main+0xdd>
lea    0xe2b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1292 <main+0xf2>
mov    %ebp,%edi
call   1040 <disk@plt>
lea    0xdba(%rip),%rdi
jmp    128b <main+0xeb>
mov    %ebp,%edi
call   1050 <rectangle@plt>
lea    0xdbd(%rip),%rdi
jmp    128b <main+0xeb>
mov    %ebp,%edi
call   1060 <h@plt>
lea    0xdbd(%rip),%rdi
jmp    128b <main+0xeb>
mov    %ebp,%edi
call   10c0 <checkerboard@plt>
lea    0xdc0(%rip),%rdi
jmp    128b <main+0xeb>
mov    %ebp,%edi
call   10a0 <noise@plt>
lea    0xdc7(%rip),%rdi
mov    %eax,%esi
call   1080 <writePGM@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [58 x i8] c"usage: se_gen (disk|rectangle|h|checkerboard|noise) size\0A\00"
@.str.1 = [5 x i8] c"disk\00"
@.str.2 = [9 x i8] c"disk.pgm\00"
@.str.3 = [10 x i8] c"rectangle\00"
@.str.4 = [14 x i8] c"rectangle.pgm\00"
@.str.5 = [2 x i8] c"h\00"
@.str.6 = [6 x i8] c"h.pgm\00"
@.str.7 = [13 x i8] c"checkerboard\00"
@.str.8 = [17 x i8] c"checkerboard.pgm\00"
@.str.9 = [6 x i8] c"noise\00"
@.str.10 = [10 x i8] c"noise.pgm\00"
@.str.11 = [32 x i8] c"ERROR: shape '%s' not supported\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %75
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 2
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %6
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @strcmp(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %11
%22 = load i32, i32* %6
%23 = call i32 @disk(i32 %22)
%24 = call i32 @writePGM(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %23)
br label %74
25: ; preds = %11
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @strcmp(i8* %28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %25
%32 = load i32, i32* %6
%33 = call i32 @rectangle(i32 %32)
%34 = call i32 @writePGM(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %33)
br label %73
35: ; preds = %25
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 @strcmp(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%40 = icmp ne i32 %39, 0
br i1 %40, label %45, label %41
41: ; preds = %35
%42 = load i32, i32* %6
%43 = call i32 @h(i32 %42)
%44 = call i32 @writePGM(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %43)
br label %72
45: ; preds = %35
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i32 @strcmp(i8* %48, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%50 = icmp ne i32 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %45
%52 = load i32, i32* %6
%53 = call i32 @checkerboard(i32 %52)
%54 = call i32 @writePGM(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i32 %53)
br label %71
55: ; preds = %45
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 1
%58 = load i8*, i8** %57
%59 = call i32 @strcmp(i8* %58, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%60 = icmp ne i32 %59, 0
br i1 %60, label %65, label %61
61: ; preds = %55
%62 = load i32, i32* %6
%63 = call i32 @noise(i32 %62)
%64 = call i32 @writePGM(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i32 %63)
br label %70
65: ; preds = %55
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 1
%68 = load i8*, i8** %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.11, i64 0, i64 0), i8* %68)
br label %70
70: ; preds = %65, %61
br label %71
71: ; preds = %70, %51
br label %72
72: ; preds = %71, %41
br label %73
73: ; preds = %72, %31
br label %74
74: ; preds = %73, %21
store i32 0, i32* %3
br label %75
75: ; preds = %74, %9
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"disk\00"
@.str.2 = [9 x i8] c"disk.pgm\00"
@.str.3 = [10 x i8] c"rectangle\00"
@.str.4 = [14 x i8] c"rectangle.pgm\00"
@.str.5 = [2 x i8] c"h\00"
@.str.6 = [6 x i8] c"h.pgm\00"
@.str.7 = [13 x i8] c"checkerboard\00"
@.str.8 = [17 x i8] c"checkerboard.pgm\00"
@.str.9 = [6 x i8] c"noise\00"
@.str.10 = [10 x i8] c"noise.pgm\00"
@.str.11 = [32 x i8] c"ERROR: shape '%s' not supported\00"
@str = [57 x i8] c"usage: se_gen (disk|rectangle|h|checkerboard|noise) size\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
br label %43
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %6
%15 = tail call i32 @disk(i32 %9)
%16 = tail call i32 @writePGM(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %43
17: ; preds = %6
%18 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = tail call i32 @rectangle(i32 %9)
%22 = tail call i32 @writePGM(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %21)
br label %43
23: ; preds = %17
%24 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = tail call i32 @h(i32 %9)
%28 = tail call i32 @writePGM(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %27)
br label %43
29: ; preds = %23
%30 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(13) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = tail call i32 @checkerboard(i32 %9)
%34 = tail call i32 @writePGM(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i32 %33)
br label %43
35: ; preds = %29
%36 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = tail call i32 @noise(i32 %9)
%40 = tail call i32 @writePGM(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i32 %39)
br label %43
41: ; preds = %35
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.11, i64 0, i64 0), i8* %11)
br label %43
43: ; preds = %14, %26, %38, %41, %32, %20, %4
ret i32 0
}