#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 tcb {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ tprintf(char const *, int, char *);
scalar_t__ umoven(struct tcb *, long, int, char *);
void printargc(const char *fmt, struct tcb *tcp, long addr) {
  int count;
  char *cp;
  for (count = 0;
       umoven((tcp), (addr), sizeof(*(&cp)), (char *)(&cp)) >= 0 && cp != NULL;
       count++) {
    addr += sizeof(char *);
  }
  tprintf(fmt, count, count == 1 ? "" : "s");
}


x86 assembly (clang, -O0):
<printargc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rcx
mov    $0x8,%edx
call   1030 <umoven@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x29(%rbp)
jl     116e <printargc+0x4e>
cmpq   $0x0,-0x28(%rbp)
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    117e <printargc+0x5e>
jmp    1198 <printargc+0x78>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113b <printargc+0x1b>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x1c(%rbp),%ecx
lea    0xe57(%rip),%rdx
lea    0xe51(%rip),%rax
cmp    $0x1,%ecx
cmove  %rax,%rdx
call   1040 <tprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printargc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0x8(%rsp),%rcx
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    $0x8,%edx
call   1030 <umoven@plt>
xor    %ebp,%ebp
lea    0xead(%rip),%rdx
test   %rax,%rax
js     11ac <printargc+0x8c>
cmpq   $0x0,0x8(%rsp)
je     11ac <printargc+0x8c>
add    $0x8,%rbx
xor    %ebp,%ebp
lea    0x8(%rsp),%r12
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
mov    %r12,%rcx
call   1030 <umoven@plt>
test   %rax,%rax
js     1197 <printargc+0x77>
add    $0x8,%rbx
cmpq   $0x0,0x8(%rsp)
jne    1170 <printargc+0x50>
cmp    $0x1,%ebp
lea    0xe60(%rip),%rax
lea    0xe58(%rip),%rdx
cmove  %rax,%rdx
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <tprintf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tcb = type { i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"s\00"
define void @printargc(i8* %0, %struct.tcb* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca %struct.tcb*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store %struct.tcb* %1, %struct.tcb** %5
store i64 %2, i64* %6
store i32 0, i32* %7
br label %9
9: ; preds = %23, %3
%10 = load %struct.tcb*, %struct.tcb** %5
%11 = load i64, i64* %6
%12 = bitcast i8** %8 to i8*
%13 = call i64 @umoven(%struct.tcb* %10, i64 %11, i32 8, i8* %12)
%14 = icmp sge i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i8*, i8** %8
%17 = icmp ne i8* %16, null
br label %18
18: ; preds = %15, %9
%19 = phi i1 [ false, %9 ], [ %17, %15 ]
br i1 %19, label %20, label %26
20: ; preds = %18
%21 = load i64, i64* %6
%22 = add i64 %21, 8
store i64 %22, i64* %6
br label %23
23: ; preds = %20
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %9
26: ; preds = %18
%27 = load i8*, i8** %4
%28 = load i32, i32* %7
%29 = load i32, i32* %7
%30 = icmp eq i32 %29, 1
%31 = zext i1 %30 to i64
%32 = select i1 %30, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%33 = call i32 @tprintf(i8* %27, i32 %28, i8* %32)
ret void
}

LLVM IR (-O2):
%struct.tcb = type { i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"s\00"
define void @printargc(i8* %0, %struct.tcb* %1, i64 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call i64 @umoven(%struct.tcb* %1, i64 %2, i32 8, i8* %5)
%7 = icmp sgt i64 %6, -1
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
%10 = select i1 %7, i1 %9, i1 false
br i1 %10, label %11, label %24
11: ; preds = %3, %11
%12 = phi i32 [ %15, %11 ], [ 0, %3 ]
%13 = phi i64 [ %14, %11 ], [ %2, %3 ]
%14 = add i64 %13, 8
%15 = add nuw nsw i32 %12, 1
%16 = call i64 @umoven(%struct.tcb* %1, i64 %14, i32 8, i8* %5)
%17 = icmp sgt i64 %16, -1
%18 = load i8*, i8** %4
%19 = icmp ne i8* %18, null
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %11, label %21
21: ; preds = %11
%22 = icmp eq i32 %12, 0
%23 = select i1 %22, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
br label %24
24: ; preds = %21, %3
%25 = phi i32 [ 0, %3 ], [ %15, %21 ]
%26 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %3 ], [ %23, %21 ]
%27 = call i32 @tprintf(i8* %0, i32 %25, i8* %26)
ret void
}