#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 strlen(char *);
int calc_msgbox_metrics(char **msg_array, int *width, int *height) {
  int line_width = 0;
  int line_count = 0;
  int idx = 0;
  *height = 0;
  *width = 0;
  while (*msg_array != NULL) {
    line_count++;
    line_width = strlen(*msg_array);
    if (line_width > (*width)) {
      *width = line_width;
      idx = line_count - 1;
    }
    msg_array++;
  }
  *height = line_count;
  return idx;
}


x86 assembly (clang, -O0):
<calc_msgbox_metrics>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     11a5 <calc_msgbox_metrics+0x95>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jle    1194 <calc_msgbox_metrics+0x84>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
jmp    114d <calc_msgbox_metrics+0x3d>
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_msgbox_metrics>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rdi,%r15
movl   $0x0,(%rdx)
movl   $0x0,(%rsi)
mov    (%rdi),%rdi
test   %rdi,%rdi
je     115e <calc_msgbox_metrics+0x4e>
mov    %rsi,%rbx
xor    %ebp,%ebp
xor    %r12d,%r12d
jmp    114e <calc_msgbox_metrics+0x3e>
nopl   0x0(%rax)
mov    0x8(%r15,%rbp,8),%rdi
add    $0x1,%rbp
test   %rdi,%rdi
je     1163 <calc_msgbox_metrics+0x53>
call   1030 <strlen@plt>
cmp    (%rbx),%eax
jle    1140 <calc_msgbox_metrics+0x30>
mov    %eax,(%rbx)
mov    %ebp,%r12d
jmp    1140 <calc_msgbox_metrics+0x30>
xor    %ebp,%ebp
xor    %r12d,%r12d
mov    %ebp,(%r14)
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @calc_msgbox_metrics(i8** %0, i32* %1, i32* %2) {
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8** %0, i8*** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%10 = load i32*, i32** %6
store i32 0, i32* %10
%11 = load i32*, i32** %5
store i32 0, i32* %11
br label %12
12: ; preds = %31, %3
%13 = load i8**, i8*** %4
%14 = load i8*, i8** %13
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %34
16: ; preds = %12
%17 = load i32, i32* %8
%18 = add nsw i32 %17, 1
store i32 %18, i32* %8
%19 = load i8**, i8*** %4
%20 = load i8*, i8** %19
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = load i32*, i32** %5
%24 = load i32, i32* %23
%25 = icmp sgt i32 %22, %24
br i1 %25, label %26, label %31
26: ; preds = %16
%27 = load i32, i32* %7
%28 = load i32*, i32** %5
store i32 %27, i32* %28
%29 = load i32, i32* %8
%30 = sub nsw i32 %29, 1
store i32 %30, i32* %9
br label %31
31: ; preds = %26, %16
%32 = load i8**, i8*** %4
%33 = getelementptr inbounds i8*, i8** %32, i32 1
store i8** %33, i8*** %4
br label %12
34: ; preds = %12
%35 = load i32, i32* %8
%36 = load i32*, i32** %6
store i32 %35, i32* %36
%37 = load i32, i32* %9
ret i32 %37
}

LLVM IR (-O2):
define i32 @calc_msgbox_metrics(i8** nocapture %0, i32* nocapture %1, i32* nocapture writeonly %2) {
store i32 0, i32* %2
store i32 0, i32* %1
%4 = load i8*, i8** %0
%5 = icmp eq i8* %4, null
br i1 %5, label %21, label %6
6: ; preds = %3, %16
%7 = phi i8* [ %19, %16 ], [ %4, %3 ]
%8 = phi i32 [ %17, %16 ], [ 0, %3 ]
%9 = phi i32 [ %11, %16 ], [ 0, %3 ]
%10 = phi i8** [ %18, %16 ], [ %0, %3 ]
%11 = add nuw nsw i32 %9, 1
%12 = tail call i32 @strlen(i8* %7)
%13 = load i32, i32* %1
%14 = icmp sgt i32 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %6
store i32 %12, i32* %1
br label %16
16: ; preds = %15, %6
%17 = phi i32 [ %9, %15 ], [ %8, %6 ]
%18 = getelementptr inbounds i8*, i8** %10, i64 1
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %6
21: ; preds = %16, %3
%22 = phi i32 [ 0, %3 ], [ %11, %16 ]
%23 = phi i32 [ 0, %3 ], [ %17, %16 ]
store i32 %22, i32* %2
ret i32 %23
}