#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 strnlen(char *, int);
void get_first_address(char *first_address, int len, char *header) {
  first_address[0] = '\0';
  int i;
  for (i = 0; i < strnlen(header, (len - 1)); i++) {
    char c = *(header + i);
    if (c == ',' || c == ' ') {
      break;
    }
    first_address[i] = c;
  }
}


x86 assembly (clang, -O0):
<get_first_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
call   1030 <strnlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    119c <get_first_address+0x8c>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0x2c,%eax
je     117b <get_first_address+0x6b>
movsbl -0x1d(%rbp),%eax
cmp    $0x20,%eax
jne    1180 <get_first_address+0x70>
jmp    119c <get_first_address+0x8c>
mov    -0x1d(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1131 <get_first_address+0x21>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_first_address>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %rdi,%r14
movb   $0x0,(%rdi)
add    $0xffffffff,%r15d
mov    %rdx,%rdi
mov    %r15d,%esi
call   1030 <strnlen@plt>
test   %eax,%eax
jle    1166 <get_first_address+0x56>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%rbp,1),%eax
cmp    $0x20,%al
je     1166 <get_first_address+0x56>
cmp    $0x2c,%al
je     1166 <get_first_address+0x56>
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
mov    %rbx,%rdi
mov    %r15d,%esi
call   1030 <strnlen@plt>
cltq
cmp    %rax,%rbp
jl     1140 <get_first_address+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @get_first_address(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
%10 = getelementptr inbounds i8, i8* %9, i64 0
store i8 0, i8* %10
store i32 0, i32* %7
br label %11
11: ; preds = %38, %3
%12 = load i32, i32* %7
%13 = load i8*, i8** %6
%14 = load i32, i32* %5
%15 = sub nsw i32 %14, 1
%16 = call i32 @strnlen(i8* %13, i32 %15)
%17 = icmp slt i32 %12, %16
br i1 %17, label %18, label %41
18: ; preds = %11
%19 = load i8*, i8** %6
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
store i8 %23, i8* %8
%24 = load i8, i8* %8
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 44
br i1 %26, label %31, label %27
27: ; preds = %18
%28 = load i8, i8* %8
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 32
br i1 %30, label %31, label %32
31: ; preds = %27, %18
br label %41
32: ; preds = %27
%33 = load i8, i8* %8
%34 = load i8*, i8** %4
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 %33, i8* %37
br label %38
38: ; preds = %32
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %11
41: ; preds = %31, %11
ret void
}

LLVM IR (-O2):
define void @get_first_address(i8* nocapture writeonly %0, i32 %1, i8* %2) {
store i8 0, i8* %0
%4 = add nsw i32 %1, -1
%5 = tail call i32 @strnlen(i8* %2, i32 %4)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %3, %11
%8 = phi i64 [ %13, %11 ], [ 0, %3 ]
%9 = getelementptr inbounds i8, i8* %2, i64 %8
%10 = load i8, i8* %9
switch i8 %10, label %11 [
i8 44, label %17
i8 32, label %17
]
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 %10, i8* %12
%13 = add nuw nsw i64 %8, 1
%14 = tail call i32 @strnlen(i8* %2, i32 %4)
%15 = sext i32 %14 to i64
%16 = icmp slt i64 %13, %15
br i1 %16, label %7, label %17
17: ; preds = %11, %7, %7, %3
ret void
}