#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*/ write_char(double, double, char);
void grid_with_text(double x1, double y1, double x2, double y2, int nrow,
                    int ncol, char *str) {
  double x, y;
  double dx = (x2 - x1) / ncol, dy = (y2 - y1) / nrow;
  char *p = str;
  int i, j;
  for (i = 1; i <= nrow; i++) {
    y = y1 + i * dy;
    for (j = 0; j < ncol; j++) {
      if (*p == '\0')
        break;
      if (*p == '\n') {
        p++;
        break;
      }
      x = x1 + j * dx;
      write_char(x, y, *p);
      p++;
    }
    if (*p == '\0')
      break;
  }
}


x86 assembly (clang, -O0):
<grid_with_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
mov    %edi,-0x24(%rbp)
mov    %esi,-0x28(%rbp)
mov    %rdx,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x1,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     125a <grid_with_text+0x14a>
movsd  -0x10(%rbp),%xmm1
cvtsi2sdl -0x5c(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x60(%rbp)
mov    -0x60(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1232 <grid_with_text+0x122>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11c5 <grid_with_text+0xb5>
jmp    1232 <grid_with_text+0x122>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11e6 <grid_with_text+0xd6>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1232 <grid_with_text+0x122>
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x60(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
mov    -0x58(%rbp),%rax
movsbl (%rax),%edi
call   1030 <write_char@plt>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    11a4 <grid_with_text+0x94>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1247 <grid_with_text+0x137>
jmp    125a <grid_with_text+0x14a>
jmp    124c <grid_with_text+0x13c>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1175 <grid_with_text+0x65>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grid_with_text>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
test   %edi,%edi
jle    11e5 <grid_with_text+0xd5>
mov    %rdx,%rbx
mov    %esi,%r12d
mov    %edi,%r14d
subsd  0x10(%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %esi,%xmm0
divsd  %xmm0,%xmm2
movsd  %xmm2,0x20(%rsp)
subsd  0x8(%rsp),%xmm3
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
divsd  %xmm0,%xmm3
movsd  %xmm3,0x18(%rsp)
mov    $0x1,%r15d
test   %r12d,%r12d
jle    11d4 <grid_with_text+0xc4>
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
mulsd  0x18(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x28(%rsp)
xor    %ebp,%ebp
xchg   %ax,%ax
movzbl (%rbx),%eax
test   %al,%al
je     11e5 <grid_with_text+0xd5>
cmp    $0xa,%al
je     11d0 <grid_with_text+0xc0>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0x20(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsbl %al,%edi
movsd  0x28(%rsp),%xmm1
call   1030 <write_char@plt>
add    $0x1,%rbx
add    $0x1,%ebp
cmp    %ebp,%r12d
jne    1190 <grid_with_text+0x80>
jmp    11d4 <grid_with_text+0xc4>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmpb   $0x0,(%rbx)
je     11e5 <grid_with_text+0xd5>
lea    0x1(%r15),%eax
cmp    %r14d,%r15d
mov    %eax,%r15d
jne    116d <grid_with_text+0x5d>
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @grid_with_text(double %0, double %1, double %2, double %3, i32 %4, i32 %5, i8* %6) {
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca i8*
%20 = alloca i32
%21 = alloca i32
store double %0, double* %8
store double %1, double* %9
store double %2, double* %10
store double %3, double* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i8* %6, i8** %14
%22 = load double, double* %10
%23 = load double, double* %8
%24 = fsub double %22, %23
%25 = load i32, i32* %13
%26 = sitofp i32 %25 to double
%27 = fdiv double %24, %26
store double %27, double* %17
%28 = load double, double* %11
%29 = load double, double* %9
%30 = fsub double %28, %29
%31 = load i32, i32* %12
%32 = sitofp i32 %31 to double
%33 = fdiv double %30, %32
store double %33, double* %18
%34 = load i8*, i8** %14
store i8* %34, i8** %19
store i32 1, i32* %20
br label %35
35: ; preds = %86, %7
%36 = load i32, i32* %20
%37 = load i32, i32* %12
%38 = icmp sle i32 %36, %37
br i1 %38, label %39, label %89
39: ; preds = %35
%40 = load double, double* %9
%41 = load i32, i32* %20
%42 = sitofp i32 %41 to double
%43 = load double, double* %18
%44 = call double @llvm.fmuladd.f64(double %42, double %43, double %40)
store double %44, double* %16
store i32 0, i32* %21
br label %45
45: ; preds = %76, %39
%46 = load i32, i32* %21
%47 = load i32, i32* %13
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %79
49: ; preds = %45
%50 = load i8*, i8** %19
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %49
br label %79
55: ; preds = %49
%56 = load i8*, i8** %19
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 10
br i1 %59, label %60, label %63
60: ; preds = %55
%61 = load i8*, i8** %19
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %19
br label %79
63: ; preds = %55
%64 = load double, double* %8
%65 = load i32, i32* %21
%66 = sitofp i32 %65 to double
%67 = load double, double* %17
%68 = call double @llvm.fmuladd.f64(double %66, double %67, double %64)
store double %68, double* %15
%69 = load double, double* %15
%70 = load double, double* %16
%71 = load i8*, i8** %19
%72 = load i8, i8* %71
%73 = call i32 @write_char(double %69, double %70, i8 signext %72)
%74 = load i8*, i8** %19
%75 = getelementptr inbounds i8, i8* %74, i32 1
store i8* %75, i8** %19
br label %76
76: ; preds = %63
%77 = load i32, i32* %21
%78 = add nsw i32 %77, 1
store i32 %78, i32* %21
br label %45
79: ; preds = %60, %54, %45
%80 = load i8*, i8** %19
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = icmp eq i32 %82, 0
br i1 %83, label %84, label %85
84: ; preds = %79
br label %89
85: ; preds = %79
br label %86
86: ; preds = %85
%87 = load i32, i32* %20
%88 = add nsw i32 %87, 1
store i32 %88, i32* %20
br label %35
89: ; preds = %84, %35
ret void
}

LLVM IR (-O2):
define void @grid_with_text(double %0, double %1, double %2, double %3, i32 %4, i32 %5, i8* nocapture %6) {
%8 = fsub double %2, %0
%9 = sitofp i32 %5 to double
%10 = fdiv double %8, %9
%11 = fsub double %3, %1
%12 = sitofp i32 %4 to double
%13 = fdiv double %11, %12
%14 = icmp slt i32 %4, 1
br i1 %14, label %42, label %15
15: ; preds = %7
%16 = icmp sgt i32 %5, 0
br label %17
17: ; preds = %35, %15
%18 = phi i32 [ 1, %15 ], [ %39, %35 ]
%19 = phi i8* [ %6, %15 ], [ %36, %35 ]
%20 = sitofp i32 %18 to double
%21 = tail call double @llvm.fmuladd.f64(double %20, double %13, double %1)
br i1 %16, label %22, label %35
22: ; preds = %17, %28
%23 = phi i32 [ %33, %28 ], [ 0, %17 ]
%24 = phi i8* [ %32, %28 ], [ %19, %17 ]
%25 = load i8, i8* %24
switch i8 %25, label %28 [
i8 0, label %42
i8 10, label %26
]
26: ; preds = %22
%27 = getelementptr inbounds i8, i8* %24, i64 1
br label %35
28: ; preds = %22
%29 = sitofp i32 %23 to double
%30 = tail call double @llvm.fmuladd.f64(double %29, double %10, double %0)
%31 = tail call i32 @write_char(double %30, double %21, i8 signext %25)
%32 = getelementptr inbounds i8, i8* %24, i64 1
%33 = add nuw nsw i32 %23, 1
%34 = icmp eq i32 %33, %5
br i1 %34, label %35, label %22
35: ; preds = %28, %17, %26
%36 = phi i8* [ %27, %26 ], [ %19, %17 ], [ %32, %28 ]
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 0
%39 = add nuw i32 %18, 1
%40 = icmp eq i32 %18, %4
%41 = select i1 %38, i1 true, i1 %40
br i1 %41, label %42, label %17
42: ; preds = %35, %22, %7
ret void
}