#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__ malloc(int);
int /*<<< orphan*/ printZigZag(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int *input1, *input2;
  input1 = (int *)malloc(sizeof(int));
  input2 = (int *)malloc(sizeof(int));
  printf("Please enter the width of the zig zag: ");
  do {
    (scanf("%d", input1));
  } while (*input1 < 1);
  printf("\n");
  printf("Please enter the number of round trips: ");
  do {
    (scanf("%d", input2));
  } while (*input2 < 1);
  printf("\n");
  printZigZag(*input1, *input2);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xea6(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x1,(%rax)
jl     1177 <main+0x37>
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x18(%rbp),%rax
cmpl   $0x1,(%rax)
jl     11ac <main+0x6c>
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1030 <printZigZag@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xe8a(%rip),%rdi
call   1050 <printf@plt>
lea    0xea6(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <scanf@plt>
cmpl   $0x0,(%r14)
jle    1190 <main+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe79(%rip),%rdi
call   1050 <printf@plt>
lea    0xe6a(%rip),%r15
xchg   %ax,%ax
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
cmpl   $0x0,(%rbx)
jle    11c0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%r14),%edi
mov    (%rbx),%esi
call   1040 <printZigZag@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Please enter the width of the zig zag: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [41 x i8] c"Please enter the number of round trips: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i64 @malloc(i32 4)
%5 = inttoptr i64 %4 to i32*
store i32* %5, i32** %2
%6 = call i64 @malloc(i32 4)
%7 = inttoptr i64 %6 to i32*
store i32* %7, i32** %3
%8 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %12, %0
%10 = load i32*, i32** %2
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %10)
br label %12
12: ; preds = %9
%13 = load i32*, i32** %2
%14 = load i32, i32* %13
%15 = icmp slt i32 %14, 1
br i1 %15, label %9, label %16
16: ; preds = %12
%17 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %22, %16
%20 = load i32*, i32** %3
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %20)
br label %22
22: ; preds = %19
%23 = load i32*, i32** %3
%24 = load i32, i32* %23
%25 = icmp slt i32 %24, 1
br i1 %25, label %19, label %26
26: ; preds = %22
%27 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32*, i32** %2
%29 = load i32, i32* %28
%30 = load i32*, i32** %3
%31 = load i32, i32* %30
%32 = call i32 @printZigZag(i32 %29, i32 %31)
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@.str = [40 x i8] c"Please enter the width of the zig zag: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [41 x i8] c"Please enter the number of round trips: \00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 4)
%2 = inttoptr i64 %1 to i32*
%3 = tail call i64 @malloc(i32 4)
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %5, %0
%6 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 1
br i1 %8, label %5, label %9
9: ; preds = %5
%10 = inttoptr i64 %3 to i32*
%11 = tail call i32 @putchar(i32 10)
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %13, %9
%14 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %10)
%15 = load i32, i32* %10
%16 = icmp slt i32 %15, 1
br i1 %16, label %13, label %17
17: ; preds = %13
%18 = tail call i32 @putchar(i32 10)
%19 = load i32, i32* %2
%20 = load i32, i32* %10
%21 = tail call i32 @printZigZag(i32 %19, i32 %20)
ret i32 0
}