#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ isdigit(char);
char *malloc(scalar_t__);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
void deal_with_argument(char **argv) {
  char *av;
  while (av = *++argv) {
    if (av[0] != '-' || !isdigit(av[1]))
      continue;
    if ((av = malloc(strlen(*argv) + 1)) == NULL) {
      fprintf(stderr, "head: malloc failed.\n");
      exit(1);
    }
    av[0] = '-';
    av[1] = 'n';
    strcpy(av + 2, *argv + 1);
    *argv = av;
  }
}


x86 assembly (clang, -O0):
<deal_with_argument>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x8(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1234 <deal_with_argument+0xd4>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11b3 <deal_with_argument+0x53>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11b8 <deal_with_argument+0x58>
jmp    116c <deal_with_argument+0xc>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11fd <deal_with_argument+0x9d>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
movb   $0x2d,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x6e,0x1(%rax)
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
add    $0x1,%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    116c <deal_with_argument+0xc>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deal_with_argument>:
push   %r15
push   %r14
push   %rbx
mov    0x8(%rdi),%rax
test   %rax,%rax
je     11d8 <deal_with_argument+0x78>
mov    %rdi,%rbx
add    $0x8,%rbx
jmp    118d <deal_with_argument+0x2d>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rbx),%rax
add    $0x8,%rbx
test   %rax,%rax
je     11d8 <deal_with_argument+0x78>
cmpb   $0x2d,(%rax)
jne    1180 <deal_with_argument+0x20>
movsbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     1180 <deal_with_argument+0x20>
mov    (%rbx),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     11de <deal_with_argument+0x7e>
mov    %rax,%r15
movw   $0x6e2d,(%rax)
mov    %rax,%rdi
add    $0x2,%rdi
add    $0x1,%r14
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %r15,(%rbx)
jmp    1180 <deal_with_argument+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"head: malloc failed.\0A\00"
define void @deal_with_argument(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
store i8** %0, i8*** %2
br label %4
4: ; preds = %33, %21, %1
%5 = load i8**, i8*** %2
%6 = getelementptr inbounds i8*, i8** %5, i32 1
store i8** %6, i8*** %2
%7 = load i8*, i8** %6
store i8* %7, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %46
9: ; preds = %4
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 45
br i1 %14, label %21, label %15
15: ; preds = %9
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = call i32 @isdigit(i8 signext %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %15, %9
br label %4
22: ; preds = %15
%23 = load i8**, i8*** %2
%24 = load i8*, i8** %23
%25 = call i64 @strlen(i8* %24)
%26 = add nsw i64 %25, 1
%27 = call i8* @malloc(i64 %26)
store i8* %27, i8** %3
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %33
29: ; preds = %22
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %22
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i64 0
store i8 45, i8* %35
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i64 1
store i8 110, i8* %37
%38 = load i8*, i8** %3
%39 = getelementptr inbounds i8, i8* %38, i64 2
%40 = load i8**, i8*** %2
%41 = load i8*, i8** %40
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = call i32 @strcpy(i8* %39, i8* %42)
%44 = load i8*, i8** %3
%45 = load i8**, i8*** %2
store i8* %44, i8** %45
br label %4
46: ; preds = %4
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"head: malloc failed.\0A\00"
define void @deal_with_argument(i8** nocapture %0) {
%2 = getelementptr inbounds i8*, i8** %0, i64 1
%3 = load i8*, i8** %2
%4 = icmp eq i8* %3, null
br i1 %4, label %34, label %5
5: ; preds = %1, %15
%6 = phi i8* [ %17, %15 ], [ %3, %1 ]
%7 = phi i8** [ %16, %15 ], [ %2, %1 ]
%8 = load i8, i8* %6
%9 = icmp eq i8 %8, 45
br i1 %9, label %10, label %15
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %6, i64 1
%12 = load i8, i8* %11
%13 = tail call i32 @isdigit(i8 signext %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %5, %10, %29
%16 = getelementptr inbounds i8*, i8** %7, i64 1
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %34, label %5
19: ; preds = %10
%20 = load i8*, i8** %7
%21 = tail call i64 @strlen(i8* dereferenceable(1) %20)
%22 = add nsw i64 %21, 1
%23 = tail call i8* @malloc(i64 %22)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %29
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %19
store i8 45, i8* %23
%30 = getelementptr inbounds i8, i8* %23, i64 1
store i8 110, i8* %30
%31 = getelementptr inbounds i8, i8* %23, i64 2
%32 = getelementptr inbounds i8, i8* %20, i64 1
%33 = tail call i32 @strcpy(i8* %31, i8* %32)
store i8* %23, i8** %7
br label %15
34: ; preds = %15, %1
ret void
}