#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 */
struct ar_hdr {
  char *ar_size;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char *, int);
size_t strtoul(char *, int /*<<< orphan*/ *, int);
int _ar_get_size(struct ar_hdr *ar, size_t *size) {
  char buf[sizeof(ar->ar_size) + 1];
  if (ar->ar_size[0] == '\0')
    return 1;
  memcpy(buf, ar->ar_size, sizeof(ar->ar_size));
  buf[sizeof(buf) - 1] = '\0';
  *size = strtoul(buf, NULL, 10);
  return 0;
}


x86 assembly (clang, -O0):
<_ar_get_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    114f <_ar_get_size+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    118b <_ar_get_size+0x6b>
lea    -0x21(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    $0x8,%edx
call   1030 <memcpy@plt>
movb   $0x0,-0x19(%rbp)
lea    -0x21(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ar_get_size>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    (%rdi),%rsi
cmpb   $0x0,(%rsi)
je     1161 <_ar_get_size+0x41>
lea    0x7(%rsp),%r15
mov    %r15,%rdi
mov    $0x8,%edx
call   1030 <memcpy@plt>
movb   $0x0,0xf(%rsp)
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,(%r14)
jmp    1166 <_ar_get_size+0x46>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.ar_hdr = type { i8* }
define i32 @_ar_get_size(%struct.ar_hdr* %0, i64* %1) {
%3 = alloca i32
%4 = alloca %struct.ar_hdr*
%5 = alloca i64*
%6 = alloca [9 x i8]
store %struct.ar_hdr* %0, %struct.ar_hdr** %4
store i64* %1, i64** %5
%7 = load %struct.ar_hdr*, %struct.ar_hdr** %4
%8 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %7, i32 0, i32 0
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %25
15: ; preds = %2
%16 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%17 = load %struct.ar_hdr*, %struct.ar_hdr** %4
%18 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %17, i32 0, i32 0
%19 = load i8*, i8** %18
%20 = call i32 @memcpy(i8* %16, i8* %19, i32 8)
%21 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 8
store i8 0, i8* %21
%22 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%23 = call i64 @strtoul(i8* %22, i32* null, i32 10)
%24 = load i64*, i64** %5
store i64 %23, i64* %24
store i32 0, i32* %3
br label %25
25: ; preds = %15, %14
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
%struct.ar_hdr = type { i8* }
define i32 @_ar_get_size(%struct.ar_hdr* nocapture %0, i64* nocapture writeonly %1) {
%3 = alloca [9 x i8]
%4 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %0, i64 0, i32 0
%6 = load i8*, i8** %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = call i32 @memcpy(i8* %4, i8* %6, i32 8)
%11 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 8
store i8 0, i8* %11
%12 = call i64 @strtoul(i8* nocapture %4, i32* null, i32 10)
store i64 %12, i64* %1
br label %13
13: ; preds = %2, %9
%14 = phi i32 [ 0, %9 ], [ 1, %2 ]
ret i32 %14
}