#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 */
size_t strlen(char *);
size_t get_argv_size(int argc, char **argv) {
  size_t expression_size = strlen(argv[1]);
  for (int i = 2; i < argc; i++) {
    expression_size += strlen(argv[i]);
  }
  return expression_size;
}


x86 assembly (clang, -O0):
<get_argv_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    116a <get_argv_size+0x5a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1137 <get_argv_size+0x27>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_argv_size>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
cmp    $0x3,%ebp
jl     1155 <get_argv_size+0x45>
mov    %ebp,%r15d
mov    $0x2,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r14,%rbp,8),%rdi
call   1030 <strlen@plt>
add    %rax,%rbx
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1140 <get_argv_size+0x30>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @get_argv_size(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i8**, i8*** %4
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %5
store i32 2, i32* %6
br label %11
11: ; preds = %24, %2
%12 = load i32, i32* %6
%13 = load i32, i32* %3
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %27
15: ; preds = %11
%16 = load i8**, i8*** %4
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = call i64 @strlen(i8* %20)
%22 = load i64, i64* %5
%23 = add i64 %22, %21
store i64 %23, i64* %5
br label %24
24: ; preds = %15
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %11
27: ; preds = %11
%28 = load i64, i64* %5
ret i64 %28
}

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