#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_gid;
};
typedef int /*<<< orphan*/ gid_t;
typedef int /*<<< orphan*/ buf;

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


x86 assembly (clang, -O0):
<_ar_get_gid>:
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_gid+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    1189 <_ar_get_gid+0x69>
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    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ar_get_gid>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    (%rdi),%rsi
cmpb   $0x0,(%rsi)
je     1161 <_ar_get_gid+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    %eax,(%r14)
jmp    1166 <_ar_get_gid+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_gid(%struct.ar_hdr* %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.ar_hdr*
%5 = alloca i32*
%6 = alloca [9 x i8]
store %struct.ar_hdr* %0, %struct.ar_hdr** %4
store i32* %1, i32** %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 i32 @strtoul(i8* %22, i32* null, i32 10)
%24 = load i32*, i32** %5
store i32 %23, i32* %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_gid(%struct.ar_hdr* nocapture %0, i32* 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 i32 @strtoul(i8* nocapture %4, i32* null, i32 10)
store i32 %12, i32* %1
br label %13
13: ; preds = %2, %9
%14 = phi i32 [ 0, %9 ], [ 1, %2 ]
ret i32 %14
}