#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 */
typedef int /*<<< orphan*/ time_t;
struct utimbuf {
  int /*<<< orphan*/ modtime;
  int /*<<< orphan*/ actime;
};
struct ar_hdr {
  char *ar_name;
  char *ar_mode;
  int /*<<< orphan*/ ar_date;
  int /*<<< orphan*/ ar_gid;
  int /*<<< orphan*/ ar_uid;
};
typedef int /*<<< orphan*/ mode_t;

/* Variables and functions */
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ atoi(int /*<<< orphan*/);
int close(int);
int /*<<< orphan*/ exit(int);
int fchown(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ strtol(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ trim(char *);
int utime(char *, struct utimbuf *);
int write_file(int, int, struct ar_hdr, char *);
int extract_file(int ar_fd, struct ar_hdr header, int verbose) {
  char tmp_buffer[16];
  char name_buffer[16];
  char *file_name = name_buffer;
  int copied = 0;
  int flags = O_WRONLY | O_CREAT | O_TRUNC;
  struct utimbuf new_times;
  time_t mtime;
  mode_t mode;
  snprintf(file_name, 16, "%s", header.ar_name);
  trim(file_name);
  snprintf(tmp_buffer, 8, "%s", header.ar_mode);
  mode = strtol(tmp_buffer, NULL, 8);
  int out_fd = open(file_name, flags, mode);
  if (out_fd == -1) {
    perror("Error creating file");
    exit(-1);
  }
  copied = write_file(ar_fd, out_fd, header, file_name);
  ;
  if (fchown(out_fd, atoi(header.ar_uid), atoi(header.ar_gid)) == -1) {
    perror("Error setting owner/group");
    exit(-1);
  }
  if (close(out_fd) == -1) {
    perror("Error closing output file");
    exit(-1);
  }
  mtime = atoi(header.ar_date);
  new_times.actime = mtime;
  new_times.modtime = time(NULL);
  if (utime(file_name, &new_times) == -1) {
    perror("Error setting time stamps on file");
    exit(-1);
  }
  if (verbose)
    printf("x - %s\n", file_name);
  return copied;
}


x86 assembly (clang, -O0):
<extract_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x30(%rbp),%rcx
mov    %rcx,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    0x2dc9(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2df0(%rip),%rdx
or     (%rdx),%ecx
mov    0x2ddf(%rip),%rdx
or     (%rdx),%ecx
mov    %ecx,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    (%rax),%rcx
mov    $0x10,%esi
lea    0xdd7(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x38(%rbp),%rdi
call   1070 <trim@plt>
mov    -0x60(%rbp),%rax
lea    -0x20(%rbp),%rdi
mov    0x8(%rax),%rcx
mov    $0x8,%esi
lea    0xdb1(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x8,%edx
call   1090 <strtol@plt>
mov    %eax,-0x50(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%esi
mov    -0x50(%rbp),%edx
call   10b0 <open@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0xffffffff,-0x54(%rbp)
jne    129b <extract_file+0xcb>
lea    0xd77(%rip),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x60(%rbp),%rax
mov    -0x4(%rbp),%edi
mov    -0x54(%rbp),%esi
mov    -0x38(%rbp),%rdx
mov    (%rax),%rcx
mov    %rcx,(%rsp)
mov    0x8(%rax),%rcx
mov    %rcx,0x8(%rsp)
mov    0x10(%rax),%rcx
mov    %rcx,0x10(%rsp)
mov    0x18(%rax),%rax
mov    %rax,0x18(%rsp)
call   1050 <write_file@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%rax
mov    %ecx,-0x3c(%rbp)
mov    -0x54(%rbp),%ecx
mov    %ecx,-0x68(%rbp)
mov    0x18(%rax),%edi
call   10e0 <atoi@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%rax
mov    %ecx,-0x64(%rbp)
mov    0x14(%rax),%edi
call   10e0 <atoi@plt>
mov    -0x68(%rbp),%edi
mov    -0x64(%rbp),%esi
mov    %eax,%edx
call   10c0 <fchown@plt>
cmp    $0xffffffff,%eax
jne    1324 <extract_file+0x154>
lea    0xd02(%rip),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x54(%rbp),%edi
call   1080 <close@plt>
cmp    $0xffffffff,%eax
jne    134b <extract_file+0x17b>
lea    0xcf5(%rip),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x60(%rbp),%rax
mov    0x10(%rax),%edi
call   10e0 <atoi@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x44(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1030 <utime@plt>
cmp    $0xffffffff,%eax
jne    1398 <extract_file+0x1c8>
lea    0xcc2(%rip),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
cmpl   $0x0,-0x8(%rbp)
je     13b2 <extract_file+0x1e2>
mov    -0x38(%rbp),%rsi
lea    0xcc0(%rip),%rdi
call   1040 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %esi,%r14d
mov    %edi,%r15d
mov    0x2ddd(%rip),%rax
mov    0x2e06(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2df3(%rip),%rax
or     (%rax),%ebx
mov    0x90(%rsp),%rcx
lea    0xdf2(%rip),%r12
lea    0x30(%rsp),%r13
mov    %r13,%rdi
mov    $0x10,%esi
mov    %r12,%rdx
call   1060 <snprintf@plt>
mov    %r13,%rdi
call   1070 <trim@plt>
mov    0x98(%rsp),%rcx
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x8,%esi
mov    %r12,%rdx
call   1060 <snprintf@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1090 <strtol@plt>
mov    %r13,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     1323 <extract_file+0x153>
mov    %eax,%ebx
lea    0x90(%rsp),%r12
movups (%r12),%xmm0
movups 0x10(%r12),%xmm1
movups %xmm1,0x10(%rsp)
movups %xmm0,(%rsp)
lea    0x30(%rsp),%rdx
mov    %r15d,%edi
mov    %eax,%esi
call   1050 <write_file@plt>
mov    %eax,%r15d
mov    0x18(%r12),%edi
call   10e0 <atoi@plt>
mov    %eax,%ebp
mov    0x14(%r12),%edi
call   10e0 <atoi@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %eax,%edx
call   10c0 <fchown@plt>
cmp    $0xffffffff,%eax
je     132c <extract_file+0x15c>
mov    %ebx,%edi
call   1080 <close@plt>
cmp    $0xffffffff,%eax
je     1335 <extract_file+0x165>
mov    0x10(%r12),%edi
call   10e0 <atoi@plt>
mov    %eax,0x2c(%rsp)
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,0x28(%rsp)
lea    0x30(%rsp),%rdi
lea    0x28(%rsp),%rsi
call   1030 <utime@plt>
cmp    $0xffffffff,%eax
je     133e <extract_file+0x16e>
test   %r14d,%r14d
je     1311 <extract_file+0x141>
lea    0xd66(%rip),%rdi
lea    0x30(%rsp),%rsi
call   1040 <printf@plt>
mov    %r15d,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcd9(%rip),%rdi
jmp    1345 <extract_file+0x175>
lea    0xce4(%rip),%rdi
jmp    1345 <extract_file+0x175>
lea    0xcf5(%rip),%rdi
jmp    1345 <extract_file+0x175>
lea    0xd06(%rip),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.ar_hdr = type { i8*, i8*, i32, i32, i32 }
%struct.utimbuf = type { i32, i32 }
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [20 x i8] c"Error creating file\00"
@.str.2 = [26 x i8] c"Error setting owner/group\00"
@.str.3 = [26 x i8] c"Error closing output file\00"
@.str.4 = [34 x i8] c"Error setting time stamps on file\00"
@.str.5 = [8 x i8] c"x - %s\0A\00"
define i32 @extract_file(i32 %0, %struct.ar_hdr* byval(%struct.ar_hdr) align 8 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca [16 x i8]
%7 = alloca [16 x i8]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.utimbuf
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %4
store i32 %2, i32* %5
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
store i8* %15, i8** %8
store i32 0, i32* %9
%16 = load i32, i32* @O_WRONLY
%17 = load i32, i32* @O_CREAT
%18 = or i32 %16, %17
%19 = load i32, i32* @O_TRUNC
%20 = or i32 %18, %19
store i32 %20, i32* %10
%21 = load i8*, i8** %8
%22 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %1, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = call i32 @snprintf(i8* %21, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %8
%26 = call i32 @trim(i8* %25)
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%28 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %1, i32 0, i32 1
%29 = load i8*, i8** %28
%30 = call i32 @snprintf(i8* %27, i32 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%32 = call i32 @strtol(i8* %31, i32* null, i32 8)
store i32 %32, i32* %13
%33 = load i8*, i8** %8
%34 = load i32, i32* %10
%35 = load i32, i32* %13
%36 = call i32 @open(i8* %33, i32 %34, i32 %35)
store i32 %36, i32* %14
%37 = load i32, i32* %14
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %42
39: ; preds = %3
%40 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %3
%43 = load i32, i32* %4
%44 = load i32, i32* %14
%45 = load i8*, i8** %8
%46 = call i32 @write_file(i32 %43, i32 %44, %struct.ar_hdr* byval(%struct.ar_hdr) align 8 %1, i8* %45)
store i32 %46, i32* %9
%47 = load i32, i32* %14
%48 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %1, i32 0, i32 4
%49 = load i32, i32* %48
%50 = call i32 @atoi(i32 %49)
%51 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %1, i32 0, i32 3
%52 = load i32, i32* %51
%53 = call i32 @atoi(i32 %52)
%54 = call i32 @fchown(i32 %47, i32 %50, i32 %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %59
56: ; preds = %42
%57 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%58 = call i32 @exit(i32 -1)
unreachable
59: ; preds = %42
%60 = load i32, i32* %14
%61 = call i32 @close(i32 %60)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%65 = call i32 @exit(i32 -1)
unreachable
66: ; preds = %59
%67 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %1, i32 0, i32 2
%68 = load i32, i32* %67
%69 = call i32 @atoi(i32 %68)
store i32 %69, i32* %12
%70 = load i32, i32* %12
%71 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %11, i32 0, i32 1
store i32 %70, i32* %71
%72 = call i32 @time(i32* null)
%73 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %11, i32 0, i32 0
store i32 %72, i32* %73
%74 = load i8*, i8** %8
%75 = call i32 @utime(i8* %74, %struct.utimbuf* %11)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %80
77: ; preds = %66
%78 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%79 = call i32 @exit(i32 -1)
unreachable
80: ; preds = %66
%81 = load i32, i32* %5
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %80
%84 = load i8*, i8** %8
%85 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %84)
br label %86
86: ; preds = %83, %80
%87 = load i32, i32* %9
ret i32 %87
}

LLVM IR (-O2):
%struct.ar_hdr = type { i8*, i8*, i32, i32, i32 }
%struct.utimbuf = type { i32, i32 }
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [20 x i8] c"Error creating file\00"
@.str.2 = [26 x i8] c"Error setting owner/group\00"
@.str.3 = [26 x i8] c"Error closing output file\00"
@.str.4 = [34 x i8] c"Error setting time stamps on file\00"
@.str.5 = [8 x i8] c"x - %s\0A\00"
define i32 @extract_file(i32 %0, %struct.ar_hdr* byval(%struct.ar_hdr) align 8 %1, i32 %2) {
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = alloca %struct.utimbuf
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* @O_WRONLY
%10 = load i32, i32* @O_CREAT
%11 = or i32 %10, %9
%12 = load i32, i32* @O_TRUNC
%13 = or i32 %11, %12
%14 = bitcast %struct.utimbuf* %6 to i8*
%15 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %1, i64 0, i32 0
%16 = load i8*, i8** %15
%17 = call i32 @snprintf(i8* %8, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @trim(i8* %8)
%19 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %1, i64 0, i32 1
%20 = load i8*, i8** %19
%21 = call i32 @snprintf(i8* %7, i32 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @strtol(i8* nocapture %7, i32* null, i32 8)
%23 = call i32 @open(i8* %8, i32 %13, i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %3
%26 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %3
%29 = call i32 @write_file(i32 %0, i32 %23, %struct.ar_hdr* byval(%struct.ar_hdr) align 8 %1, i8* %8)
%30 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %1, i64 0, i32 4
%31 = load i32, i32* %30
%32 = call i32 @atoi(i32 %31)
%33 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %1, i64 0, i32 3
%34 = load i32, i32* %33
%35 = call i32 @atoi(i32 %34)
%36 = call i32 @fchown(i32 %23, i32 %32, i32 %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %28
%39 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %28
%42 = call i32 @close(i32 %23)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%46 = call i32 @exit(i32 -1)
unreachable
47: ; preds = %41
%48 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %1, i64 0, i32 2
%49 = load i32, i32* %48
%50 = call i32 @atoi(i32 %49)
%51 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %6, i64 0, i32 1
store i32 %50, i32* %51
%52 = call i32 @time(i32* null)
%53 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %6, i64 0, i32 0
store i32 %52, i32* %53
%54 = call i32 @utime(i8* %8, %struct.utimbuf* %6)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %59
56: ; preds = %47
%57 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%58 = call i32 @exit(i32 -1)
unreachable
59: ; preds = %47
%60 = icmp eq i32 %2, 0
br i1 %60, label %63, label %61
61: ; preds = %59
%62 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %8)
br label %63
63: ; preds = %61, %59
ret i32 %29
}